Skip to content

Instantly share code, notes, and snippets.

Nathan Lucas bnlucas

Block or report user

Report or block bnlucas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View compare.txt
--------------------------------------------------------------------------------
BaseHash vs Hashbrown
testing instantiation and hashing combined
base: 62
length: 171
value: 3154851373153015827738309232812515645550893040441169750950287100081801
7098580981494840912925603132017160147302934098705114421342560722423313
View takeover.py
import time
import webbrowser
import click
from pymouse import PyMouse
from pykeyboard import PyKeyboard
m = PyMouse()
@bnlucas
bnlucas / 0_reuse_code.js
Created Oct 31, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bnlucas
bnlucas / Paginated.py
Last active Oct 17, 2015
Move seamlessly through paginated API results without loading all pages at once. Only loads the pages needed.
View Paginated.py
import math
def mceil(n, m):
'''
returns ceil(n) the multiple m.
example: mceil(21, 10) -> 30.0 which is the next multiple of 10.
:param n: value to ceil.
@bnlucas
bnlucas / imports.py
Created Jun 22, 2015
Find all .py files that import a certain module or just supplied methods of the module. I use http://click.pocoo.org/ for interacting with the command line, but this can be changed.
View imports.py
import os
import re
from subprocess import PIPE, Popen
import click
def which(executable):
for path in os.environ['PATH'].split(os.pathsep):
@bnlucas
bnlucas / which.py
Last active Aug 29, 2015
Implement the Linux `which` command in Python that works in Windows!
View which.py
import os
def which(executable):
for path in os.environ['PATH'].split(os.pathsep):
path = path.strip('"')
fpath = os.path.join(path, executable)
if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
return fpath
View compare.py
'''
def test1(stop=100):
for i in range(stop):
pass
def test2(stop=100):
for i in xrange(stop):
pass
compare = Compare('Testing the use of range and xrange.')
@bnlucas
bnlucas / extended_gcd.py
Created Jun 11, 2015
Extended Euclidean Algorithm extended_gcs(a, b) - With benchmarks.
View extended_gcd.py
'''
Extended Euclidean Algorithm extended_gcd(a, b) methods found online.
'''
from functools import wraps
from time import time
def benchmark(iterations=10000):
def wrapper(function):
@wraps(function)
@bnlucas
bnlucas / float_formating.py
Last active Aug 29, 2015
A better way to print formatted floats using the `format()` specs.
View float_formating.py
def float_spec(fill, align, sign, width, separator, precision):
if len(fill) > 1:
raise ValueError('The fill character can only contain 1 character.')
if align not in ['left', 'right', 'center', 'padded']:
raise ValueError('{} is not an allowed alignment.'.format(align))
if sign not in ['+', '-', ' ']:
raise ValueError('{} is not a valid sign.'.format(sign))
View fourth_clean_primes.py
chain = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
You can’t perform that action at this time.