Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jackmaney
jackmaney / gist:cfb535f161b30b325fdebfbb3170a426
Created March 22, 2018 21:39
Scala's sexy, sexy implicits...
implicit class Factorial(val n: Int) extends AnyVal{
def `!`: BigInt = n match {
case _ if n < 0 => throw new IllegalArgumentException()
case 0 => 1L
case _ => (1 to n).foldLeft(1L)(_*_)
}
}
defined class Factorial
@ 5!
@jackmaney
jackmaney / pypi_homepage.sh
Last active August 27, 2015 06:02
A simple function to open the homepage of any project on PyPI (with a listed homepage)
# Retrieves the home page of a project in PyPI, and opens that homepage in your default browser.
# This makes use of the PyPI JSON API: https://wiki.python.org/moin/PyPIJSON
function pypi_homepage() { curl -sL http://pypi.python.org/pypi/$1/json | \
python -c "from __future__ import print_function;import json;import fileinput;\
blob=json.loads(' '.join([x for x in fileinput.input()]));print(blob['info']['home_page'])"| xargs open ;}
@jackmaney
jackmaney / click_command_delegation.py
Last active August 29, 2015 14:27
Delegating Commands in Click
import click
@click.group()
def main():
"""Do things."""
def delegate_command(group, command_name, function, args=None, kwargs=None):
"""
Takes a function that has been decorated with ``click.group`` and delegates a command to it
"""
@jackmaney
jackmaney / pyenv_virtualenv_ps1.sh
Created August 11, 2015 14:52
pyenv virtualenv in PS1
export VIRTUAL_ENV_DISABLE_PROMPT=1
pyenv_python_version(){
result=""
if pyenv 2>/dev/null; then
pyenv_version="$(pyenv version-name)";
if [ -n "$pyenv_version" ]; then
result="$pyenv_version";
fi
fi
@jackmaney
jackmaney / gist:4c5360255d5f43391567
Created August 6, 2015 20:22
MacDown crash log
Process: MacDown [17345]
Path: /Applications/MacDown.app/Contents/MacOS/MacDown
Identifier: com.uranusjr.macdown
Version: 0.4.5.1 (647)
Code Type: X86-64 (Native)
Parent Process: launchd [445]
Responsible: MacDown [17345]
User ID: 502
Date/Time: 2015-08-06 15:22:12.317 -0500
pyenv_python_version(){
result=""
pyenv_version="$(pyenv version-name)";
if [ -n "$pyenv_version" ]; then
result="$pyenv_version";
fi
[[ -n "$result" ]] && echo "($result) "
}
export PS1="\$(pyenv_python_version)\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[33;1m\]\w\[\033[m\]$ "
@jackmaney
jackmaney / macbeth.py
Created March 9, 2015 13:24
r/dailyprogrammer challenge #204 [Easy]
# Daily Programming Challenge:
# http://www.reddit.com/r/dailyprogrammer/comments/2xoxum/20150302_challenge_204_easy_remembering_your_lines/
import requests
import re
import sys
macbeth = requests.get(
"https://gist.githubusercontent.com/Quackmatic/f8deb2b64dd07ea0985d/raw/macbeth.txt").text
# act_number: {scene: {description: (desc_of_scene), dialogues: [{speaker:
# S, text: T}]}}
@jackmaney
jackmaney / parse_manifest.py
Last active August 29, 2015 14:15
Using distutils to parse MANIFEST.in and grab files against the manifest
# Adapted from https://github.com/python/cpython/blob/2.7/Lib/distutils/command/sdist.py#L386
from distutils.text_file import TextFile
from distutils.filelist import FileList
template = TextFile("MANIFEST.in", strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1)
filelist = FileList()
try:
while True:
@jackmaney
jackmaney / gist:4a98cfdfef61e1d5a097
Last active August 29, 2015 14:13
A queue for geocoding addresses with geopy that respects a per-second rate limit
from time import time
class RateLimitedGeocodingQueue(object):
def __init__(self, geocoder, addresses, per_sec_rate_limit=5):
self.geocoder = geocoder
self.addresses = [x for x in addresses] # Cloning list of addresses so we can pop with impunity
self.per_sec_rate_limit = per_sec_rate_limit
2014-12-30 18:36:20 -0600
./configure
--disable-dependency-tracking
--prefix=/usr/local/Cellar/harfbuzz/0.9.37
--with-icu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d