Skip to content

Instantly share code, notes, and snippets.

View unbracketed's full-sized avatar

Brian Luft unbracketed

View GitHub Profile
@unbracketed
unbracketed / yyyymmdd.js
Last active August 29, 2015 14:06
Javascript date formatter YYYYMMDD
Date.prototype.yyyymmdd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};
d = new Date();
@unbracketed
unbracketed / heroku-copy-config.sh
Created November 26, 2014 18:04
Heroku copy config
#!/bin/bash
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
key=${key%%:}
echo "Setting $key=$value"
@unbracketed
unbracketed / Matches.jsx
Last active August 29, 2015 14:17
Riff on Omniscient-style component
//http://omniscientjs.github.io/playground/02-search/
// content component (pure)
var Match = React.createClass({
render: () => {(
<li>
<a href="{this.props.url}">{this.props.title}</a>
</li>
)}
})
@unbracketed
unbracketed / gist:228472
Created November 7, 2009 01:59
Hook for new virtualenvs
#I like to use something like this as the global mkvirtualenv new environment hook.
#This drops a few libs and tools that I tend to lean heavily on into the new environment.
easy_install pip
pip install ipython
pip install pudb
#Django command shortcuts
alias dj='python manage.py'
alias djr='dj runserver'
alias djrp='dj runserver_plus'
alias djdb='dj dbshell'
alias djs='dj shell'
alias djsp='dj shell_plus'
alias djt='dj test'
alias djm='dj migrate'
alias djsm='dj startmigration'
from BeautifulSoup import BeautifulSoup
from urllib import urlopen
url = "http://www.radioparadise.com/content.php?name=Playlist"
soup = BeautifulSoup(urlopen(url))
playlist_table = soup.findAll('table')[2]
track_rows = playlist_table.findAll('tr', attrs={'class':['shade', 'noshade']})
f = open('radioparadise_playlist.txt', 'w')
@unbracketed
unbracketed / twitter_golden_ratios.py
Created May 29, 2010 06:17
A quick and dirty script that aggregates Twitter account golden ratios using Redis to store data.
import redis
import time
import twitter
twitter = twitter.Twitter()
R = redis.Redis()
while True:
for tweet in twitter.statuses.public_timeline():
@unbracketed
unbracketed / gist:457758
Created June 29, 2010 20:20
Parsing columns out of MySQL table status dump
import re
tables = open('path/to/table_status_dump').readlines()
for table in tables:
mo = re.search(r'^\|\s(?P<table_name>[\w_]+)\s+\|\s(InnoDB|MyISAM)\s?\|\s+\d+\s+\|\s(Compact|Fixed|Dynamic)\s+\|\s+(?P<row_count>\d+)\s+\|(\s+\d+\s+)\|\s+(?P<data_length>\d+)\s+\|(\s+\d+\s+)\|\s+(?P<index_length>\d+)\s+\|', table)
print ','.join((mo.group('table_name'), mo.group('row_count'), mo.group('data_length'), mo.group('index_length'), )
@unbracketed
unbracketed / virtualenv_komodo_project.py
Created July 2, 2010 04:42
Util for generating a Komodo project file that works with virtualenv
"""
A sample utility for customizing virtualenv creation based
on the postmkvirtualenv hook provided by virtualenvwrapper.
This script will generate a Komodo project file suitable for
use in Komodo Edit (and presumably Komodo IDE). The project preferences
are automatically customized so that the Python path contains the
new virtualenv's site-packages directory.
(Project Properties -> Languages -> Python in the GUI)
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.mybash/django_bash_completion.sh
#load Firefox with a development profile
alias ffdev="firefox -no-remote -P dev"
#Commands that can be handy when working in Python environments
#-----------