Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tcg on github.
  • I am tommygeorge (https://keybase.io/tommygeorge) on keybase.
  • I have a public key whose fingerprint is 4EB6 B9FC CF65 5C61 EBEA 8F22 5246 02EA E3D7 FF6B

To claim this, I am signing this object:

@tcg
tcg / guessing_game.py
Created April 25, 2016 15:26
Some Python code to tinker with the ideas presented in the Numberphile episode "How to Win a Guessing Game".
"""
Some Python code to tinker with the ideas presented
in the Numberphile episode "How to Win a Guessing Game".
See: https://www.youtube.com/watch?v=ud_frfkt1t0
"""
import random
import time
@tcg
tcg / get_month_day_range.py
Created January 18, 2016 19:09
Get first and last day of a particular month, in Python, with no requirements outside of Python's standard library. From: https://gist.github.com/waynemoore/1109153#gistcomment-1193720
import datetime
import calendar
def get_month_day_range(date):
"""
For a date 'date' returns the start and end date for the month of 'date'.
Month with 31 days:
>>> date = datetime.date(2011, 7, 27)
>>> get_month_day_range(date)
@tcg
tcg / README.md
Last active October 17, 2021 11:18
Foundation 6 Pagination HTML for WordPress Timber+Twig
@tcg
tcg / gist:63af244d01f1aae1810a
Created October 20, 2015 19:04 — forked from Ry4an/gist:8736298
Detecting referenced unset variables. based on https://excess.org/article/2012/04/paranoid-django-templates/
class ParanoidContextProxy(object):
"""
This is a poor-man's proxy for a context instance.
Make sure template rendering stops immediately on a KeyError.
"""
def __init__(self, context):
self.context = context
def __getitem__(self, key):
@tcg
tcg / .profile
Last active November 19, 2015 07:17
Some current aliases and functions from my .profile/.bashrc/.zshrc, etc
# List Git branches in order of most-recently-updated.
# https://gist.github.com/tcg/381dba155117a2e7a545
alias gitbranchesbydate="git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:iso8601) %09 %(refname) %09 %(authorname)' | sed -e 's-refs/heads/--'"
# Output looks like:
# 2014-06-06 12:58:53 -0500 tcg/donate_language_updates Tommy George
# 2014-06-06 10:28:04 -0500 integration Brad
# 2014-06-05 16:13:30 -0500 super_dev_branch Chris
# List files that SHOULD now be ignored by .gitignore, but might not yet be.
# Use this if you just added your .gitignore file and want to make sure that
# -*- coding: utf-8 -*-
from datetime import datetime
import time
import sublime_plugin
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date` and `time`
/* Solarized Dark
For use with Jekyll and Pygments
http://ethanschoonover.com/solarized
SOLARIZED HEX ROLE
--------- -------- ------------------------------------------
base03 #002b36 background
base01 #586e75 comments / secondary content
@tcg
tcg / pointingpoker-mindreader.css
Created February 19, 2014 20:42
Read minds while using http://pointingpoker.com/ Also includes some bonus tips/material.
/**
* Add this style to the page. It's like you can read minds.
* Ugly, but it works. It's a free example, alright!?
*/
.playerPoints::after {
content: attr(data-point-value);
font-style: italic;
font-weight: bolder;
background-color: #eee;
padding-left: 1em;
@tcg
tcg / eyed3.py
Created May 17, 2013 15:51
Use eyed3 in python to get audio encoding information (bitrate, sample rate, channel mode)
# pip install eyeD3
import eyed3
from eyed3 import mp3
f = mp3.Mp3AudioFile('2-297a587f40fdc0064c44f2e5247d7bf7.mp3')
# Now:
# >>> f.info.sample_freq
# 24000
# >>> f.info.bit_rate