Skip to content

Instantly share code, notes, and snippets.

Ryan Wilson-Perkin ryanwilsonperkin

Block or report user

Report or block ryanwilsonperkin

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
@ryanwilsonperkin
ryanwilsonperkin / github_repos.py
Last active Jan 9, 2018
Use the GitHub API to generate a CSV or your organization's repositories.
View github_repos.py
#!/usr/local/bin/python
"""
Generate a CSV file of your organization's GitHub repositories.
Results in a CSV file with the following columns:
- name: The name of the repository
- private: True if this is a private repository, else False
- fork: True if this repository is the result of a fork, else False
- created_at: The datetime this repository was created
- updated_at: The datetime this repository was last updated
@ryanwilsonperkin
ryanwilsonperkin / convox_env_check.sh
Created Dec 20, 2017
Check all applications in a convox rack for environment variables (name or value) containing a search_query
View convox_env_check.sh
rack=$1
search_query=$2
if [ -z "$rack" ] || [ -z "$search_query" ]; then
echo "usage: $0 rack search_query"
exit 1
fi
apps=$(convox apps --rack $rack | grep -v STATUS | cut -f1 -d' ')
@ryanwilsonperkin
ryanwilsonperkin / decorators.py
Last active Nov 23, 2017
Different types of decorators
View decorators.py
# Regular decorator
def decorator(f):
def wrapped(*args, **kwargs):
print('Before')
result = f(*args, **kwargs)
print('After')
return result
return wrapped
# Regular decorator usage
@ryanwilsonperkin
ryanwilsonperkin / fast_vagrant_ssh.md
Created May 3, 2017
Faster SSHing into vagrant
View fast_vagrant_ssh.md

Running vagrant ssh can be slow because it boots up a ruby process, does a bunch of analysis to determine your ssh parameters, and then actually invokes the command. If you want a faster login, try the following:

# Compute the ssh parameters, append them to your global ssh config file
# The --host parameter specifies what you want the vagrant machine to be called
vagrant ssh-config --host vagrant >> ~/.ssh/config

# Now just ssh into that machine directly
ssh vagrant
@ryanwilsonperkin
ryanwilsonperkin / webpack.config.js
Created Feb 23, 2017
Webpack: chunkhash in production, hash in development
View webpack.config.js
const PRODUCTION = process.env.NODE_ENV === 'production';
const HASH_MODE = PRODUCTION ? 'chunkhash' : 'hash';
module.exports = {
output: {
filename: `[name].[${HASH_MODE}].js`,
chunkFilename: `[name].[${HASH_MODE}].js`,
},
...
};
View profiling.md

Profiling!

A simple way to get line profiling on your python functions.

  1. pip install line_profiler
  2. Decorate your function with @profile (no import needed)
  3. Launch a shell with kernprof -l manage.py shell
  4. Call the function you want to profile. Preferably several times! (%timeit is great for running it several times)
  5. Exit the shell. You'll see a dumped file created called manage.py.lprof
View contextmanagers.py
# Having fun with context managers
from contextlib import contextmanager
@contextmanager
def deity():
print 'The Father'
yield
print 'The Holy Ghost'
god = deity()
View keybase.md

Keybase proof

I hereby claim:

  • I am ryanwilsonperkin on github.
  • I am ryanwilsonperkin (https://keybase.io/ryanwilsonperkin) on keybase.
  • I have a public key whose fingerprint is 5664 AF96 D17B 16E8 F21B F431 FBA8 1CE4 75C6 7F0D

To claim this, I am signing this object:

View comprehension.js
// Clever
function comprehension(arr, fn) {
return arr.reduce((obj, key) => Object.assign(obj, {[key]: fn(key)}), {});
}
// Legible
function comprehension(arr, fn) {
const obj = {};
for (key of arr) {
obj[key] = fn(key);
View shitty_python.py
import random
class ShittyList(list):
def __len__(self):
min, max = 0, super(ShittyList, self).__len__()
return random.randrange(min, max)
You can’t perform that action at this time.