_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q28000
defineNativeMethodsOnChainable
train
function defineNativeMethodsOnChainable() { var nativeTokens = { 'Function': 'apply,call', 'RegExp': 'compile,exec,test', 'Number': 'toExponential,toFixed,toLocaleString,toPrecision', 'Object': 'hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString', 'Array': 'concat,join,pop,...
javascript
{ "resource": "" }
q28001
showHelp
train
function showHelp(specifiedScripts) { if (parsedArgv.help) { // if --help was specified, then yargs will show the default help log.info(help(psConfig)) return true } const helpStyle = String(psConfig.options['help-style']) const hasDefaultScript = Boolean(psConfig.scripts.default) ...
javascript
{ "resource": "" }
q28002
stringifyObject
train
function stringifyObject(object, indent) { return Object.keys(object).reduce((string, key, index) => { const script = object[key] let value if (isPlainObject(script)) { value = `{${stringifyObject(script, `${indent} `)}\n${indent}}` } else { value = `'${escapeSingleQuote(script)}'` } ...
javascript
{ "resource": "" }
q28003
loadConfig
train
function loadConfig(configPath, input) { let config if (configPath.endsWith('.yml') || configPath.endsWith('.yaml')) { config = loadYAMLConfig(configPath) } else { config = loadJSConfig(configPath) } if (isUndefined(config)) { // let the caller deal with this return config } let typeMessa...
javascript
{ "resource": "" }
q28004
addData
train
function addData (db, mime, source) { Object.keys(mime).forEach(function (key) { var data = mime[key] var type = key.toLowerCase() var obj = db[type] = db[type] || createTypeEntry(source) // add missing data setValue(obj, 'charset', data.charset) setValue(obj, 'compressible', data.compressibl...
javascript
{ "resource": "" }
q28005
appendExtension
train
function appendExtension (obj, extension) { if (!obj.extensions) { obj.extensions = [] } if (obj.extensions.indexOf(extension) === -1) { obj.extensions.push(extension) } }
javascript
{ "resource": "" }
q28006
appendExtensions
train
function appendExtensions (obj, extensions) { if (!extensions) { return } for (var i = 0; i < extensions.length; i++) { var extension = extensions[i] // add extension to the type entry appendExtension(obj, extension) } }
javascript
{ "resource": "" }
q28007
setValue
train
function setValue (obj, prop, value) { if (value !== undefined && obj[prop] === undefined) { obj[prop] = value } }
javascript
{ "resource": "" }
q28008
get
train
function get (url, callback) { https.get(url, function onResponse (res) { if (res.statusCode !== 200) { callback(new Error('got status code ' + res.statusCode + ' from ' + URL)) } else { getBody(res, true, callback) } }) }
javascript
{ "resource": "" }
q28009
parseScope
train
function parseScope( path, obj ) { return path.split('.').reduce( function( prev, curr ) { return prev[curr]; }, obj || this ); }
javascript
{ "resource": "" }
q28010
train
function(el) { (el.length > 0) && (el = el[0]); var orgAttributes = {}; for (var i=0; i<el.attributes.length; i++) { var attr = el.attributes[i]; orgAttributes[attr.name] = attr.value; } return orgAttributes; }
javascript
{ "resource": "" }
q28011
train
function(scope, attrs) { var events = {}; var toLowercaseFunc = function($1){ return "_"+$1.toLowerCase(); }; var EventFunc = function(attrValue) { // funcName(argsStr) var matches = attrValue.match(/([^\(]+)\(([^\)]*)\)/); var funcName = matches[1]; var a...
javascript
{ "resource": "" }
q28012
train
function(filtered) { var controlOptions = {}; if (typeof filtered != 'object') { return false; } for (var attr in filtered) { if (filtered[attr]) { if (!attr.match(/(.*)ControlOptions$/)) { continue; // if not controlOptions, skip it } ...
javascript
{ "resource": "" }
q28013
train
function(map, panoId) { var svp = new google.maps.StreetViewPanorama( map.getDiv(), {enableCloseButton: true} ); svp.setPano(panoId); }
javascript
{ "resource": "" }
q28014
pages
train
function pages() { return gulp.src(['src/pages/**/*.html', '!src/pages/archive/**/*.html']) .pipe(panini({ root: 'src/pages', layouts: 'src/layouts', partials: 'src/partials', helpers: 'src/helpers' })) .pipe(inky()) .pipe(gulp.dest('dist')); }
javascript
{ "resource": "" }
q28015
sass
train
function sass() { return gulp.src('src/assets/scss/app.scss') .pipe($.if(!PRODUCTION, $.sourcemaps.init())) .pipe($.sass({ includePaths: ['node_modules/foundation-emails/scss'] }).on('error', $.sass.logError)) .pipe($.if(PRODUCTION, $.uncss( { html: ['dist/**/*.html'] }))) ...
javascript
{ "resource": "" }
q28016
watch
train
function watch() { gulp.watch('src/pages/**/*.html').on('all', gulp.series(pages, inline, browser.reload)); gulp.watch(['src/layouts/**/*', 'src/partials/**/*']).on('all', gulp.series(resetPages, pages, inline, browser.reload)); gulp.watch(['../scss/**/*.scss', 'src/assets/scss/**/*.scss']).on('all', gulp.series(...
javascript
{ "resource": "" }
q28017
creds
train
function creds(done) { var configPath = './config.json'; try { CONFIG = JSON.parse(fs.readFileSync(configPath)); } catch(e) { beep(); console.log('[AWS]'.bold.red + ' Sorry, there was an issue locating your config.json. Please see README.md'); process.exit(); } done(); }
javascript
{ "resource": "" }
q28018
aws
train
function aws() { var publisher = !!CONFIG.aws ? $.awspublish.create(CONFIG.aws) : $.awspublish.create(); var headers = { 'Cache-Control': 'max-age=315360000, no-transform, public' }; return gulp.src('./dist/assets/img/*') // publisher will add Content-Length, Content-Type and headers specified above ...
javascript
{ "resource": "" }
q28019
litmus
train
function litmus() { var awsURL = !!CONFIG && !!CONFIG.aws && !!CONFIG.aws.url ? CONFIG.aws.url : false; return gulp.src('dist/**/*.html') .pipe($.if(!!awsURL, $.replace(/=('|")(\/?assets\/img)/g, "=$1"+ awsURL))) .pipe($.litmus(CONFIG.litmus)) .pipe(gulp.dest('dist')); }
javascript
{ "resource": "" }
q28020
mail
train
function mail() { var awsURL = !!CONFIG && !!CONFIG.aws && !!CONFIG.aws.url ? CONFIG.aws.url : false; if (EMAIL) { CONFIG.mail.to = [EMAIL]; } return gulp.src('dist/**/*.html') .pipe($.if(!!awsURL, $.replace(/=('|")(\/?assets\/img)/g, "=$1"+ awsURL))) .pipe($.mail(CONFIG.mail)) .pipe(gulp.dest...
javascript
{ "resource": "" }
q28021
zip
train
function zip() { var dist = 'dist'; var ext = '.html'; function getHtmlFiles(dir) { return fs.readdirSync(dir) .filter(function(file) { var fileExt = path.join(dir, file); var isHtml = path.extname(fileExt) == ext; return fs.statSync(fileExt).isFile() && isHtml; }); } ...
javascript
{ "resource": "" }
q28022
train
function() { if (this.$element[0] instanceof document.constructor && !this.options.selector) { throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!'); } if (this.getTrigger() !== 'manu...
javascript
{ "resource": "" }
q28023
some
train
function some(array, member) { if(isUndefined(member)) { return false; } return array.some(function(el) { return equals(el, member); }); }
javascript
{ "resource": "" }
q28024
indexOf
train
function indexOf(word, p, c) { var j = 0; while ((p + j) <= word.length) { if (word.charAt(p + j) == c) return j; j++; } return -1; }
javascript
{ "resource": "" }
q28025
hasSimilarSelectors
train
function hasSimilarSelectors(selectors1, selectors2) { var cursor1 = selectors1.head; while (cursor1 !== null) { var cursor2 = selectors2.head; while (cursor2 !== null) { if (cursor1.data.compareMarker === cursor2.data.compareMarker) { return true; } ...
javascript
{ "resource": "" }
q28026
unsafeToSkipNode
train
function unsafeToSkipNode(node) { switch (node.type) { case 'Rule': // unsafe skip ruleset with selector similarities return hasSimilarSelectors(node.prelude.children, this); case 'Atrule': // can skip at-rules with blocks if (node.block) { ...
javascript
{ "resource": "" }
q28027
throttled
train
function throttled (fn, delay) { let lastCall = 0 return function (...args) { const now = new Date().getTime() if (now - lastCall < delay) { return } lastCall = now return fn(...args) } }
javascript
{ "resource": "" }
q28028
train
function(path, options) { var self = this; // options if (typeof(options) === "undefined") options = {}; // disable auto open, as we handle the open options.autoOpen = false; // internal buffer this._buffer = Buffer.alloc(0); this._id = 0; this._cmd = 0; this._length = 0; ...
javascript
{ "resource": "" }
q28029
checkError
train
function checkError(e) { if(e.errno && networkErrors.includes(e.errno)) { console.log("we have to reconnect"); // close port client.close(); // re open client client = new ModbusRTU(); timeoutConnectRef = setTimeout(connect, 1000); } }
javascript
{ "resource": "" }
q28030
connect
train
function connect() { // clear pending timeouts clearTimeout(timeoutConnectRef); // if client already open, just run if (client.isOpen) { run(); } // if client closed, open a new connection client.connectTCP("127.0.0.1", { port: 8502 }) .then(setClient) .then(functio...
javascript
{ "resource": "" }
q28031
_asciiEncodeRequestBuffer
train
function _asciiEncodeRequestBuffer(buf) { // replace the 2 byte crc16 with a single byte lrc buf.writeUInt8(calculateLrc(buf.slice(0, -2)), buf.length - 2); // create a new buffer of the correct size var bufAscii = Buffer.alloc(buf.length * 2 + 1); // 1 byte start delimit + x2 data as ascii encoded + ...
javascript
{ "resource": "" }
q28032
_asciiDecodeResponseBuffer
train
function _asciiDecodeResponseBuffer(bufAscii) { // create a new buffer of the correct size (based on ascii encoded buffer length) var bufDecoded = Buffer.alloc((bufAscii.length - 1) / 2); // decode into new buffer (removing delimiters at start and end) for (var i = 0; i < (bufAscii.length - 3) / 2; i+...
javascript
{ "resource": "" }
q28033
_checkData
train
function _checkData(modbus, buf) { // check buffer size if (buf.length !== modbus._length && buf.length !== 5) { modbusSerialDebug({ action: "length error", recive: buf.length, expected: modbus._length }); return false; } // check buffer unit-id and command return (buf[0] === modbu...
javascript
{ "resource": "" }
q28034
train
function(path, options) { var modbus = this; // options options = options || {}; // disable auto open, as we handle the open options.autoOpen = false; // internal buffer this._buffer = Buffer.from(""); this._id = 0; this._cmd = 0; this._length = 0; // create the SerialPor...
javascript
{ "resource": "" }
q28035
_startTimeout
train
function _startTimeout(duration, transaction) { if (!duration) { return undefined; } return setTimeout(function() { transaction._timeoutFired = true; if (transaction.next) { transaction.next(new TransactionTimedOutError()); } }, duration); }
javascript
{ "resource": "" }
q28036
_handlePromiseOrValue
train
function _handlePromiseOrValue(promiseOrValue, cb) { if (promiseOrValue && promiseOrValue.then && typeof promiseOrValue.then === "function") { promiseOrValue .then(function(value) { cb(null, value); }) .catch(function(err) { cb(err); ...
javascript
{ "resource": "" }
q28037
_handleReadCoilsOrInputDiscretes
train
function _handleReadCoilsOrInputDiscretes(requestBuffer, vector, unitID, callback, fc) { var address = requestBuffer.readUInt16BE(2); var length = requestBuffer.readUInt16BE(4); if (_errorRequestBufferLength(requestBuffer)) { return; } // build answer var dataBytes = parseInt((length -...
javascript
{ "resource": "" }
q28038
_handleWriteCoil
train
function _handleWriteCoil(requestBuffer, vector, unitID, callback) { var address = requestBuffer.readUInt16BE(2); var state = requestBuffer.readUInt16BE(4); if (_errorRequestBufferLength(requestBuffer)) { return; } // build answer var responseBuffer = Buffer.alloc(8); responseBuffe...
javascript
{ "resource": "" }
q28039
_handleWriteSingleRegister
train
function _handleWriteSingleRegister(requestBuffer, vector, unitID, callback) { var address = requestBuffer.readUInt16BE(2); var value = requestBuffer.readUInt16BE(4); if (_errorRequestBufferLength(requestBuffer)) { return; } // build answer var responseBuffer = Buffer.alloc(8); res...
javascript
{ "resource": "" }
q28040
_handleForceMultipleCoils
train
function _handleForceMultipleCoils(requestBuffer, vector, unitID, callback) { var address = requestBuffer.readUInt16BE(2); var length = requestBuffer.readUInt16BE(4); // if length is bad, ignore message if (requestBuffer.length !== 7 + Math.ceil(length / 8) + 2) { return; } // build an...
javascript
{ "resource": "" }
q28041
_handleWriteMultipleRegisters
train
function _handleWriteMultipleRegisters(requestBuffer, vector, unitID, callback) { var address = requestBuffer.readUInt16BE(2); var length = requestBuffer.readUInt16BE(4); // if length is bad, ignore message if (requestBuffer.length !== (7 + length * 2 + 2)) { return; } // build answer ...
javascript
{ "resource": "" }
q28042
_handleMEI
train
function _handleMEI(requestBuffer, vector, unitID, callback) { var MEIType = requestBuffer[2]; switch(parseInt(MEIType)) { case 14: _handleReadDeviceIdentification(requestBuffer, vector, unitID, callback); break; default: callback({ modbusErrorCode: 0x01 }); /...
javascript
{ "resource": "" }
q28043
_serverDebug
train
function _serverDebug(text, unitID, functionCode, responseBuffer) { // If no responseBuffer, then assume this is an error // o/w assume an action if (typeof responseBuffer === "undefined") { modbusSerialDebug({ error: text, unitID: unitID, functionCode: functionCo...
javascript
{ "resource": "" }
q28044
_callbackFactory
train
function _callbackFactory(unitID, functionCode, sockWriter) { return function cb(err, responseBuffer) { var crc; // If we have an error. if (err) { var errorCode = 0x04; // slave device failure if (!isNaN(err.modbusErrorCode)) { errorCode = err.modbus...
javascript
{ "resource": "" }
q28045
_parseModbusBuffer
train
function _parseModbusBuffer(requestBuffer, vector, serverUnitID, sockWriter) { var cb; // Check requestBuffer length if (!requestBuffer || requestBuffer.length < MBAP_LEN) { modbusSerialDebug("wrong size of request Buffer " + requestBuffer.length); return; } var unitID = requestBuf...
javascript
{ "resource": "" }
q28046
_checkData
train
function _checkData(modbus, buf) { // check buffer size if (buf.length !== modbus._length && buf.length !== 5) return false; // calculate crc16 var crcIn = buf.readUInt16LE(buf.length - 2); // check buffer unit-id, command and crc return (buf[0] === modbus._id && (0x7f & buf[1]) === mo...
javascript
{ "resource": "" }
q28047
train
function(ip, options) { var modbus = this; this.ip = ip; this.openFlag = false; // options if (typeof(options) === "undefined") options = {}; this.port = options.port || C701_PORT; // C701 port // create a socket this._client = dgram.createSocket("udp4"); // wait for answer th...
javascript
{ "resource": "" }
q28048
checkGraphvizInstalled
train
function checkGraphvizInstalled(config) { if (config.graphVizPath) { const cmd = path.join(config.graphVizPath, 'gvpr -V'); return exec(cmd) .catch(() => { throw new Error('Could not execute ' + cmd); }); } return exec('gvpr -V') .catch((error) => { throw new Error('Graphviz could not be found. E...
javascript
{ "resource": "" }
q28049
createGraphvizOptions
train
function createGraphvizOptions(config) { const graphVizOptions = config.graphVizOptions || {}; return { G: Object.assign({ overlap: false, pad: 0.3, rankdir: config.rankdir, layout: config.layout, bgcolor: config.backgroundColor }, graphVizOptions.G), E: Object.assign({ color: config.edgeColo...
javascript
{ "resource": "" }
q28050
createGraph
train
function createGraph(modules, circular, config, options) { const g = graphviz.digraph('G'); const nodes = {}; const cyclicModules = circular.reduce((a, b) => a.concat(b), []); if (config.graphVizPath) { g.setGraphVizPath(config.graphVizPath); } Object.keys(modules).forEach((id) => { nodes[id] = nodes[id] ||...
javascript
{ "resource": "" }
q28051
getPath
train
function getPath(parent, unresolved) { let parentVisited = false; return Object.keys(unresolved).filter((module) => { if (module === parent) { parentVisited = true; } return parentVisited && unresolved[module]; }); }
javascript
{ "resource": "" }
q28052
resolver
train
function resolver(id, modules, circular, resolved, unresolved) { unresolved[id] = true; if (modules[id]) { modules[id].forEach((dependency) => { if (!resolved[dependency]) { if (unresolved[dependency]) { circular.push(getPath(dependency, unresolved)); return; } resolver(dependency, modules...
javascript
{ "resource": "" }
q28053
tryInitOrHookIntoEvents
train
function tryInitOrHookIntoEvents(options, $that) { var success = tryInit(options, $that); if (!success) { console.log('TSS: Body width smaller than options.minWidth. Init is delayed.'); $(document).on('scroll.' + options.namespace, function (options, $that) { ...
javascript
{ "resource": "" }
q28054
tryInit
train
function tryInit(options, $that) { if (options.initialized === true) { return true; } if ($('body').width() < options.minWidth) { return false; } init(options, $that); return true; }
javascript
{ "resource": "" }
q28055
getClearedHeight
train
function getClearedHeight(e) { var height = e.height(); e.children().each(function () { height = Math.max(height, $(this).height()); }); return height; }
javascript
{ "resource": "" }
q28056
isSameValue
train
function isSameValue(a, b) { const [propA, propB] = [a, b].map(value => ( isArray(value) ? [...value].sort() : value )); return isEqual(propA, propB); }
javascript
{ "resource": "" }
q28057
upgrade
train
function upgrade(template) { const type = OWNER_SVG_ELEMENT in this ? 'svg' : 'html'; const tagger = new Tagger(type); bewitched.set(this, {tagger, template: template}); this.textContent = ''; this.appendChild(tagger.apply(null, arguments)); }
javascript
{ "resource": "" }
q28058
hyper
train
function hyper(HTML) { return arguments.length < 2 ? (HTML == null ? content('html') : (typeof HTML === 'string' ? hyper.wire(null, HTML) : ('raw' in HTML ? content('html')(HTML) : ('nodeType' in HTML ? hyper.bind(HTML) : weakly(HTML, 'html')...
javascript
{ "resource": "" }
q28059
train
function (options) { google.maps.Marker.prototype.setMap.apply(this, [options]); (this.MarkerLabel) && this.MarkerLabel.setMap.apply(this.MarkerLabel, [options]); }
javascript
{ "resource": "" }
q28060
train
function () { this.div.parentNode.removeChild(this.div); for (var i = 0, I = this.listeners.length; i < I; ++i) { google.maps.event.removeListener(this.listeners[i]); } }
javascript
{ "resource": "" }
q28061
basicAuth
train
function basicAuth(checker, realm) { realm = realm || 'Authorization Required'; function unauthorized(res) { res.writeHead(401, { 'WWW-Authenticate': 'Basic realm="' + realm + '"', 'Content-Length': 13 }); res.end("Unauthorize...
javascript
{ "resource": "" }
q28062
getReactProps
train
function getReactProps(node, parent) { if (node.openingElement.attributes.length === 0 || htmlElements.indexOf(node.openingElement.name.name) > 0) return {}; const result = node.openingElement.attributes .map(attribute => { const name = attribute.name.name; let valueName; if (attribute.value...
javascript
{ "resource": "" }
q28063
getChildJSXElements
train
function getChildJSXElements(node, parent) { if (node.children.length === 0) return []; const childJsxComponentsArr = node .children .filter(jsx => jsx.type === 'JSXElement' && htmlElements.indexOf(jsx.openingElement.name.name) < 0); return childJsxComponentsArr .map(child => { return { ...
javascript
{ "resource": "" }
q28064
isES6ReactComponent
train
function isES6ReactComponent(node) { return (node.superClass.property && node.superClass.property.name === 'Component') || node.superClass.name === 'Component'; }
javascript
{ "resource": "" }
q28065
jsToAst
train
function jsToAst(js) { const ast = acorn.parse(js, { plugins: { jsx: true }, }); if (ast.body.length === 0) throw new Error('Empty AST input'); return ast; }
javascript
{ "resource": "" }
q28066
d3DataBuilder
train
function d3DataBuilder(obj) { if (!obj.ENTRY) throw new Error('Entry component not found'); const formatted = {}; // parsing AST into formatted objects based on ES5/ES6 syntax Object.entries(obj).forEach(entry => { if (entry[0] === 'ENTRY') return; const componentChecker = reactParser.componentChecker(...
javascript
{ "resource": "" }
q28067
assignFiberPropertiesInDEV
train
function assignFiberPropertiesInDEV(target, source) { if (target === null) { // This Fiber's initial properties will always be overwritten. // We only use a Fiber to ensure the same hidden class so DEV isn't slow. target = createFiber(IndeterminateComponent, null, null, NoContext); } // This is inten...
javascript
{ "resource": "" }
q28068
processor
train
function processor() { var destination = unified() var length = attachers.length var index = -1 while (++index < length) { destination.use.apply(null, attachers[index]) } destination.data(extend(true, {}, namespace)) return destination }
javascript
{ "resource": "" }
q28069
toByteArray
train
function toByteArray(obj) { var uint = new Uint8Array(obj.length); for (var i = 0, l = obj.length; i < l; i++){ uint[i] = obj.charCodeAt(i); } return new Uint8Array(uint); }
javascript
{ "resource": "" }
q28070
Vehicle
train
function Vehicle(id, token, unitSystem) { if (!(this instanceof Vehicle)) { // eslint-disable-next-line max-len throw new TypeError("Class constructor Vehicle cannot be invoked without 'new'"); } this.id = id; this.token = token; this.request = util.request.defaults({ baseUrl: util.getUrl(this.id...
javascript
{ "resource": "" }
q28071
relativePath
train
function relativePath(file1, file2) { var file1Dirname = path.dirname(file1); var file2Dirname = path.dirname(file2); if (file1Dirname !== file2Dirname) { return path.relative(file1Dirname, file2Dirname); } return ''; }
javascript
{ "resource": "" }
q28072
curry
train
function curry( func ) { var args = aps.call( arguments, 1 ); return function() { return func.apply( this, args.concat( aps.call( arguments ) ) ); }; }
javascript
{ "resource": "" }
q28073
train
function(d) { return function(t) { var c = d.sets.map(function(set) { var start = previous[set], end = circles[set]; if (!start) { start = {x : width/2, y : height/2, radius : 1}; } if (!e...
javascript
{ "resource": "" }
q28074
shouldExclude
train
function shouldExclude(sets) { for (var i = 0; i < sets.length; ++i) { if (!(sets[i] in exclude)) { return false; } } return true; }
javascript
{ "resource": "" }
q28075
containedInCircles
train
function containedInCircles(point, circles) { for (var i = 0; i < circles.length; ++i) { if (distance(point, circles[i]) > circles[i].radius + SMALL) { return false; } } return true; }
javascript
{ "resource": "" }
q28076
getIntersectionPoints
train
function getIntersectionPoints(circles) { var ret = []; for (var i = 0; i < circles.length; ++i) { for (var j = i + 1; j < circles.length; ++j) { var intersect = circleCircleIntersection(circles[i], circles[j]); ...
javascript
{ "resource": "" }
q28077
distance
train
function distance(p1, p2) { return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); }
javascript
{ "resource": "" }
q28078
circleOverlap
train
function circleOverlap(r1, r2, d) { // no overlap if (d >= r1 + r2) { return 0; } // completely overlapped if (d <= Math.abs(r1 - r2)) { return Math.PI * Math.min(r1, r2) * Math.min(r1, r2); } var w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (...
javascript
{ "resource": "" }
q28079
getCenter
train
function getCenter(points) { var center = {x: 0, y: 0}; for (var i =0; i < points.length; ++i ) { center.x += points[i].x; center.y += points[i].y; } center.x /= points.length; center.y /= points.length; return center; }
javascript
{ "resource": "" }
q28080
bisect
train
function bisect(f, a, b, parameters) { parameters = parameters || {}; var maxIterations = parameters.maxIterations || 100, tolerance = parameters.tolerance || 1e-10, fA = f(a), fB = f(b), delta = b - a; if (fA * fB > 0) { throw "Initia...
javascript
{ "resource": "" }
q28081
distanceFromIntersectArea
train
function distanceFromIntersectArea(r1, r2, overlap) { // handle complete overlapped circles if (Math.min(r1, r2) * Math.min(r1,r2) * Math.PI <= overlap + SMALL$1) { return Math.abs(r1 - r2); } return bisect(function(distance$$1) { return circleOverlap(r1, r2, dis...
javascript
{ "resource": "" }
q28082
train
function(value, context, scope) { return this.isInstance(value, context, scope) || (Jsonix.Util.Type.isObject(value) && !Jsonix.Util.Type.isArray(value)); }
javascript
{ "resource": "" }
q28083
train
function(value){ value = Function.from(value)(); value = (typeof value == 'string') ? value.split(' ') : Array.from(value); return value.map(function(val){ val = String(val); var found = false; Object.each(Fx.CSS.Parsers, function(parser, key){ if (found) return; var parsed = parser.parse(val); ...
javascript
{ "resource": "" }
q28084
train
function(from, to, delta){ var computed = []; (Math.min(from.length, to.length)).times(function(i){ computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser}); }); computed.$family = Function.from('fx:css:value'); return computed; }
javascript
{ "resource": "" }
q28085
train
function(value, unit){ if (typeOf(value) != 'fx:css:value') value = this.parse(value); var returned = []; value.each(function(bit){ returned = returned.concat(bit.parser.serve(bit.value, unit)); }); return returned; }
javascript
{ "resource": "" }
q28086
train
function(element, property, value, unit){ element.setStyle(property, this.serve(value, unit)); }
javascript
{ "resource": "" }
q28087
isScriptLoaded
train
function isScriptLoaded(elem,scriptentry) { if ((elem[sREADYSTATE] && elem[sREADYSTATE]!==sCOMPLETE && elem[sREADYSTATE]!=="loaded") || scriptentry[sDONE]) { return bFALSE; } elem[sONLOAD] = elem[sONREADYSTATECHANGE] = nNULL; // prevent memory leak return bTRUE; }
javascript
{ "resource": "" }
q28088
resetScroll
train
function resetScroll() { // Set the element to it original positioning. target.trigger('preUnfixed.ScrollToFixed'); setUnfixed(); target.trigger('unfixed.ScrollToFixed'); // Reset the last offset used to determine if the page has moved // horizont...
javascript
{ "resource": "" }
q28089
setFixed
train
function setFixed() { // Only fix the target element and the spacer if we need to. if (!isFixed()) { //get REAL dimensions (decimal fix) //Ref. http://stackoverflow.com/questions/3603065/how-to-make-jquery-to-not-round-value-returned-by-width var d...
javascript
{ "resource": "" }
q28090
setUnfixed
train
function setUnfixed() { // Only unfix the target element and the spacer if we need to. if (!isUnfixed()) { lastOffsetLeft = -1; // Hide the spacer now that the target element will fill the // space. spacer.css('display', 'none'); ...
javascript
{ "resource": "" }
q28091
setLeft
train
function setLeft(x) { // Only if the scroll is not what it was last time we did this. if (x != lastOffsetLeft) { // Move the target element horizontally relative to its original // horizontal position. target.css('left', offsetLeft - x); ...
javascript
{ "resource": "" }
q28092
rstr2binb
train
function rstr2binb(input) { var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length; for (i = 0; i < lo; i += 1) { output[i] = 0; } for (i = 0; i < l; i += 8) { output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32); } return output...
javascript
{ "resource": "" }
q28093
train
function(str) { var crc = 0, x = 0, y = 0, table, i, iTop; str = utf8Encode(str); table = [ '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ', '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3...
javascript
{ "resource": "" }
q28094
rstr
train
function rstr(s) { s = (utf8) ? utf8Encode(s) : s; return binl2rstr(binl(rstr2binl(s), s.length * 8)); }
javascript
{ "resource": "" }
q28095
rstr
train
function rstr(s, utf8) { s = (utf8) ? utf8Encode(s) : s; return binb2rstr(binb(rstr2binb(s), s.length * 8)); }
javascript
{ "resource": "" }
q28096
int64copy
train
function int64copy(dst, src) { dst.h = src.h; dst.l = src.l; }
javascript
{ "resource": "" }
q28097
int64revrrot
train
function int64revrrot(dst, x, shift) { dst.l = (x.h >>> shift) | (x.l << (32 - shift)); dst.h = (x.l >>> shift) | (x.h << (32 - shift)); }
javascript
{ "resource": "" }
q28098
int64shr
train
function int64shr(dst, x, shift) { dst.l = (x.l >>> shift) | (x.h << (32 - shift)); dst.h = (x.h >>> shift); }
javascript
{ "resource": "" }
q28099
int64add
train
function int64add(dst, x, y) { var w0 = (x.l & 0xffff) + (y.l & 0xffff); var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16); var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16); var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16); dst.l = (w0 & 0xffff) | (w1 << 16); dst...
javascript
{ "resource": "" }