Skip to content

Instantly share code, notes, and snippets.

View fabiospampinato's full-sized avatar

Fabio Spampinato fabiospampinato

View GitHub Profile
@fabiospampinato
fabiospampinato / hash-ish.js
Created December 21, 2022 15:04
A little toy hash function that maybe works somewhat
/* IMPORT */
const crypto = require ( 'crypto' );
/* MAIN */
// const hash = str => {
// const PRIMEn = 115792089237316195423570985008687907853269984665640564039457584007913129639349n; // 2**256-587 - https://primes.utm.edu/lists/2small/200bit.html
// const SEEDn = 340282366920938463463374607431768211099n; // 2**128-357 - https://primes.utm.edu/lists/2small/100bit.html
@fabiospampinato
fabiospampinato / huff.js
Created December 21, 2022 14:39
Barebones in-memory huffman coding implementation
/* INPUT */
const input = 'bcaadddccacacac';
if ( input.length < 2 ) throw new Error ( 'Unimplemented' );
/* FREQUENCIES */
const frequenciesMap = {};
@fabiospampinato
fabiospampinato / xor.js
Created December 1, 2022 00:53
A 99% precise neural network that learned the XOR function. There's about a 1kb fixed overhead, the model is ~just those two hex strings.
function xor(t){const _=xor;return _._||(_._=!0,_.p=(e,t)=>{const r=[];for(let n=0,c=e.length;n<c;n++){r[n]=[];for(let c=0,a=t[0].length;c<a;c++){let a=0;for(let r=0,l=e[0].length;r<l;r++)a+=e[n][r]*t[r][c];r[n][c]=a}}return r},_.m=(e,t)=>{const r=new Array(e.length);for(let n=0,c=e.length;n<c;n++){r[n]=new Array(e[n].length);for(let c=0,a=e[n].length;c<a;c++)r[n][c]=t(e[n][c],n,c)}return r},_.d=(e,t)=>{const r="float64"===t?Float64Array:Float32Array;return e.split("|").map((e=>{const t=e.length/2,n=r.BYTES_PER_ELEMENT,c=new ArrayBuffer(t+(t%n?n-t%n:0)),a=new Uint8Array(c),l=new r(c);for(let t=0,r=e.length;t<r;t+=2)a[t/2]=parseInt(e.slice(t,t+2),16);return Array.from(l).slice(0,t)}))},_.a0=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.a1=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.w0=_.d("cf70bbc08a93cfc043c6bb40c6ee8240|de3eb8c06b4a4e4080843bc0480001c1"),_.w1=_.d("c98b9fc1|eb82af40|dd0cbac0|e8d02d41")),_.m(_.p(_.m(_.p([t],_.w0),_.a0),_.w1),_.a1)[0][0]}
console.log(xor([0,0]));
consol
@fabiospampinato
fabiospampinato / tree.txt
Created October 29, 2022 11:52
electron-forge's dependencies tree
[email protected] /Users/fabio/Desktop/asd
└─┬ [email protected]
├─┬ @octokit/[email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected] deduped
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected] deduped
│ │ └─┬ [email protected]
@fabiospampinato
fabiospampinato / bf.js
Created October 12, 2022 19:00
JavaScript Brainfuck interpreter
const program = `[ This program prints "Hello World!" and a newline to the screen, its
length is 106 active command characters. [It is not the shortest.]
This loop is an "initial comment loop", a simple way of adding a comment
to a BF program such that you don't have to worry about any command
characters. Any ".", ",", "+", "-", "<" and ">" characters are simply
ignored, the "[" and "]" characters just have to be balanced. This
loop and the commands it contains are ignored because the current cell
defaults to a value of 0; the 0 value causes this loop to be skipped.
]
@fabiospampinato
fabiospampinato / valid_one_letter_identifiers.txt
Created September 5, 2022 18:42
valid_one_letter_identifiers.txt
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼʽʾʿˀˁˆˇˈˉˊˋˌˍˎˏːˑˠˡˢˣˤˬˮͰͱͲͳʹͶͷͺͻͼͽͿΆΈΉΊΌΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϏϐϑϒϓϔϕϖϗϘϙϚϛϜϝϞϟϠϡϢϣϤϥϦϧϨϩϪϫϬϭϮϯϰϱϲϳϴϵϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѠѡѢѣѤѥѦѧѨѩѪѫѬѭѮѯѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿҀҁҊҋҌҍҎҏҐґҒғҔҕҖҗҘҙҚқҜҝҞҟҠҡҢңҤҥҦҧҨҩҪҫҬҭҮүҰұҲҳҴҵҶҷҸҹҺһҼҽҾҿӀӁӂӃӄӅӆӇӈӉӊӋӌӍӎӏӐӑӒӓӔӕӖӗӘәӚӛӜӝӞӟӠӡӢӣӤӥӦӧӨөӪӫӬӭӮӯӰӱӲӳӴӵӶӷӸӹӺӻӼӽӾӿԀԁԂԃԄԅԆԇԈԉԊԋԌԍԎԏԐԑԒԓԔԕԖԗԘԙԚԛԜԝԞԟԠԡԢԣԤԥԦԧԨԩԪԫԬԭԮԯԱԲԳԴԵԶԷԸԹԺԻԼԽ
@fabiospampinato
fabiospampinato / emoji_skin_tone.ts
Last active August 9, 2022 17:39
Little ugly function for setting the skin tone on an emoji
/* HELPERS */
const SKIN_TONE = {
DARK: '\uD83C\uDFFF',
MEDIUM_DARK: '\uD83C\uDFFE',
MEDIUM: '\uD83C\uDFFD',
MEDIUM_LIGHT: '\uD83C\uDFFC',
LIGHT: '\uD83C\uDFFB',
NEUTRAL: ''
@fabiospampinato
fabiospampinato / eors.js
Created June 23, 2022 19:25
English or Spanish classifier
var l=["eng","spa"],G=l,f=Object.fromEntries(l.map((e,s)=>[e,s]));var b={output:e=>e.map((N,o)=>({language:G[o],probability:N})).sort((N,o)=>o.probability-N.probability)},H=b;var S={getHashes:(e,s)=>[(e.charCodeAt(0)&255)/255,s]},x=S;var _={getFrequencies:(e,s,a=1/0)=>{let N=_.getTable(e,s),o=Object.entries(N),r=o.reduce((E,A)=>E+A[1],0);return o.slice(0,a).map(([E,A])=>[E,A/r]).sort((E,A)=>A[1]-E[1])},getHashes:(e,s,a=1/0)=>_.getFrequencies(e,s,a).flatMap(([r,c])=>x.getHashes(r,c)),getTable:(e,s)=>{let a=/\d/g,N=/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g,r=e.toLowerCase().replace(a,"").replace(N,"").split(/\s+/g),c={};for(let T=0,E=r.length;T<E;T++){let A=r[T];for(let g=0,D=A.length-s;g<=D;g++){let h=A.slice(g,g+s),O=(c[h]||0)+1;c[h]=O}}return c}},m=_;var U={input:e=>{let s=m.getHashes(e,1,40),a=m.getHashes(e,2,20),N=m.getHashes(e,3,10),o=new Array(40+20+10).fill(0);return s.forEach((r,c)=>{o[c]=r}),a.forEach((r,c)=>{o[c+40]=r}),N.forEach((r,c)=>{o[c+40+20]=r}),o},output:e=>{let s=n
@fabiospampinato
fabiospampinato / xor.js
Created June 22, 2022 16:12
A little NN trained to learn XOR
function XOR(d){const a={0:1,1:1,7:.05,2:2,3:-2.8,4:-.09,5:2,6:-4.8,8:.04,26:5.7,14:.9,9:10,10:4.5,11:3.3,12:6.8,13:-5.6,15:.01,27:-7.9,21:.9,16:3.8,17:6.4,18:-1.1,19:5,20:2.5,22:0,28:4.7,29:.08,23:2.2,24:-2.3,25:.5,30:.08};a[0]=d[0],a[1]=d[1],a[2]=a[3],a[3]=a[4],a[3]+=a[0]*a[5],a[3]+=a[1]*a[6],a[7]=1/(1+Math.exp(-a[3])),a[8]=a[7]*(1-a[7]),a[9]=a[10],a[10]=a[11],a[10]+=a[0]*a[12],a[10]+=a[1]*a[13],a[14]=1/(1+Math.exp(-a[10])),a[15]=a[14]*(1-a[14]),a[16]=a[17],a[17]=a[18],a[17]+=a[0]*a[19],a[17]+=a[1]*a[20],a[21]=1/(1+Math.exp(-a[17])),a[22]=a[21]*(1-a[21]),a[23]=a[24],a[24]=a[25],a[24]+=a[7]*a[26],a[24]+=a[14]*a[27],a[24]+=a[21]*a[28],a[29]=1/(1+Math.exp(-a[24])),a[30]=a[29]*(1-a[29]);var b=[];return b[0]=a[29],b}
console.log ( XOR ([ 0, 0 ]) );
console.log ( XOR ([ 0, 1 ]) );
console.log ( XOR ([ 1, 0 ]) );
console.log ( XOR ([ 1, 1 ]) );
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};