Skip to content

Instantly share code, notes, and snippets.

View tomleo's full-sized avatar
:shipit:
Hacking into the mainframe

Tom Leo tomleo

:shipit:
Hacking into the mainframe
View GitHub Profile
@tomleo
tomleo / symmetric-encryption.py
Created February 6, 2014 19:32
Python symmetric encryption with CRC
# This code is via http://www.turnkeylinux.org/blog/python-symmetric-encryption
# Author: Alon Swartz
import zlib
import struct
from Crypto.Cipher import AES
class CheckSumError(Exception):
pass
@tomleo
tomleo / simplify_statistics.py
Created June 10, 2014 17:04
Cut down on the amount of data in data set.
import csv
import codecs
fin = 'quick-statistics.csv'
threshold = 40
lines_to_keep = []
with open(fin, 'r') as f:
keep_line = 0
reader = csv.reader(f)
@tomleo
tomleo / test_kwargs.py
Created August 26, 2014 14:24
Examples showing the flexibility of passing args and kwargs to python functions.
import sys
num = 0
def printNum(func):
def pprint(*args, **kwargs):
global num
num += 1
sys.stdout.write(u'%s: ' % num)
sys.stdout.write(func(*args, **kwargs))
sys.stdout.write(u'\n')
return pprint
@tomleo
tomleo / SassMeister-input.scss
Created August 27, 2014 14:04
Generated by SassMeister.com.
// ----
// Sass (v3.3.14)
// Compass (v1.0.0)
// ----
@mixin animation($animate...) {
$max: length($animate);
$animations: '';
@for $i from 1 through $max {
@tomleo
tomleo / gist:155ceceb41287e777e81
Created January 6, 2015 16:36
Checking Equality of Hashes
def is_equal(val1, val2):
"""
This is a really nice way to comparing two hash values using the set operation XOR
This snippet is from the plone project https://github.com/plone/plone.session/blob/master/plone/session/tktauth.py
"""
# constant time comparison
if not isinstance(val1, basestring) or not isinstance(val2, basestring):
return False
@tomleo
tomleo / gist:b6823624bc77b7b78a5f
Created January 6, 2015 22:05
Efficient scroll function using setInterval
$.fn.scrollFoo = function() {
'use strict'
var that = this,
didscroll = false;
$(window).scroll(function() {
didscroll = true;
});
@tomleo
tomleo / parsing_name_col.py
Created January 16, 2015 16:18
Grepping Names
# Last, Middle, First
(\w+)(,\ )(\w+.),\ (\w+)
# First Middle. Last, Title
(\w+)\ (\w+).\ (\w+),\ (\w+)
# First Last (via Twitter)
(\w+)\ (\w+)\ (\([\w\ ]+\))
@tomleo
tomleo / SassMeister-input.scss
Created January 29, 2015 17:05
Generated by SassMeister.com.
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
//Use placeholders for repeating visual styles
%dotted-border { border: 1px dotted #eee; }
.box1 {
@extend %dotted-border;
@tomleo
tomleo / SassMeister-input.scss
Created January 29, 2015 17:10
Generated by SassMeister.com.
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
//Write mixins where the pattern takes variables
@mixin transparent-backgroung($color, $alpha) {
$rgba: rgba($color, $alpha);
$ie-hex-str: ie-hex-str($rgba);
background-color: transparent;
@tomleo
tomleo / SassMeister-input.scss
Created January 29, 2015 17:12
Generated by SassMeister.com.
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
//Use placeholders for repeating visual styles:
%dotted-border { border: 1px dotted #eee; }
.box {
@extend %dotted-border;