Lookup the magic number in magic-number DB
@param {Buffer} buf Data buffer
@param {function} cb Callback to invoke on completion
331435
function magic(buf, cb) {
  setTimeout(() => {
    const sampleLength = 24;
    const sample = buf.slice(0, sampleLength).toString('hex'); // lookup data

    const found = Object.keys(_magicDb2.default).find(it => {
      return sample.indexOf(it) != -1;
    });

    if (found) {
      cb(null, _magicDb2.default[found]);
    } else {
      cb(new Error('Magic number not found'));
    }
  }, 0);
}
510549
def process_lit(exp)
      exp.shift
      value = exp.shift

      if value.is_a?(Numeric) && !@ignore.include?(value)
        @file.magic_numbers << MagicNumber.new(:value => value, :line => exp.line)
      end

      s()
    end
490805
function parse_BOF(blob, length) {
	var o = {BIFFVer:0, dt:0};
	o.BIFFVer = blob.read_shift(2); length -= 2;
	if(length >= 2) { o.dt = blob.read_shift(2); blob.l -= 2; }
	switch(o.BIFFVer) {
		case 0x0600: /* BIFF8 */
		case 0x0500: /* BIFF5 */
		case 0x0400: /* BIFF4 */
		case 0x0300: /* BIFF3 */
		case 0x0200: /* BIFF2 */
		case 0x0002: case 0x0007: /* BIFF2 */
			break;
		default: if(length > 6) throw new Error("Unexpected BIFF Ver " + o.BIFFVer);
	}

	blob.read_shift(length);
	return o;
}
1140820
function makeCountNCallback(n, cb) {
        var count = 0,
            results = [],
            error;
        return function(index, err, result) {
            results[index] = result;
            if (!error && err) {
                error = err;
                return cb(err);
            }
            if (!error && ++count == n) {
                cb(null, results);
            }
        };
    }
201102
function(cb) {
    // return early if already connected
    if (_socket) {
      return cb(null, {host: _options.host, port: _options.port});
    }

    _socket = net.createConnection(_options.port, _options.host);

    _socket.on('connect', function() {
      if (cb) {
        cb(null, {host: _options.host, port: _options.port});
      }
    });

    _socket.on('data', function(buf) {
      var res;
      var rblock;
      var decoder;

      if (!_rcvBuf) {
        _rcvBuf = kb();
      }
      _rcvBuf.append(buf);
      res = response.decodeHead(_rcvBuf.get());
      // console.log(res)

      // buffer can have more than one msg...
      // don't want to drop msgs
      while (_rcvBuf.length() > 0 && _rcvBuf.length() >= res.size + 4) {
        decoder = _cbt.remove(res.correlation);
        rblock = decoder.decode(_rcvBuf.get(), res);

        _rcvBuf.slice(res.size + 4);

        if (_rcvBuf.length() > 0) {
          res = response.decodeHead(_rcvBuf.get());
        }

        decoder.callback(rblock.err, rblock.result);
      }
    });

    _socket.on('end', function() {});

    _socket.on('timeout', function(){
      console.log('socket timeout');
    });

    _socket.on('drain', function(){});

    _socket.on('error', function(err){
      console.log('SOCKET ERROR: ' + err);
    });

    _socket.on('close', function(){});
  }
1011018
def db_get(self, db_number):
        
        logger.debug("db_get db_number: %s" % db_number)
        _buffer = buffer_type()
        result = self.library.Cli_DBGet(
            self.pointer, db_number, byref(_buffer),
            byref(c_int(buffer_size)))
        check_error(result, context="client")
        return bytearray(_buffer)
1085921
function findOrCreate(params, cb) {
	/* istanbul ignore next */
	if (typeof cb !== 'function') {
		throw new Error('Callback must be a function');
	}

	db.findOne(params, (err, doc) => {
		/* istanbul ignore next: hard-to-invoke error */
		if (err) {
			cb(err);
			return;
		}

		if (doc) {
			cb(null, doc.token);
		} else {
			params.token = uuid();
			db.insert(params, (err, newDoc) => {
				/* istanbul ignore next: hard-to-invoke error */
				if (err) {
					cb(err);
					return;
				}

				cb(null, newDoc.token);
			});
		}
	});
}
1212220
function func1(info, cb, resource) {
  let error
  log.debug('Calling func1', data)
  cb(error)
  return false
}
686319
def set_key_callback(window, cbfun):
    
    window_addr = ctypes.cast(ctypes.pointer(window),
                              ctypes.POINTER(ctypes.c_long)).contents.value
    if window_addr in _key_callback_repository:
        previous_callback = _key_callback_repository[window_addr]
    else:
        previous_callback = None
    if cbfun is None:
        cbfun = 0
    c_cbfun = _GLFWkeyfun(cbfun)
    _key_callback_repository[window_addr] = (cbfun, c_cbfun)
    cbfun = c_cbfun
    _glfw.glfwSetKeyCallback(window, cbfun)
    if previous_callback is not None and previous_callback[0] != 0:
        return previous_callback[0]
