Skip to content

Instantly share code, notes, and snippets.

View gkucmierz's full-sized avatar
💻

Grzegorz Kućmierz gkucmierz

💻
View GitHub Profile
@jiristepan
jiristepan / chickenVsEgg.js
Created October 19, 2018 09:26
Chicken egg problem solved by javascript
let question = ['🥚','🐔']
let answer = question.sort()
console.log(answer[0] + ' was first!')
@gkucmierz
gkucmierz / memoize.js
Created October 4, 2016 22:08
Advanced memoization using references for any number of arguments - codewars
function memoize(func) {
let mem = {};
return (...args) => {
let dest = args.reduce((mem, arg) => {
mem.args = mem.args || [];
mem.mems = mem.mems || [];
let idx = mem.args.indexOf(arg);
let obj;
@Justasic
Justasic / openvpn_gen.py
Created November 8, 2015 06:24
This is a python script to generate client OpenVPN configuration files. This is based mostly on the easyrsa script and is much simpler to understand.
import os
import socket
from OpenSSL import crypto, SSL
# OpenVPN is fairly simple since it works on OpenSSL. The OpenVPN server contains
# a root certificate authority that can sign sub-certificates. The certificates
# have very little or no information on who they belong to besides a filename
# and any required information. Everything else is omitted or blank.
# The client certificate and private key are inserted into the .ovpn file
# which contains some settins as well and the entire thing is then ready for
@JordanDelcros
JordanDelcros / triangle-center.js
Created July 30, 2015 08:48
Find centroid of a triangle with JavaScript
// Very simple way to compute the center (centroid) of a triangle.
// The only things you have to know are the three vectors forming the triangle.
// vector = [x, y, z];
var vectorA = [-1, -3, -2];
var vectorB = [2, 1, 2];
var vectorC = [8, -4, 1];
var centerX = ((vectorA[0] + vectorB[0] + vectorC[0]) / 3);
var centerY = ((vectorA[1] + vectorB[1] + vectorC[1]) / 3);
@LaurentMazare
LaurentMazare / tonelli_shanks.c
Created September 28, 2013 19:33
A simple implementation of the Tonelli-Shanks algorithm to compute a square root in Z/pZ where p is prime. It could probably be made quite faster by using a faster pow_mod function instead of the recursive one and also by trying to avoid some of the modulus calculations.
long pow_mod(long x, long n, long p) {
if (n == 0) return 1;
if (n & 1)
return (pow_mod(x, n-1, p) * x) % p;
x = pow_mod(x, n/2, p);
return (x * x) % p;
}
/* Takes as input an odd prime p and n < p and returns r
* such that r * r = n [mod p]. */
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();