_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q45300 | train | function(){
// If the data grid has already been built, nothing to do here
if (this.spreadsheet.datagrid) return this.spreadsheet.datagrid;
var s = this.series,
datagrid = this.spreadsheet.loadDataGrid(),
colgroup = ['<colgroup><col />'],
buttonDownload, buttonSelect, t;
... | javascript | {
"resource": ""
} | |
q45301 | train | function(tabName){
if (this.spreadsheet.activeTab === tabName){
return;
}
switch(tabName) {
case 'graph':
D.hide(this.spreadsheet.container);
D.removeClass(this.spreadsheet.tabs.data, 'selected');
D.addClass(this.spreadsheet.tabs.graph, 'selected');
break;
cas... | javascript | {
"resource": ""
} | |
q45302 | train | function(){
var csv = '',
series = this.series,
options = this.options,
dg = this.spreadsheet.loadDataGrid(),
separator = encodeURIComponent(options.spreadsheet.csvFileSeparator);
if (options.spreadsheet.decimalSeparator === options.spreadsheet.csvFileSeparator) {
thro... | javascript | {
"resource": ""
} | |
q45303 | train | function(src, dest){
var i, v, result = dest || {};
for (i in src) {
v = src[i];
if (v && typeof(v) === 'object') {
if (v.constructor === Array) {
result[i] = this._.clone(v);
} else if (v.constructor !== RegExp && !this._.isElement(v)) {
result[i] = Flotr.merge(... | javascript | {
"resource": ""
} | |
q45304 | train | function(element, child){
if(_.isString(child))
element.innerHTML += child;
else if (_.isElement(child))
element.appendChild(child);
} | javascript | {
"resource": ""
} | |
q45305 | train | function (mouse) {
var
options = this.options,
prevHit = this.prevHit,
closest, sensibility, dataIndex, seriesIndex, series, value, xaxis, yaxis, n;
if (this.series.length === 0) return;
// Nearest data element.
// dist, x, y, relX, relY, absX, absY, sAngle, eAngle, fraction, mouse,... | javascript | {
"resource": ""
} | |
q45306 | resolve | train | function resolve (framework) {
// strip off a trailing slash if present
if (framework[framework.length-1] == '/')
framework = framework.slice(0, framework.length-1);
// already absolute, return as-is
if (~framework.indexOf('/')) return framework;
var i=0, l=PATH.length, rtn=null;
for (; i<l; i++) {
... | javascript | {
"resource": ""
} |
q45307 | getStruct | train | function getStruct (type) {
// First check if a regular name was passed in
var rtn = structCache[type];
if (rtn) return rtn;
// If the struct type name has already been created, return that one
var name = parseStructName(type);
rtn = structCache[name];
if (rtn) return rtn;
if(knownStructs[name]) typ... | javascript | {
"resource": ""
} |
q45308 | parseStructName | train | function parseStructName (struct) {
var s = struct.substring(1, struct.length-1)
, equalIndex = s.indexOf('=')
if (~equalIndex)
s = s.substring(0, equalIndex)
return s
} | javascript | {
"resource": ""
} |
q45309 | map | train | function map (type) {
if (!type) throw new Error('got falsey "type" to map ('+type+'). this should NOT happen!');
if (type.type) type = type.type;
if (isStruct(type)) return getStruct(type);
type = type.replace(methodEncodingsTest, '')
// if the first letter is a ^ then it's a "pointer" type
if (type[0] ===... | javascript | {
"resource": ""
} |
q45310 | parse | train | function parse (types) {
if (typeof types === 'string') {
var rtn = []
, cur = []
, len = types.length
, depth = 0
for (var i=0; i<len; i++) {
var c = types[i]
if (depth || !/(\d)/.test(c)) {
cur.push(c)
}
if (c == '{' || c == '[' || c == '(') {
dept... | javascript | {
"resource": ""
} |
q45311 | ID | train | function ID (pointer) {
if (typeof this !== 'function') return createFunction(null, 0, ID, arguments);
var objClass = core.object_getClass(pointer);
// This is absolutely necessary, otherwise we'll seg fault if a user passes in
// a simple type or specifies an object on a class that takes a simple type.
if ... | javascript | {
"resource": ""
} |
q45312 | copyIvarList | train | function copyIvarList (classPtr) {
var rtn = []
, numIvars = ref.alloc('uint')
, ivars = objc.class_copyIvarList(classPtr, numIvars)
, count = numIvars.deref();
for (var i=0; i<count; i++)
rtn.push(objc.ivar_getName(ivars.readPointer(i * ref.sizeof.pointer)));
free(ivars);
return rtn;
} | javascript | {
"resource": ""
} |
q45313 | copyMethodList | train | function copyMethodList (classPtr) {
var numMethods = ref.alloc('uint')
, rtn = []
, methods = objc.class_copyMethodList(classPtr, numMethods)
, count = numMethods.deref();
for (var i=0; i<count; i++)
rtn.push(wrapValue(objc.method_getName(methods.readPointer(i * ref.sizeof.pointer)),':'));
free... | javascript | {
"resource": ""
} |
q45314 | wrapValues | train | function wrapValues (values, objtypes) {
var result = [];
for(var i=0; i < objtypes.length; i++) result.push(wrapValue(values[i], objtypes[i]));
return result;
} | javascript | {
"resource": ""
} |
q45315 | unwrapValue | train | function unwrapValue (val, type) {
var basetype = type.type ? type.type : type;
if (basetype == '@?') return createBlock(val, basetype);
else if (basetype == '^?') return createWrapperPointer(val, type);
else if (basetype == '@' || basetype == '#') {
if(Buffer.isBuffer(val)) return val;
return val ? val... | javascript | {
"resource": ""
} |
q45316 | unwrapValues | train | function unwrapValues (values, objtypes) {
var result = [];
for(var i=0; i < objtypes.length; i++) result.push(unwrapValue(values[i], objtypes[i]));
return result;
} | javascript | {
"resource": ""
} |
q45317 | createUnwrapperFunction | train | function createUnwrapperFunction (funcPtr, type, isVariadic) {
var rtnType = type.retval || type[0] || 'v';
var argTypes = type.args || type[1] || [];
var unwrapper;
if (isVariadic) {
var func = ffi.VariadicForeignFunction(funcPtr, types.map(rtnType), types.mapArray(argTypes));
unwrapper = function() {... | javascript | {
"resource": ""
} |
q45318 | Filter | train | function Filter(opts) {
this.model = opts.model
this.filteredKeys = isPlainObject(opts.filteredKeys)
? {
private: opts.filteredKeys.private || [],
protected: opts.filteredKeys.protected || []
}
: {
private: [],
protected: []
}
if (this.model && this.model.disc... | javascript | {
"resource": ""
} |
q45319 | createAbortSignal | train | function createAbortSignal() {
const signal = Object.create(AbortSignal.prototype);
eventTargetShim.EventTarget.call(signal);
abortedFlags.set(signal, false);
return signal;
} | javascript | {
"resource": ""
} |
q45320 | abortSignal | train | function abortSignal(signal) {
if (abortedFlags.get(signal) !== false) {
return;
}
abortedFlags.set(signal, true);
signal.dispatchEvent({ type: "abort" });
} | javascript | {
"resource": ""
} |
q45321 | getSignal | train | function getSignal(controller) {
const signal = signals.get(controller);
if (signal == null) {
throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
}
return signal;
} | javascript | {
"resource": ""
} |
q45322 | Config | train | function Config(rules, options) {
this.options = {};
if (options) { options.forEach(this.addOption.bind(this)); }
this.rulesMap = {};
if (rules) { rules.forEach(this.addRule.bind(this)); }
} | javascript | {
"resource": ""
} |
q45323 | train | function (config) {
this.setOption = config.setOption.bind(config);
this.isOption = function (name) { return name in config.options; };
this.clear();
} | javascript | {
"resource": ""
} | |
q45324 | applyConfig | train | function applyConfig(config) {
var previous = {};
config.rules.forEach(function (rule) {
var isprev = (rule.value === '$previous');
var setOption = function (name, value) {
previous[name] = this.current[name];
this.current[name] = this.setOption(name, value, isprev);
... | javascript | {
"resource": ""
} |
q45325 | parsePair | train | function parsePair(name, value, pos, isOption) {
if (!name || !value || !name.length || !value.length) {
return new Issue('E050', pos);
}
var nameRegex = /^[a-zA-Z0-9-_]+$/;
if (!nameRegex.test(name)) {
return new Issue('E051', pos, {name: name});
}
// Strip quotes and replace ... | javascript | {
"resource": ""
} |
q45326 | train | function (rules, options) {
this.rules = new Config(rules, options);
this.parser = new Parser();
this.inlineConfig = new InlineConfig(this.rules);
} | javascript | {
"resource": ""
} | |
q45327 | linspace | train | function linspace(min, max, count) {
var range = (max - min) / (count - 1);
var res = [];
for (var i = 0; i < count; i++) {
res.push(min + range * i);
}
return res;
} | javascript | {
"resource": ""
} |
q45328 | train | function (newProps) {
var value = this._or(ensureArray(newProps.value), this.state.value);
// ensure the array keeps the same size as `value`
this.tempArray = value.slice();
for (var i = 0; i < value.length; i++) {
this.state.value[i] = this._trimAlignValue(value[i], newProps);
}... | javascript | {
"resource": ""
} | |
q45329 | train | function (value) {
var range = this.props.max - this.props.min;
if (range === 0) {
return 0;
}
var ratio = (value - this.props.min) / range;
return ratio * this.state.upperBound;
} | javascript | {
"resource": ""
} | |
q45330 | train | function (offset) {
var ratio = offset / this.state.upperBound;
return ratio * (this.props.max - this.props.min) + this.props.min;
} | javascript | {
"resource": ""
} | |
q45331 | train | function (position, callback) {
var pixelOffset = this._calcOffsetFromPosition(position);
var closestIndex = this._getClosestIndex(pixelOffset);
var nextValue = this._trimAlignValue(this._calcValue(pixelOffset));
var value = this.state.value.slice(); // Clone this.state.value since we'll modify... | javascript | {
"resource": ""
} | |
q45332 | train | function (i) {
return function (e) {
if (this.props.disabled) return;
this._start(i);
this._addHandlers(this._getKeyDownEventMap());
pauseEvent(e);
}.bind(this);
} | javascript | {
"resource": ""
} | |
q45333 | train | function (i) {
return function (e) {
if (this.props.disabled) return;
var position = this._getMousePosition(e);
this._start(i, position[0]);
this._addHandlers(this._getMouseEventMap());
pauseEvent(e);
}.bind(this);
} | javascript | {
"resource": ""
} | |
q45334 | train | function (i) {
return function (e) {
if (this.props.disabled || e.touches.length > 1) return;
var position = this._getTouchPosition(e);
this.startPosition = position;
this.isScrolling = undefined; // don't know yet if the user is trying to scroll
this._start(i, position[0])... | javascript | {
"resource": ""
} | |
q45335 | train | function() {
var result = {};
for (var i = arguments.length - 1; i >= 0; i--) {
var obj = arguments[i];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
result[k] = obj[k];
}
}
}
return result;
} | javascript | {
"resource": ""
} | |
q45336 | train | function(el, text) {
var scrollPos = el.scrollTop,
strPos = 0,
browser = false,
range;
if ((el.selectionStart || el.selectionStart === '0')) {
browser = "ff";
} else if (document.selection) {
browser = "ie";
}
if (browser === "ie") {
el.foc... | javascript | {
"resource": ""
} | |
q45337 | readParameters | train | function readParameters(obj, scope) {
var result = {},
attrs = obj.$attr,
option, value;
for (var key in attrs) {
option = lcfirst(key.substr(attrName.length));
value = obj[key];
// Check if the given key is a valid string type, not empty and starts with the attribute name
i... | javascript | {
"resource": ""
} |
q45338 | train | function(instance) {
var $this = $(instance);
return {
getValue: function() {
return $this.val();
},
insertValue: function(val) {
inlineAttachment.util.insertTextAtCursor($this[0], val);
},
setValue: function(val) {
$this.val(val);
}
};
} | javascript | {
"resource": ""
} | |
q45339 | train | function (matrix4x4) {
let ismirror = matrix4x4.isMirroring()
// get two vectors in the plane:
let r = this.normal.randomNonParallelVector()
let u = this.normal.cross(r)
let v = this.normal.cross(u)
// get 3 points in the plane:
let point1 = this.normal.times(this.w)
let point2 =... | javascript | {
"resource": ""
} | |
q45340 | train | function (p1, p2) {
let direction = p2.minus(p1)
let labda = (this.w - this.normal.dot(p1)) / this.normal.dot(direction)
if (isNaN(labda)) labda = 0
if (labda > 1) labda = 1
if (labda < 0) labda = 0
let result = p1.plus(direction.times(labda))
return result
} | javascript | {
"resource": ""
} | |
q45341 | vectorParams | train | function vectorParams (options, input) {
if (!input && typeof options === 'string') {
options = { input: options }
}
options = options || {}
let params = Object.assign({}, defaultsVectorParams, options)
params.input = input || params.input
return params
} | javascript | {
"resource": ""
} |
q45342 | setShared | train | function setShared (shared) {
let polygons = this.polygons.map(function (p) {
return new Polygon3(p.vertices, shared, p.plane)
})
let result = fromPolygons(polygons)
result.properties = this.properties // keep original properties
result.isRetesselated = this.isRetesselated
result.isCanonicalized = this.... | javascript | {
"resource": ""
} |
q45343 | train | function (options) {
options = options || {}
if (('points' in options) !== ('faces' in options)) {
throw new Error("polyhedron needs 'points' and 'faces' arrays")
}
let vertices = parseOptionAs3DVectorList(options, 'points', [
[1, 1, 0],
[1, -1, 0],
[-1, -1, 0],
... | javascript | {
"resource": ""
} | |
q45344 | connectTo | train | function connectTo (shape3, connector, otherConnector, mirror, normalrotation) {
let matrix = connector.getTransformationTo(otherConnector, mirror, normalrotation)
return transform(matrix, shape3)
} | javascript | {
"resource": ""
} |
q45345 | rotate | train | function rotate (...params) {
let out
let angle
let vector
if (params.length === 2) {
out = create()
angle = params[0]
vector = params[1]
} else {
out = params[0]
angle = params[1]
vector = params[2]
}
// fIXME: not correct
console.log('rotate', angle, vector)
const origin = [... | javascript | {
"resource": ""
} |
q45346 | train | function (plane, coplanarfrontnodes, coplanarbacknodes, frontnodes, backnodes) {
if (this.children.length) {
let queue = [this.children]
let i
let j
let l
let node
let nodes
for (i = 0; i < queue.length; i++) { // queue.length can increase, do not cache
nodes = queu... | javascript | {
"resource": ""
} | |
q45347 | translateLine | train | function translateLine (options, line) {
const { x, y } = Object.assign({ x: 0, y: 0 }, options || {})
let segments = line.segments
let segment = null
let point = null
for (let i = 0, il = segments.length; i < il; i++) {
segment = segments[i]
for (let j = 0, jl = segment.length; j < jl; j++) {
p... | javascript | {
"resource": ""
} |
q45348 | fromObject | train | function fromObject (obj) {
let polygons = obj.polygons.map(polygonLike => poly3.fromObject(polygonLike))
let shape3 = fromPolygons(polygons)
shape3.isCanonicalized = obj.isCanonicalized
shape3.isRetesselated = obj.isRetesselated
return shape3
} | javascript | {
"resource": ""
} |
q45349 | train | function (plane, rightvector) {
if (arguments.length < 2) {
// choose an arbitrary right hand vector, making sure it is somewhat orthogonal to the plane normal:
rightvector = vec3.random(plane)
} else {
rightvector = rightvector
}
this.v = vec3.unit(vec3.cross(plane, rightvector))
this.u = vec3.cr... | javascript | {
"resource": ""
} | |
q45350 | setEngine | train | function setEngine(Engine, config) {
initialized = false;
engine = new Engine(config);
init(config);
} | javascript | {
"resource": ""
} |
q45351 | init | train | function init(config) {
if (!engine)
throw new Error(
"No engine set for research. Set an engine using gitbook.research.setEngine(Engine)."
);
return engine.init(config).then(function() {
initialized = true;
gitbook.events.trigger("search.ready");
});
} | javascript | {
"resource": ""
} |
q45352 | query | train | function query(q, offset, length) {
if (!initialized) throw new Error("Search has not been initialized");
return engine.search(q, offset, length);
} | javascript | {
"resource": ""
} |
q45353 | enlargeFontSize | train | function enlargeFontSize(e) {
e.preventDefault();
if (fontState.size >= MAX_SIZE) return;
fontState.size++;
saveFontSettings();
} | javascript | {
"resource": ""
} |
q45354 | reduceFontSize | train | function reduceFontSize(e) {
e.preventDefault();
if (fontState.size <= MIN_SIZE) return;
fontState.size--;
saveFontSettings();
} | javascript | {
"resource": ""
} |
q45355 | changeFontFamily | train | function changeFontFamily(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var familyId = getFontFamilyId(configName);
fontState.family = familyId;
saveFontSettings();
} | javascript | {
"resource": ""
} |
q45356 | changeColorTheme | train | function changeColorTheme(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var $book = gitbook.state.$book;
// Remove currently applied color theme
if (fontState.theme !== 0)
$book.removeClass("color-theme-" + fontState.theme);
// Set new color theme
var t... | javascript | {
"resource": ""
} |
q45357 | getFontFamilyId | train | function getFontFamilyId(configName) {
// Search for plugin configured font family
var configFamily = $.grep(FAMILIES, function(family) {
return family.config == configName;
})[0];
// Fallback to default font family
return !!configFamily ? configFamily.id : 0;
} | javascript | {
"resource": ""
} |
q45358 | getThemeId | train | function getThemeId(configName) {
// Search for plugin configured theme
var configTheme = $.grep(THEMES, function(theme) {
return theme.config == configName;
})[0];
// Fallback to default theme
return !!configTheme ? configTheme.id : 0;
} | javascript | {
"resource": ""
} |
q45359 | sanitizeKey | train | function sanitizeKey(obj) {
if (typeof obj !== 'object') return obj;
if (Array.isArray(obj)) return obj;
if (obj === null) return null;
if (obj instanceof Boolean) return obj;
if (obj instanceof Number) return obj;
if (obj instanceof Buffer) return obj.toString();
for (const k in obj) {
const escapedK... | javascript | {
"resource": ""
} |
q45360 | train | function(property) {
if (!property) {
return true
}
var div = document.createElement("div")
var vendorPrefixes = ["khtml", "ms", "o", "moz", "webkit"]
var count = vendorPrefixes.length
// Note: HTMLElement.style.hasOwnProperty seems broken in Edge
if (property in div.style) {
return true
... | javascript | {
"resource": ""
} | |
q45361 | train | function (mapping) {
const result = {};
for (const [key, value] of _.toPairs(mapping)) {
result[key] = _.isString(value) ? value : JSON.stringify(value);
}
return result;
} | javascript | {
"resource": ""
} | |
q45362 | extractFromApks | train | async function extractFromApks (apks, dstPath) {
if (!_.isArray(dstPath)) {
dstPath = [dstPath];
}
return await APKS_CACHE_GUARD.acquire(apks, async () => {
// It might be that the original file has been replaced,
// so we need to keep the hash sums instead of the actual file paths
// as caching ... | javascript | {
"resource": ""
} |
q45363 | extractApkInfoWithApkanalyzer | train | async function extractApkInfoWithApkanalyzer (localApk, apkanalyzerPath) {
const args = ['-h', 'manifest', 'print', localApk];
log.debug(`Starting '${apkanalyzerPath}' with args ${JSON.stringify(args)}`);
const manifestXml = (await exec(apkanalyzerPath, args, {
shell: true,
cwd: path.dirname(apkanalyzerPa... | javascript | {
"resource": ""
} |
q45364 | buildStartCmd | train | function buildStartCmd (startAppOptions, apiLevel) {
let cmd = ['am', 'start'];
if (util.hasValue(startAppOptions.user)) {
cmd.push('--user', startAppOptions.user);
}
cmd.push('-W', '-n', `${startAppOptions.pkg}/${startAppOptions.activity}`);
if (startAppOptions.stopApp && apiLevel >= 15) {
cmd.push('... | javascript | {
"resource": ""
} |
q45365 | train | function (str) {
str = str.trim();
let space = str.indexOf(' ');
if (space === -1) {
return str.length ? [str] : [];
} else {
return [str.substring(0, space).trim(), str.substring(space + 1).trim()];
}
} | javascript | {
"resource": ""
} | |
q45366 | train | function (dumpsysOutput, groupNames, grantedState = null) {
const groupPatternByName = (groupName) => new RegExp(`^(\\s*${_.escapeRegExp(groupName)} permissions:[\\s\\S]+)`, 'm');
const indentPattern = /\S|$/;
const permissionNamePattern = /android\.permission\.\w+/;
const grantedStatePattern = /\bgranted=(\w+)... | javascript | {
"resource": ""
} | |
q45367 | patchApksigner | train | async function patchApksigner (originalPath) {
const originalContent = await fs.readFile(originalPath, 'ascii');
const patchedContent = originalContent.replace('-Djava.ext.dirs="%frameworkdir%"',
'-cp "%frameworkdir%\\*"');
if (patchedContent === originalContent) {
return originalPath;
}
log.debug(`Pa... | javascript | {
"resource": ""
} |
q45368 | google | train | function google (query, start, callback) {
var startIndex = 0
if (typeof callback === 'undefined') {
callback = start
} else {
startIndex = start
}
igoogle(query, startIndex, callback)
} | javascript | {
"resource": ""
} |
q45369 | copypaste | train | function copypaste(from, to, ...props) {
props.forEach((prop) => {
if (prop in from) to[prop] = from[prop];
});
} | javascript | {
"resource": ""
} |
q45370 | prepare | train | function prepare(props) {
const clean = rip(props,
'translate', 'scale', 'rotate', 'skewX', 'skewY', 'originX', 'originY',
'fontFamily', 'fontSize', 'fontWeight', 'fontStyle',
'style'
);
const transform = [];
//
// Correctly apply the transformation properties.
// To apply originX and originY ... | javascript | {
"resource": ""
} |
q45371 | G | train | function G(props) {
const { x, y, ...rest } = props;
if ((x || y) && !rest.translate) {
rest.translate = `${x || 0}, ${y || 0}`;
}
return <g { ...prepare(rest) } />;
} | javascript | {
"resource": ""
} |
q45372 | Svg | train | function Svg(props) {
const { title, ...rest } = props;
if (title) {
return (
<svg role='img' aria-label='[title]' { ...prepare(rest) }>
<title>{ title }</title>
{ props.children }
</svg>
);
}
return <svg { ...prepare(rest) } />;
} | javascript | {
"resource": ""
} |
q45373 | Text | train | function Text(props) {
const { x, y, dx, dy, rotate, ...rest } = props;
return <text { ...prepare(rest) } { ...{ x, y, dx, dy, rotate } } />;
} | javascript | {
"resource": ""
} |
q45374 | TSpan | train | function TSpan(props) {
const { x, y, dx, dy, rotate, ...rest } = props;
return <tspan { ...prepare(rest) } { ...{ x, y, dx, dy, rotate } } />;
} | javascript | {
"resource": ""
} |
q45375 | _applyAttrs | train | function _applyAttrs(context, attrs) {
for (var attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
context.setAttribute(attr, attrs[attr]);
}
}
} | javascript | {
"resource": ""
} |
q45376 | _applyStyles | train | function _applyStyles(context, attrs) {
for (var attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
context.style[attr] = attrs[attr];
}
}
} | javascript | {
"resource": ""
} |
q45377 | _getStyle | train | function _getStyle(el, styleProp) {
var x = el
, y = null;
if (window.getComputedStyle) {
y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp);
}
else if (x.currentStyle) {
y = x.currentStyle[styleProp];
}
return y;
} | javascript | {
"resource": ""
} |
q45378 | _saveStyleState | train | function _saveStyleState(el, type, styles) {
var returnState = {}
, style;
if (type === 'save') {
for (style in styles) {
if (styles.hasOwnProperty(style)) {
returnState[style] = _getStyle(el, style);
}
}
// After it's all done saving all the previous states, ch... | javascript | {
"resource": ""
} |
q45379 | _outerWidth | train | function _outerWidth(el) {
var b = parseInt(_getStyle(el, 'border-left-width'), 10) + parseInt(_getStyle(el, 'border-right-width'), 10)
, p = parseInt(_getStyle(el, 'padding-left'), 10) + parseInt(_getStyle(el, 'padding-right'), 10)
, w = el.offsetWidth
, t;
// For IE in case no border is set ... | javascript | {
"resource": ""
} |
q45380 | _outerHeight | train | function _outerHeight(el) {
var b = parseInt(_getStyle(el, 'border-top-width'), 10) + parseInt(_getStyle(el, 'border-bottom-width'), 10)
, p = parseInt(_getStyle(el, 'padding-top'), 10) + parseInt(_getStyle(el, 'padding-bottom'), 10)
, w = parseInt(_getStyle(el, 'height'), 10)
, t;
// For IE i... | javascript | {
"resource": ""
} |
q45381 | _getText | train | function _getText(el) {
var theText;
// Make sure to check for type of string because if the body of the page
// doesn't have any text it'll be "" which is falsey and will go into
// the else which is meant for Firefox and shit will break
if (typeof document.body.innerText == 'string') {
theTe... | javascript | {
"resource": ""
} |
q45382 | _mergeObjs | train | function _mergeObjs() {
// copy reference to target object
var target = arguments[0] || {}
, i = 1
, length = arguments.length
, deep = false
, options
, name
, src
, copy
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
... | javascript | {
"resource": ""
} |
q45383 | shortcutHandler | train | function shortcutHandler(e) {
if (e.keyCode == self.settings.shortcut.modifier) { isMod = true } // check for modifier press(default is alt key), save to var
if (e.keyCode == 17) { isCtrl = true } // check for ctrl/cmnd press, in order to catch ctrl/cmnd + s
if (e.keyCode == 18) { isCtrl = false }
... | javascript | {
"resource": ""
} |
q45384 | deposit | train | function deposit(g, i, j, xl, displacement) {
var currentKey = j * xl + i;
// Pick a random neighbor.
for (var k = 0; k < 3; k++) {
var r = Math.floor(Math.random() * 8);
switch (r) {
case 0: i++; break;
case 1: i--; break;
... | javascript | {
"resource": ""
} |
q45385 | WhiteNoise | train | function WhiteNoise(g, options, scale, segments, range, data) {
if (scale > segments) return;
var i = 0,
j = 0,
xl = segments,
yl = segments,
inc = Math.floor(segments / scale),
lastX = -inc,
lastY = -inc;
// Walk over the t... | javascript | {
"resource": ""
} |
q45386 | gaussianBoxBlur | train | function gaussianBoxBlur(scl, w, h, r, n, tcl) {
if (typeof r === 'undefined') r = 1;
if (typeof n === 'undefined') n = 3;
if (typeof tcl === 'undefined') tcl = new Float64Array(scl.length);
var boxes = boxesForGauss(r, n);
for (var i = 0; i < n; i++) {
boxBlur(scl, tcl, w, h, (boxes[i]-1)/2... | javascript | {
"resource": ""
} |
q45387 | boxesForGauss | train | function boxesForGauss(sigma, n) {
// Calculate how far out we need to go to capture the bulk of the distribution.
var wIdeal = Math.sqrt(12*sigma*sigma/n + 1); // Ideal averaging filter width
var wl = Math.floor(wIdeal); // Lower odd integer bound on the width
if (wl % 2 === 0) wl--;
var wu = wl+2;... | javascript | {
"resource": ""
} |
q45388 | boxBlur | train | function boxBlur(scl, tcl, w, h, r) {
for (var i = 0, l = scl.length; i < l; i++) { tcl[i] = scl[i]; }
boxBlurH(tcl, scl, w, h, r);
boxBlurV(scl, tcl, w, h, r);
} | javascript | {
"resource": ""
} |
q45389 | boxBlurH | train | function boxBlurH(scl, tcl, w, h, r) {
var iarr = 1 / (r+r+1); // averaging adjustment parameter
for (var i = 0; i < h; i++) {
var ti = i * w, // current target index
li = ti, // current left side of the examined range
ri = ti + r, // current right side of the examined range
... | javascript | {
"resource": ""
} |
q45390 | distanceToNearest | train | function distanceToNearest(coords, points, distanceType) {
var color = Infinity,
distanceFunc = 'distanceTo' + distanceType;
for (var k = 0; k < points.length; k++) {
var d = points[k][distanceFunc](coords);
if (d < color) {
color = d;
}
... | javascript | {
"resource": ""
} |
q45391 | watchFocus | train | function watchFocus() {
var _blurred = false;
window.addEventListener('focus', function() {
if (_blurred) {
_blurred = false;
// startAnimating();
// controls.freeze = false;
}
});
window.addEventListener('blur', function() {
// stopAnimating();
_blurred = true;
controls.fr... | javascript | {
"resource": ""
} |
q45392 | numberToCategory | train | function numberToCategory(value, buckets) {
if (!buckets) {
buckets = [-2, -2/3, 2/3, 2];
}
if (typeof buckets.length === 'number' && buckets.length > 3) {
if (value < buckets[0]) return 'very low';
if (value < buckets[1]) return 'low';
if (value < buckets[2]) return 'medi... | javascript | {
"resource": ""
} |
q45393 | percentRank | train | function percentRank(arr, v) {
if (typeof v !== 'number') throw new TypeError('v must be a number');
for (var i = 0, l = arr.length; i < l; i++) {
if (v <= arr[i]) {
while (i < l && v === arr[i]) {
i++;
}
if (i === 0) return 0;
if (v !== ar... | javascript | {
"resource": ""
} |
q45394 | getFittedPlaneNormal | train | function getFittedPlaneNormal(points, centroid) {
var n = points.length,
xx = 0,
xy = 0,
xz = 0,
yy = 0,
yz = 0,
zz = 0;
if (n < 3) throw new Error('At least three points are required to fit a plane');
var r = new THREE.Vector3();
for (var i = 0, l = poin... | javascript | {
"resource": ""
} |
q45395 | bucketNumbersLinearly | train | function bucketNumbersLinearly(data, bucketCount, min, max) {
var i = 0,
l = data.length;
// If min and max aren't given, set them to the highest and lowest data values
if (typeof min === 'undefined') {
min = Infinity;
max = -Infinity;
for (i = 0; i < l; i++) {
if... | javascript | {
"resource": ""
} |
q45396 | percentVariationExplainedByFittedPlane | train | function percentVariationExplainedByFittedPlane(vertices, centroid, normal, range) {
var numVertices = vertices.length,
diff = 0;
for (var i = 0; i < numVertices; i++) {
var fittedZ = Math.sqrt(
(vertices[i].x - centroid.x) * (vertices[i].x - centroid.x) +
(vertic... | javascript | {
"resource": ""
} |
q45397 | convolve | train | function convolve(src, kernel, tgt) {
// src and kernel must be nonzero rectangular number arrays.
if (!src.length || !kernel.length) return src;
// Initialize tracking variables.
var i = 0, // current src x-position
j = 0, // current src y-position
a = 0, // current kernel x-position
... | javascript | {
"resource": ""
} |
q45398 | gauss | train | function gauss(x, s) {
// 2.5066282746310005 is sqrt(2*pi)
return Math.exp(-0.5 * x*x / (s*s)) / (s * 2.5066282746310005);
} | javascript | {
"resource": ""
} |
q45399 | gaussianKernel1D | train | function gaussianKernel1D(s, n) {
if (typeof n !== 'number') n = 7;
var kernel = new Float64Array(n),
halfN = Math.floor(n * 0.5),
odd = n % 2,
i;
if (!s || !n) return kernel;
for (i = 0; i <= halfN; i++) {
kernel[i] = gauss(s * (i - halfN - odd * 0.5), s);
}
for ... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.