Skip to content

Instantly share code, notes, and snippets.

View reidransom's full-sized avatar

Reid Ransom reidransom

View GitHub Profile
@reidransom
reidransom / gist:75927abacecabde58903
Created May 29, 2015 15:48
Normalize any object for json serialization
class NormalizeData(object):
SERIALIZABLE_TYPES = [str, int, bool, float, list, dict, type(None)]
def __init__(self, element):
self.element = element
def execute(self):
if isinstance(self.element, dict):
self.iterate_dict()

In your js:

;(function () {
    window.lcms = window.lcms || {}
    window.lcms.initSomething = function (config) {
        doStuffWith(config.var_name)
        $.ajax(config.whatever_url)
    }
}).call(this);
@reidransom
reidransom / gist:2c699837044898ec6227
Last active September 11, 2015 16:32
Setup a python3 venv
pyvenv-3.4 ~/venv/myvenv --without-pip
. ~/venv/myvenv/bin/activate
curl -O https://bootstrap.pypa.io/ez_setup.py
python ez_setup.py
easy_install pip
@reidransom
reidransom / views.py
Last active June 27, 2022 16:03
Returning binary data from a Django view
from django.http import HttpResponse
def django_file_download_view(request):
filepath = '/path/to/file.xlsx'
with open(filepath, 'r') as fp:
data = fp.read()
filename = 'some-filename.xlsx'
response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=%s' % filename # force browser to download file
response.write(data)
# localhost:3000
NoMethodError in Home#index
Showing /Users/editor/Dropbox/www.b2plus.tv/app/views/home/index.html.slim where line #2 raised:
undefined method `poster' for nil:NilClass
Extracted source (around line #2):
@reidransom
reidransom / gist:7000836
Created October 16, 2013 00:32
Convert svg to png with the CLI
/Applications/Inkscape.app/Contents/Resources/bin/inkscape image.svg --export-png=image.png

A simple objective-c program

#import <Foundation/foundation.h>

int main( int argc, const char* argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSObject *object = [[NSObject alloc] init];
    NSLog(@"Created Object: %@", object);
    [pool release];

return 0;

@reidransom
reidransom / gist:6198304
Created August 9, 2013 23:59
Execute a command for each file in a folder

Execute a command for each file in a folder

$ for f in *.xls ; do xls2csv "$f" "${f%.xls}.csv" ; done

@reidransom
reidransom / gist:6167543
Last active December 8, 2022 05:50
HandBrakeCLI encoding for HTML5 Video

HandBrakeCLI --input 88Min_20_v2.mov --output 88Min_20_v2-handbrake.mp4 --large-file --optimize --encoder x264 --x264-preset medium --x264-profile high --x264-tune zerolatency --encopts level=3.1:vbv-bufsize=17500:vbv-maxrate=17500 --quality 22 --width 960 --height 540 --pixel-aspect 1:1 --decomb

@reidransom
reidransom / gist:6086313
Last active December 20, 2015 06:29
Create an empty file in OS X

Create an empty file in OS X

$ mkfile 1m onemegfile.txt