Skip to content

Instantly share code, notes, and snippets.

@igniteflow
igniteflow / emoji-wall.py
Created May 26, 2016 09:47
Slack emoji wall
"""
print out all the emojis to spam your friends Slack clients
"""
import requests
api_token = 'your-api-token'
text = ' '.join([':{}:'.format(e) for e in requests.get('https://slack.com/api/emoji.list?token={}'.format(token)).json()['emoji'].keys()])
print(text)
@igniteflow
igniteflow / python-coverage-xml-parser.coffee
Created May 19, 2016 07:34
Python Coverage XML file parser in Coffeescript
fs = require 'fs',
xml2js = require 'xml2js'
coverage =
modules: []
filename = 'coverage.xml'
parser = new xml2js.Parser()
fs.readFile __dirname + '/' + filename, (err, data) ->
@igniteflow
igniteflow / gitcommands.sh
Created April 18, 2016 13:56
Useful Git commands
# checkout master from n days ago
git checkout `git rev-list -n 1 --before="7 days ago" master`
@igniteflow
igniteflow / dummy-progress-response.py
Created December 2, 2015 15:09
Django scribble for when you want to simulate a job progress checker
from django.core.cache import cache
# inside get() or your view function
cache_key = 'dummy-csv-export-status'
dummy_data = cache.get(cache_key)
if not dummy_data:
dummy_data = ['ready'] + ['processing' for i in range(9)]
cache.set(cache_key, dummy_data)
@igniteflow
igniteflow / list-target.py
Created October 6, 2015 10:34
List python packages installed in a directory (such as with pip install --target my_dir)
import sys
import pkg_resources
"""
List python packages installed in a directory (such as with pip install --target my_dir)
python list-target.py /path/to/my_dir # can be relative or absolute
"""
try:
target_dir = sys.argv[1]
@igniteflow
igniteflow / orderedlist.css
Created October 1, 2015 14:27
Preserve indent in multi-line ordered list item content
/* from http://stackoverflow.com/a/17514460 */
li {
list-style-type: disc;
list-style-position: inside;
text-indent: -1em;
padding-left: 1em;
}
@igniteflow
igniteflow / gist:922bbe327478368d2342
Created September 3, 2015 11:06
Django: Setting transaction level and autocommit with MySQL
# my.conf
[mysqld]
autocommit = 1
transaction-isolation = READ-COMMITTED
# settings.py
DATABASES = {
...,
'OPTIONS': {
'init_command': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
@igniteflow
igniteflow / atom-django-snippets.cson
Last active August 29, 2015 14:25
Atom Django snippets
'.source.python':
'Django context_data':
'prefix': 'context_data'
'body': 'def get_context_data(self, **kwargs):\n\tcontext_data = super(, self).get_context_data(**kwargs)\nreturn context_data'
@igniteflow
igniteflow / gist:7847cf96dd57d4f7aecc
Last active August 29, 2015 14:24
A class decorator to apply Gargoyle's @Switches decorator to all test cases in a class
import inspect
def decorate_all_tests_in_class(decorator, prefix='test_', **kwargs):
def decorate_the_class(cls):
for name, m in inspect.getmembers(cls, inspect.ismethod):
if name.startswith(prefix):
setattr(cls, name, decorator(**kwargs)(m))
return cls
return decorate_the_class
@igniteflow
igniteflow / mock-django-cache.py
Created July 6, 2015 12:57
Mock Django's cache in unit tests
"""
myapp/mymodule.py:
from django.core.cache import cache
def set_cache():
cache.set('foo', 'bar')
def get_cache():
return cache.get('foo')