Skip to content

Instantly share code, notes, and snippets.

View bnlucas's full-sized avatar

Nathan Lucas bnlucas

View GitHub Profile
package com.bnlucas.app.config;
import com.codahale.metrics.MetricRegistry;
import com.bnlucas.components.ldap.LdapClient;
import com.bnlucas.app.config.liquibase.AsyncSpringLiquibase;
import com.bnlucas.app.domain.AppAuditorAware;
import com.bnlucas.springbootextras.config.Constants;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import com.zaxxer.hikari.HikariDataSource;
import liquibase.integration.spring.SpringLiquibase;
--------------------------------------------------------------------------------
BaseHash vs Hashbrown
testing instantiation and hashing combined
base: 62
length: 171
value: 3154851373153015827738309232812515645550893040441169750950287100081801
7098580981494840912925603132017160147302934098705114421342560722423313
import time
import webbrowser
import click
from pymouse import PyMouse
from pykeyboard import PyKeyboard
m = PyMouse()
@bnlucas
bnlucas / 0_reuse_code.js
Created October 31, 2015 21:11
Here are some things you can do with Gists in GistBox.
// 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 October 17, 2015 22:54
Move seamlessly through paginated API results without loading all pages at once. Only loads the pages needed.
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 June 22, 2015 06:04
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.
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 August 29, 2015 14:23
Implement the Linux `which` command in Python that works in Windows!
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
'''
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 June 11, 2015 07:04
Extended Euclidean Algorithm extended_gcs(a, b) - With benchmarks.
'''
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 August 29, 2015 14:22
A better way to print formatted floats using the `format()` specs.
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))