Skip to content

Instantly share code, notes, and snippets.

View gitsubmodules_install.sh
#!/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
View is_node.js
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');
};
View spinner.sh
#!/bin/bash
spinner() {
local i sp n
sp='/-\|'
n=${#sp}
printf ' '
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
View isPromise.js
export default (val) => val && typeof val.then === 'function';
View toHex.js
export default (val) => ("0000000" + (val >>> 0).toString(16)).substr(-8);
View hash_fnv32a.js
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;
}
View binary.js
//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--) {
View array.js
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++) {
View disableTextSelection.js
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
laravel city model
View City.php
<?php
namespace App\Models;
class City extends Model {
/**
* The database table used by the model.
* @var string
*/
protected $table = 'cities';
public $timestamps = false;