323877
def _get_file_magic_name(self, buffer):
        
        default = "Unknown"
        ftype = None

        try:
            # Magic is optional
            import magic
        except ImportError:
            return default

        try:
            # There are several implementations of magic,
            # unfortunately all called magic
            # We use this one: https://github.com/ahupp/python-magic/
            getattr(magic, "MagicException")
        except AttributeError:
            # Looks like no magic was installed
            return default

        try:
            ftype = magic.from_buffer(buffer[:1024])
        except magic.MagicError as e:
            log.exception("Error getting the magic type!")
            return default

        if not ftype:
            return default
        else:
            return self._patch_magic(buffer, ftype)
1296825
function amf0decArray(buf) {
//    var count = buf.readUInt32BE(1);
    var obj = amf0decObject(buf.slice(4));
    return { len: 5 + obj.len, value: obj.value }
}
1252432
private BigDecimal parseMediumNumber(final NumberBuffer buffer) {
        BigDecimal sum = BigDecimal.ZERO;
        BigDecimal result = parseMediumPair(buffer);

        if (result == null) {
            return null;
        }

        while (result != null) {
            sum = sum.add(result);
            result = parseMediumPair(buffer);
        }

        return sum;
    }
1277947
static int getSignedInt(ByteBuf buf, int offset) {
        return (buf.getByte(offset)     & 0xFF) << 24 |
               (buf.getByte(offset + 1) & 0xFF) << 16 |
               (buf.getByte(offset + 2) & 0xFF) <<  8 |
                buf.getByte(offset + 3) & 0xFF;
    }
105406
function amf3decDate(buf) {  // The UI29 should be 1
    var uTz = amf3decUI29(buf);
    var ts = buf.readDoubleBE(uTz.len);
    return { len: uTz.len + 8, value: ts }
}
732881
def from_buffer(self, buf):
        
        with self.lock:
            try:
                # if we're on python3, convert buf to bytes
                # otherwise this string is passed as wchar*
                # which is not what libmagic expects
                if isinstance(buf, str) and str != bytes:
                    buf = buf.encode('utf-8', errors='replace')
                return maybe_decode(magic_buffer(self.cookie, buf))
            except MagicException as e:
                return self._handle509Bug(e)
602535
private void findMagic() throws BitcoinBlockReadException {
	// search if first byte of any magic matches
	// search up to maximum size of a bitcoin block
	int currentSeek=0;
	while(currentSeek!=this.maxSizeBitcoinBlock) {
		int firstByte=-1;
		try {
			this.bin.mark(4); // magic is always 4 bytes
			firstByte=this.bin.read();
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		if (firstByte==-1) { 
			throw new BitcoinBlockReadException("Error: Did not find defined magic within current stream");
		}
		try {
			if (checkForMagicBytes(firstByte)) {
				return;
			}
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		if (currentSeek==this.maxSizeBitcoinBlock) { 
			throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found within the maximum size of a Bitcoin block. Check data or increase maximum size of Bitcoin block.");
		}
	// increase by one byte if magic not found yet
		try {
			this.bin.reset();
			if (this.bin.skip(1)!=1) {
				LOG.error("Error cannot skip 1 byte in InputStream");
			}
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
	currentSeek++;
	}
}
1156636
function(buf, crc) {

      var c = (typeof(crc) == "undefined" ? 0 : crc) ^ 0xffffffff;
      var bArray  = typeof buf !== "string";
      var n;

      if (bArray) {
        for (n = 0; n < buf.length; n++) {
          c = SAP_CRC32_TABLE[(c ^ buf[n]) & 0xff] ^ (c >>> 8);
        }
      } else {
        for (n = 0; n < buf.length; n++) {
          c = SAP_CRC32_TABLE[(c ^ buf.charCodeAt(n)) & 0xff] ^ (c >>> 8);
        }
      }

      return c ^ 0xffffffff;
    }