Skip to content

Instantly share code, notes, and snippets.

View leomastoras's full-sized avatar
🏠
Working from home

Leo leomastoras

🏠
Working from home
View GitHub Profile
const keySequence = ['l','o','l'];
let userInput = new Array( keySequence.length );
window.addEventListener( 'keydown', ( { key } ) => {
userInput = [ ...userInput.slice( 1 ), key ];
if ( keySequence.every( ( v, k ) => v === userInput[ k ] ) ) {
alert( 'Yatta!' );
@leomastoras
leomastoras / smith.c
Created April 14, 2024 09:31
Single (ONE) statement to generate 100k random smith numbers
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COMPUTATIONS 100000
int c,G,o,d,S,k,i,L,l;
int main(int n,char **v){for(!(n=v?0:n)?srand(c=time(NULL)),printf("Current time is %d\n\n",c),k=L=0:n<0||(S=0);i!=COMPUTATIONS?1:(printf("\nFound %.2f%% Smith numbers\n",(double)L*100/COMPUTATIONS),0);!n?d=2,G=4,main(o=l=((rand()%32768)+1)*((rand()%32768)+1)+1,NULL)?printf("%10d is a Smithnumber\n",l,L++):0,i++:(n<0||!(n%d)?k=d,main(-1,NULL),n/=d:(d+=d<5?d-1:(G=6-G))))if(!n?0:(d*d>n))return n<0?!k||(!(n+1)?S-=k%10:(S+=k%10),k/=10,main(n,NULL)):(S&&n-1?k=n,main(-1,NULL),k=o,main(-1337,NULL),!S:0);}
@leomastoras
leomastoras / 42.bf
Created April 14, 2024 09:33
42 Brainfuck
+++++[>++[>+>+ ++>++++>++++>++++>++++++
>++++++>+++++++ ++>+++++++++<<<<<<<<<-]>>
>+>+>+> >>>+[<]< -]>> >++>-->>+>>++>+
>--<<<< <<<..... .> ....<......
...>... <<.>.... >.>>>>>.<.
<<<<.. ..<.... >..>>>>>.<
.<<<<. >>>.<<. >>>>>.<.<
<<<<< <.>...> >>>.>>>.
<<<.< <<<..>> .>>>>>.<
<.<<< <<...>> >>>.<<<
@leomastoras
leomastoras / trollsort.c
Created April 14, 2024 09:36
trollsort - sorts an array of n integers - (the troll way) Kappa Keepo
/*
* trollsort - sorts an array of n integers - (the troll way) Kappa Keepo
* ----------------------------------------------------------------------
* just some code i wrote for fun. i think complexity should be same with
* bubblesort O(n^2) altho im not sure. feel free to explore it yourself.
* obviously its easy to break it but runs ok for most cases.
* qs O(nlogn) coming soon...
* qs is now ready
* ----------------------------------------------------------------------
* WARNING!!! the is a million undefined behavior things in this code plz
@leomastoras
leomastoras / date.extensions.js
Created April 14, 2024 09:39
Extends Date Object adding fancier collections
Object.assign(Date, {
emojiclocks: [11,...Array(23).keys()].map(c=>String.fromCodePoint(128336+c%12))
}, {
dayperiods: ` ${['',...
'evening afternoon morning night'
.split(/ /)].copyWithin(0,4).join(' ')} `
.replace(/\w+ /g, (w, i) => w.repeat(i / 7 + 3))
.match(/\w+/g)
.reverse()
.slice(1)
copy.sh/brainfuck
this | bf | bf | bf
++[------>+<]>..++[->++<]>+.-[-->+<]>......---[-->+++<]>-.+[--->++<]>+.+[----->+<]>.++[-->+++<]>.[--->++<]>.[->+++++++++<]>.---..++[->++<]>+.-[-->+<]>.---[-->+++<]>-.+[--->++<]>+..+[----->+<]>.++[-->+++<]>.[--->++<]>.+[--->++<]>+.+++.-.[->++<]>+.-[-->+<]>..---[-->+++<]>-.+[--->++<]>+.+[----->+<]>.++[-->+++<]>.[--->++<]>.[->+++++++++<]>.......-...[->++<]>+.-[-->+<]>..---[-->+++<]>-.+[--->++<]>+...+[----->+<]>.++[-->+++<]>.[--->++<]>.--[---->+++<]>.+.---.++[->++<]>+.-[-->+<]>...---[-->+++<]>-.+[--->++<]>+..+[----->+<]>.++[-->+++<]>.[--->++<]>.+[--->++<]>+.+++..---.++[->++<]>+.-[-->+<]>.....---[-->+++<]>-.+[--->++<]>+.+[----->+<]>.++[-->+++<]>.[--->++<]>.[->+++++++++<]>.---..++[->++<]>+.-[-->+<]>..---[-->+++<]>-.+[--->++<]>+...+[----->+<]>.++[-->+++<]>.[--->++<]>.[->+++++++++<]>.[->++<]>-.-[-->+<]>...---[-->+++<]>-.+[--->++<]>+..+[----->+<]>.++[-->+++<]>.[--->++<]>.[->+++++++++<]>.-..[->++<]>+.-[-->+<]>....---[-->+++<]>-.+[--->++<]>+...+[----->+<]>.++[-->+++<]>.[--->++<]
@leomastoras
leomastoras / bf.c
Created April 14, 2024 09:46
shortest (140 bytes) BF interpreter with whitespace
// shortest BF interpreter with whitespace:
s[999], *r=s, *d, c;
main(a, b)
{
char *v=1[d=b];
for(;c = *v++ % 93;)
for(b = c%7 ?
a &&
@leomastoras
leomastoras / bf.js
Last active April 14, 2024 10:11
Brainfuck interpretter written in Javascript
// fmb = F**K My Brain
// ins = instructions string
// oup = terminal output callback function
// inp = terminal input callback function
function fmb(ins, oup, inp) {
var m = [], dp = 0, ip = 0,
il = ins.length, scp = {},
op, mdp;
for(; ip < il; ip++) {
@leomastoras
leomastoras / deckofcards.js
Last active April 20, 2024 18:31
Deck of cards
Array.prototype.hasOwnProperty('shuffle') || Object.defineProperty(Array.prototype, 'shuffle', {
value: function() { return this.sort(() => Math.random() - .5); }
});
let deck = [...'♠♣♥♦'].flatMap(s => ('A,'+[...Array(11).keys()].slice(2)+',J,Q,K').split(/,/).map(c => c + s));
console.log(deck);
console.log(deck.shuffle());
@leomastoras
leomastoras / beautyquicksort.c
Created April 14, 2024 09:58
Beauty Quicksort
void quicksort(int l, int u) {
int i, m;
if (l >= u) return;
m = l;
for (i = l+1; i <= u; i++)
if (x[i] < x[l])
swap(++m, i);
swap(l, m);
quicksort(l, m-1);
quicksort(m+1, u);