Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $path
done
export default (o) => {
if (typeof o == 'undefined' || o === null) return false;
return (typeof Node == 'object' ? o instanceof Node : o && typeof o == 'object' && typeof o.nodeType == 'number' && typeof o.nodeName == 'string');
};
#!/bin/bash
spinner() {
local i sp n
sp='/-\|'
n=${#sp}
printf ' '
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
export default (val) => val && typeof val.then === 'function';
export default (val) => ("0000000" + (val >>> 0).toString(16)).substr(-8);
const FNV_OFFSET_32 = 0x811c9dc5;
export const hash_fnv32a (input) => {
let hval = FNV_OFFSET_32;
// Strips unicode bits, only the lower 8 bits of the values are used
for (var i = 0; i < input.length; i++) {
hval = hval ^ (input.charCodeAt(i) & 0xFF);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
}
//Hamming weight
export const getBitCount32 = (n) => {
n = n - ((n >> 1) & 0x55555555);
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
export const getBitCount = (n) => {
let str = n.toString(2), count = 0;
for (let i = str.length - 1; i >= 0; i--) {
@di3
di3 / array.js
Last active April 10, 2019 03:48
export const shuffle = (array) => {
for (let i = array.length - 1; i > 0; i--) {
let rand = Math.floor(Math.random() * (i + 1));
[array[i], array[rand]] = [array[rand], array[i]]
}
}
export const filter = (arr, cb) => {
var r = [];
for (let i = 0, c = arr.length; i < c; i++) {
export default {
WebkitTouchCallout: "none",
MozUserSelect: "none",
WebkitUserSelect: "none",
KhtmlUserSelect: "none",
msUserSelect: "none",
OUserSelect: "none",
userSelect: "none"
}
@di3
di3 / City.php
Last active May 17, 2019 13:45
laravel city model
<?php
namespace App\Models;
class City extends Model {
/**
* The database table used by the model.
* @var string
*/
protected $table = 'cities';
public $timestamps = false;