Skip to content

Instantly share code, notes, and snippets.

View zekrom-vale's full-sized avatar
🐲
Dragon

Shawn zekrom-vale

🐲
Dragon
View GitHub Profile
@zekrom-vale
zekrom-vale / length
Last active June 1, 2017 14:07 — forked from olvado/getAverageColourAsRGB.js
Get the average colour of an image in javascript using getImageData in CANVAS
function getAvColor (img) {
var canvas = document.createElement('canvas'),
context = canvas.getContext && canvas.getContext('2d'),
rgb,
pixelInterval = 5, // Rather than inspect every single pixel in the image inspect every 5th pixel
count = 0,
data, length,
i = -4;
// return the base colour for non-compliant browsers
@zekrom-vale
zekrom-vale / binarySearch.js
Last active March 9, 2018 13:28
Find if the value exists in a sorted array or return the index.
function binarySearch(l,v){
var m=0,M=l.length,g;
while(m<=M){
//bitwisecmd.com/#0xffffffff%3E%3E%3E1
if(M<=0xF0000000){
while(m<=M){
g=(M+m)>>>1;
if(l[g]===v)return g;
if (l[g]<v)m=g+1;
else M=g-1;
@zekrom-vale
zekrom-vale / isPrime1K.js
Last active March 9, 2018 13:33
Check if a number under 1K is prime
function isPrime1K(v){
v=Math.abs(v);
if(v==1 || v/2==Math.floor(v/2))return false;
if(v>997)return undefined;
return binaryExists(
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997],
v);
}
function binaryExists(l,v){
@zekrom-vale
zekrom-vale / binarySort.js
Created March 11, 2018 03:07
Sort an array using binarySearch and insertionSorting to maintain efficiency.
function binarySort(l){
for(var i in l){
var m=0,M=i-1,g;
main:
while(m<=M){
if(M<=0xF0000000){
while(m<=M){
g=(M+m)>>>1;
if(l[g]===l[i])break main;
if(l[g]<l[i])m=g+1;
[
[{
"op":"test",
"path":"/speciesOrdering/0",
"value":"penguin"
},{
"op":"remove",
"path":"/speciesOrdering/0"
}],
[{
@zekrom-vale
zekrom-vale / objectFlatten.js
Last active May 28, 2018 13:55
Flatten an object or get the deep keys of one
function getDeepKeys(obj,key,d="/"){
if(typeof(obj)!=="object")return null;
var arr=[];
for(let i in obj){
if(typeof(obj[i])==="object")arr=arr.concat(getDeepKeys(obj[i],key?key+d+i:i));
else arr.push(key?key+d+i:i);
}
return arr;
}
@zekrom-vale
zekrom-vale / ebay.css
Last active November 28, 2018 18:51
Trying to create an external CSS sheet for eBay, unfortunately eBay blocks all external references or complains about it.
c{text-align:center}
div,pre{font-size:18px}
*{font-family:Arial,Helvetica,sans-serif}
button{background:cyan;border-color:#9ff;border-radius:5px;cursor:pointer;margin:0 2px}
button:hover{background:#9ff;border-color:cyan;border-radius:5px}
nav a{font-size:26px;text-decoration:none}h1,h2{margin:0 2px}
#p1,#p2{fill:cyan;stroke:#9ff;stroke-width:5}p{margin-top:0}
.s1{width:1000;height:50}.s2{width:500;height:25}
.s1 text{font-size:36px}
.s2 text{font-size:28px}
@zekrom-vale
zekrom-vale / PowerPoint.RunPrograms.reg
Created September 18, 2018 17:33
Allows PowerPoint to run programs (Warning will appear the first time)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\Security]
"RunPrograms"=dword:00000001
@zekrom-vale
zekrom-vale / Fibonacci.js
Created July 22, 2019 02:47
Fibonacci sequence using generators in js
function* F(){
yield 1;
yield 1;
var N=[1,1];
while(true){
let sum=N[0]+N[1];
N=[N[1], sum];
yield sum;
}
}
console.time("test");
Promise.all([
new Promise(r=>chrome.storage.sync.get(null, s=>r(s))),
new Promise(r=>chrome.storage.local.get(null, l=>r(l)))
]).then(x=>console.timeEnd("test"));
console.time("test2");
chrome.storage.sync.get(s=>{
chrome.storage.local.get(l=>console.timeEnd("test2"));
});