Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
View sleep.js
const sleep = async (n) => await (new Promise(r => setTimeout(r, n)));
export default sleep;
View upsert.js
const tableFactory = () => {
const columns = [];
const compositeUniqueColumns = [];
const dataTypes = [
'uuid',
'string',
'timestamp',
'float',
'integer',
View install-virtualbox.sh
# posix
sudo echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" > /etc/apt/sources.list.d/virtualbox.list
# fish
# sudo echo "deb http://download.virtualbox.org/virtualbox/debian (lsb_release -cs) contrib" > /etc/apt/sources.list.d/virtualbox.list
sudo apt-get update
sudo apt-get install virtualbox-5.0 -y
View hgrep.sh
hgrep() {
history | grep -v grep | grep $1 | awk '{f=$1;$1="";print $0}' | awk '{$1=$1}1' | sort | uniq
}
@snahor
snahor / gist:36da9cbc701b758fd998
Last active Aug 29, 2015
Useful commands I always forget
View gist:36da9cbc701b758fd998
# clear text file
cat /dev/null > {path to file}
cp /dev/null {path to file}
> {path to file} # works if you're not using fish
# clipboard to file
xsel -o > {path to file}
@snahor
snahor / topological_sort.py
Created Feb 24, 2015
Topological ordering
View topological_sort.py
def topological_sort(graph):
"""
:param graph: an adjacency list representing an acyclic digraph
:type graph: dict
:return: a list of vertices in order of decreasing finish times
:rtype: list
>>> G = {'w': ['t'], 's': ['v', 'w'], 'v': ['t'], 't': []}
>>> order = topological_sort(G)
>>> order in (['s', 'w', 'v', 't'], ['s', 'v', 'w', 't'])
View readme.md

Given an array of positive integers, write a function which returns all the unique pairs which add (equal) up to 100.

Example data:

sample_data = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51]
sample_output = [[1,99], [0,100], [10,90], [51,49], [50,50]]
View better_pascal.py
def better_pascal(n):
def row(n):
row = [1]
for i in range(n):
row.append(row[i] * (n - i) // (i + 1))
return row
return [row(i) for i in range(n)]
View gist:9223205
import hashlib
import base64
import hmac
import time
def _decrypt_cookie(name, value, cookie_secret, include_name=True):
def _cookie_signature(*parts):
hash = hmac.new(cookie_secret,
digestmod=hashlib.sha1)
@snahor
snahor / freetds.conf
Last active Jan 2, 2016
SQLA + pyodbc
View freetds.conf
[db_name]
host = 1.1.1.1
port = 1433
tds version = 8.0
client charset = UTF-8