Skip to content

Instantly share code, notes, and snippets.

View snahor's full-sized avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
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)
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)]
@snahor
snahor / readme.md
Last active August 29, 2015 14:15 — forked from ukd1/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]]
@snahor
snahor / topological_sort.py
Created February 24, 2015 21:48
Topological ordering
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'])
@snahor
snahor / gist:36da9cbc701b758fd998
Last active August 29, 2015 14:17
Useful commands I always forget
# 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}
# Including logging
log_file = who_args.pop('log_file', None)
if log_file is not None:
if log_file.lower() == 'stdout':
log_stream = sys.stdout
elif log_file.lower() == 'stderr':
log_stream = sys.stderr
else:
log_stream = open(log_file, 'wb')
who_args['log_stream'] = log_stream
@snahor
snahor / gist:410290
Created May 22, 2010 19:19
google pacman
google.pacman ||
function () {
var a = true,
e = false,
g = {},
i = [1, 4, 2, 8],
l = {
0: {
axis: 0,
increment: 0
-- SQL Server
SELECT [Tables] = so.name,
[Rows] = MAX(si.rows)
FROM sysobjects so,
sysindexes si
WHERE so.xtype = 'U'
AND si.id = OBJECT_ID(so.name)
GROUP BY so.name
ORDER BY 2 DESC
// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft
.Jet.OLEDB.4.0;Data Source=Book1.xls;Extended
Properties=""Excel 8.0;HDR=YES;""";
// Create Connection to Excel Workbook
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
REPLACE(SUBSTRING(ci.dir_cliente,
CHARINDEX('->', ci.dir_cliente),
CHARINDEX('->', ci.dir_cliente)), '-> ' ,'')