Skip to content

Instantly share code, notes, and snippets.

View dmr's full-sized avatar

Daniel Rech dmr

View GitHub Profile
@dmr
dmr / b64encode.py
Created November 4, 2013 10:42
The script accepts a glob pattern and prints the base64 encoded image on the commandline. Helpful to convert images to inline css
import base64
import glob
import argparse
import os
# fmt_str = u"define(function(){{return 'data:{mimetype};base64,{content}';}});"
fmt_str = u'"data:{mimetype};base64,{content}"'
@dmr
dmr / gist:6120628
Created July 31, 2013 09:17
I have an improved version of http://stackoverflow.com/a/16160300/2630724 to share. All you need in addition to this is one element for the modal <div class="modal fade" data-bind="modal: currentModal"> </div> somewhere on your page and then you open a dialog by writing to the currentModal observable and you close the dialog by nulling it: curre…
ko.bindingHandlers.modal = {
init: function(element, valueAccessor, allBindings, vm, context) {
var modal = valueAccessor();
//init the modal and make sure that we clear the observable no matter how the modal is closed
$(element).modal({show: false}).on("hidden.bs.modal", function() {
if (ko.isWriteableObservable(modal)) {
modal(null);
}
});
@dmr
dmr / gist:c168646cdac49a108da7
Created May 21, 2014 05:39
random_reorder_pdf_file takes a PDF file as input and generates 30 pdfs with the same slides but in random order. Helpful to study
#!/usr/bin/env python
import sys
from pyPdf import PdfFileWriter, PdfFileReader
from random import shuffle
import sha
import os
def random_reorder_pdf_file(fn):
fn_base, ext = os.path.splitext(fn)