Skip to content

Instantly share code, notes, and snippets.

View alesmenzel's full-sized avatar
:octocat:

Aleš Menzel alesmenzel

:octocat:
  • Emplifi
  • Prague
View GitHub Profile
@alesmenzel
alesmenzel / how-to-copy-aws-rds-to-local.md
Created August 9, 2017 21:58 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
@alesmenzel
alesmenzel / sha256.js
Created August 21, 2017 18:22 — forked from bryanchow/sha256.js
JavaScript SHA-256 implementation
// Modified by bryanchow for namespace control and higher compressibility
// See https://gist.github.com/1649353 for full revision history from original
/*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
* in FIPS 180-2
* Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for details.
@alesmenzel
alesmenzel / npm_debug.log
Created October 5, 2017 18:59
NPM 5.3.0 -> 5.4.2 update log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'i',
1 verbose cli '-g',
1 verbose cli 'npm' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 2c1a7daf83d23fd8
5 silly install loadCurrentTree
@alesmenzel
alesmenzel / bash-cheatsheet.sh
Created June 9, 2018 16:17 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@alesmenzel
alesmenzel / event-loop.md
Created July 15, 2018 07:46 — forked from jesstelford/event-loop.md
What is the JS Event Loop and Call Stack?

Regular Event Loop

This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)


Given the code

@alesmenzel
alesmenzel / tcpproxy.js
Created July 15, 2018 16:38 — forked from kfox/tcpproxy.js
A basic TCP proxy written in node.js
var net = require("net");
process.on("uncaughtException", function(error) {
console.error(error);
});
if (process.argv.length != 5) {
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
process.exit();
}
@alesmenzel
alesmenzel / README.md
Created August 12, 2018 19:24 — forked from pcan/README.md
Node.js plain TLS Client & Server, 2-way Cert Auth

Node.js TLS plain TLS sockets

This guide shows how to set up a bidirectional client/server authentication for plain TLS sockets.

Prepare certificates

Generate a Certificate Authority:

openssl req -new -x509 -days 9999 -keyout ca-key.pem -out ca-crt.pem
@alesmenzel
alesmenzel / OpenSSL cheat sheet for socket programmers.md
Created August 12, 2018 19:41 — forked from azadkuh/OpenSSL cheat sheet for socket programmers.md
OpenSSL cheat sheet. This is a brief howto for socket programmers.

#OpenSSL cheat sheet This is a brief howto for socket programmers.

create RSA key pairs

ex: 1024bits length key pair:

$> openssl genrsa -out myprivate.pem 1024
$> openssl rsa -in myprivate.pem -pubout -out mypublic.pem
@alesmenzel
alesmenzel / pick-random-element-based-on-probability.js
Last active July 25, 2025 05:22
Select random element from array by probability
const arr = ['A', 'B', 'C'];
// Probability map
const weight = {
A: 0.5,
B: 0.3,
C: 0.2
};
const find = input =>
@alesmenzel
alesmenzel / combinations.js
Last active August 28, 2018 20:40
Combination of k elements from an array
const k_combinations = (arr, k) => {
if (arr.length < k) {
return [];
}
if (arr.length === k) {
return [arr];
}
if (k === 1) {