Skip to content

Instantly share code, notes, and snippets.

@lukakostic
lukakostic / CircularDeepCopy.js
Last active May 22, 2024 18:45
JS Circular reference DeepCopy and LinearizedDeepCopy (can be jsoned and back)
/*
DeepCopy and LinearizedDeepCopy which can handle circular references.
LinearizedDeepCopy can be jsonified and back yet keep circular references.
(For use see comments below the functions)
// these dont clone functions or keep class(constructor) info!!!
// so its like JSON.parse(JSON.stringify(obj)) but faster(?) and can do circular references.
*/
@lukakostic
lukakostic / Screencap.py
Last active May 17, 2024 06:30
Python screencap and screenshot gui tool
#!/usr/bin/env python3
"""
uses following cli tools:
slop - let user area select on screen
maim - cli screenshot tool , uses slop
recordMyDesktop - cli tool to screencap videos
zenity - cli tool for dialogs (save as dialog)
#include<cstdio>
#define D fputc(i*8,f) //colors (max = 248=31*8) with 31 iterations
main(){
int h=4000,w=4000,a=w*h,i; //resolution
FILE*f=fopen("img.ppm","wb");
fprintf(f,"P6\n%d %d\n255\n",w,h); //ppm header: P6 w h colorMax
for(;a--;i=31){ //iterations (31) per each pixel (x)
for(double t,x=.0,y=.0;x*x+y*y<4.&&i-->1;) //limit (4=2^2)
t=x*x-y*y+(a%w-w/2.)*.0006-.5, //x zoom (*.0006) & view (-.5)
y=2.*x*y+(a/w-h/2.)*.0006+.0, //y zoom (*.0006) & view (+.0)
/*
Use these commands to render img.ppm:
w & h: 4000 4000
2 -.5 0 .3
1
*/
#include<stdio.h>
#include<stdlib.h>
#include<vector>
This file has been truncated, but you can view the full file.
Benjamin Rennells,/benjamin.rennells,Jessica Hayward,/haywardcal
Benjamin Rennells,/benjamin.rennells,James Martin,/profile.php?id=100011349840834
Benjamin Rennells,/benjamin.rennells,Leslie Darnell,/leslie.darnell.9
Benjamin Rennells,/benjamin.rennells,Kathy Frasca,/intergalactickathy.1
Benjamin Rennells,/benjamin.rennells,Sean Brady,/sean.brady.94
Benjamin Rennells,/benjamin.rennells,Kate Mattes,/kate.mattes.3
Benjamin Rennells,/benjamin.rennells,Deborah Cronin,/profile.php?id=100018394773973
Benjamin Rennells,/benjamin.rennells,Mike Bird,/mike.bird.92351
Benjamin Rennells,/benjamin.rennells,Mike Bird,/mike.bird.12177
Benjamin Rennells,/benjamin.rennells,Denise Sharpe,/MIBESCH
@lukakostic
lukakostic / async sleep.js
Last active October 1, 2018 15:20
await sleep(2000); //2 sec
async function sleep(x) {
return new Promise(resolve => {
setTimeout(() =>{resolve(x);},x);
});
}
@lukakostic
lukakostic / encrypt_decrypt.c
Created October 1, 2018 15:16
Start args: key mode(encrypt/decrypt) input.txt output.txt OR input.txt output.txt (will encrypt and print the random key used)
#include<stdio.h>
#include<stdlib.h> //rand & srand
#include<time.h> //to seed srand
int main(int argc, char * argv[])
{
FILE * file;
long length; //file length
char * text = 0;
@lukakostic
lukakostic / Noise.py
Created August 31, 2018 05:17
Produces a random colored noise image of size
from PIL import Image
import numpy as np
import random
import time
random.seed(time.time())
size = 256 #edit size here
im = Image.new('RGB', (size, size))
#define n double
n l=25; //Change this
#define p(X) putchar("* \n"[X])
#define f(X,Y) for(n X=0;X<l;p(Y)){X++;
n g(n z){return z==1?0:(z==2?1:g(z-1)+2);}void main(){n o=0.5;n h=l*o;f(i,2)n d=i>h?g(l-i+1):g(i);
n s=(l-d)*o;f(j,(j==h+o)?(j<=(s+o)?0:1):(j<=h?(j<(s+o)?0:1):((l+1-j)<(s+o)?0:1)))}}}
/*
Try doing your own to replicate the below output, it took me more than id like to admit ;) (~1-2hrs)
lenght = 25
*************************
************ ************
*********** ***********
********** **********
********* *********
******** ********
******* *******