Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
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)
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 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 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'])
@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}
View gist:294105
# 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
View gist:410290
google.pacman ||
function () {
var a = true,
e = false,
g = {},
i = [1, 4, 2, 8],
l = {
0: {
axis: 0,
increment: 0
View number_of_rows_per_table.sql
-- 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
View gist:417112
// 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
View gist:452250
REPLACE(SUBSTRING(ci.dir_cliente,
CHARINDEX('->', ci.dir_cliente),
CHARINDEX('->', ci.dir_cliente)), '-> ' ,'')