Skip to content

Instantly share code, notes, and snippets.

View MattiasFestin's full-sized avatar

Mattias Festin MattiasFestin

View GitHub Profile
@MattiasFestin
MattiasFestin / hash.es6
Last active August 29, 2015 14:20
JavaScript ES6 non-secure hash function
let hash = (o) => {
return padLeft(uneval(o)
.split('')
.map((c) => c.charCodeAt(0))
.reduce((x,y) => {
let v = ((y<<5)-y)+x;
return modPow(0xBCD1B799D, v && v, 0x7FFFFFFF);
})
.toString(16)
.toUpperCase(),'0',9);
@MattiasFestin
MattiasFestin / uneval.es6
Last active January 7, 2020 13:55
uneval "polyfill"
let uneval = (o, noNativeFns = true) => {
var retVal = '';
if (typeof o === 'object') {
if (Array.isArray(o)) {
retVal = '[' + o.map((el) => uneval(el)).join(',') + ']';
} else if (o instanceof RegExp) {
retVal = o.toString();
} else if (o instanceof Date) {
retVal = `new Date(${o})`;
} else if (o === null) {
@MattiasFestin
MattiasFestin / uuid.es6
Created May 11, 2015 09:12
a small simple uuid function for javascript
let Uuid = () => {
let r = (s) => {
let p = (Math.random().toString(16)+"000000000").substr(2,8);
return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p;
};
return r() + r(1) + r(1) + r();
};
@MattiasFestin
MattiasFestin / spawn-webworker.es6
Created May 11, 2015 09:14
Spawn webworker with function or js code in string
let spawn = (...args) => {
var src = args.map(function (x) {
return typeof x === 'function' ? '((' + x.toString() + ').call(this));' : x;
}).join(';');
return new Worker(
window.URL.createObjectURL(
new Blob([src])
)
);
@MattiasFestin
MattiasFestin / modPow.es6
Last active August 29, 2015 14:20
Power modulo (Requires propper tail calls)
let modPow = (b, e, m, value = 1) => {
b = b % m;
if (e % 2 === 1) {
value = (value * b) % m;
}
return e <= 1 ? value : modPow(b * b, e >> 1, m, value);
};
@MattiasFestin
MattiasFestin / str-pad.es6
Created May 11, 2015 09:18
String padding (Requires propper tail calls)
let padLeft = (value, char, n) => n - value.length > 0 ? padLeft(char + value, char, n-1) : value;
let padRight = (value, char, n) => n - value.length > 0 ? padRight(value + char, char, n-1) : value;
@MattiasFestin
MattiasFestin / weakhashmap.js
Last active September 2, 2015 06:56
WeakHashMap for ext.js
Ext.define('Ext.util.WeakHashMap', {
mixins: {
observable: 'Ext.util.Observable'
},
generation: 0,
/**
* Creates new HashMap.
@MattiasFestin
MattiasFestin / AbstractManager.js
Last active February 11, 2016 07:42
memmory safe AbstractManager
//Dependency: https://gist.github.com/MattiasFestin/e5e92d5ae5e2b4bf89c3
Ext.override('Ext.AbstractManager', {
constructor: function(config) {
Ext.apply(this, config || {});
/**
* @property {Ext.util.HashMap} all
* Contains all of the items currently managed
*/
if (typeof window.WeakMap === 'function') {
@MattiasFestin
MattiasFestin / boombox.ascii
Last active April 4, 2018 16:11
Ascii arts
░░█▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
██▀▀▀██▀▀▀▀▀▀██▀▀▀██
█▒▒▒▒▒█▒▀▀▀▀▒█▒▒▒▒▒█
█▒▒▒▒▒█▒████▒█▒▒▒▒▒█
██▄▄▄██▄▄▄▄▄▄██▄▄▄██
█ ██ ██▀███ ▒█████ ▄████▄ ██ ▄█▀ ▐██▌
██ ▓██▒ ▓██ ▒ ██▒▒██▒ ██▒▒██▀ ▀█ ██▄█▒ ▐██▌
▓██ ▒██░ ▓██ ░▄█ ▒▒██░ ██▒▒▓█ ▄ ▓███▄░ ▐██▌
Add-Type -AssemblyName System.Speech; $ss = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer; $ss.Speak('Do you want some up dog?'); $ss.SelectVoice('Microsoft Zira Desktop') ; $ss.Speak('What is up dog?'); $ss.SelectVoice('Microsoft David Desktop'); $ss.Speak('Nothing much, how about you'); $ss.SelectVoice('Microsoft Zira Desktop') ; $ss.Speak('Fuck you Dave!');