Skip to content

Instantly share code, notes, and snippets.

import select
import socket
class UDPEchoServer(object):
def __init__(self):
self.sock = socket.socket(type=socket.SOCK_DGRAM)
self.sock.bind(('0.0.0.0', 5000))
@jart
jart / pbkdf2.c
Created September 13, 2011 21:39
Justine's PBKDF2
/* gcc -O3 --std=gnu99 -o pbkdf2 pbkdf2.c sha256.c && time ./pbkdf2 password salt 100000 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "sha256.h"
#define DIGEST_SIZE 32
#define BLOCK_SIZE 64
@jart
jart / gist:3156709
Created July 21, 2012 18:43
Assembly Audio Mixing
/**
* Represents 20ms of 8khz signed linear 16-bit audio
*
* This is how much audio gets put in each RTP packet.
*/
typedef int16_t frame_t[160];
/**
* Fast mix two audio frames together on x86 and x86_64
*
@jart
jart / gist:3432942
Created August 23, 2012 05:24
Generated Poetry
-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-
IAMBIC PENTAMETER COUPLETS GOTH CORPUS
-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-
we really have to plug my eyes before
black angel i feel hunger for the shore
which answered not with a caress he died
shone for me to the lake of the night tide
with sadness here i opened wide the door
that scream i hear the angels name lenore
@jart
jart / gotham.py
Created August 23, 2012 05:27
Gothic Poetry Generator
r"""
gotham
~~~~~~
Gothic Poetry Generator
"""
import sys
@jart
jart / gotham.py
Created August 24, 2012 20:12
Lorem Gotham w/ Rhyming
r"""
gotham
~~~~~~
Gothic Poetry Generator
"""
import marshal
@jart
jart / form_errors.html
Last active December 11, 2015 01:39
An example of how to use Twitter Bootstrap with Django Forms
{% for error in form.non_field_errors %}
<div class="alert alert-error">{{ error }}</div>
{% endfor %}
@jart
jart / euler.py
Last active March 19, 2016 18:32
These are the Project Euler solutions I wrote to sharpen my coding skills when I was preparing for my Google interviews. I don't have a strong background in math. So sometimes you'll notice I just kludge things and treat numbers as strings.
# problem 1
# add all natural numbers below one thousand that are multiples of 3 or 5.
print sum(n for n in xrange(1, 1000) if n % 3 == 0 or n % 5 == 0)
# problem 2
# sum of even value fibs below four million
def fib():
yield 1
yield 1
a, b = 1, 1
@jart
jart / gist:4704095
Created February 3, 2013 22:53
Google Open Source Libraries for C++ Development
* http://google-opensource.blogspot.com/
* http://blog.0x1fff.com/2009/12/35-google-open-source-projects-that-you.html
* glog - An excellent C++ logging library.
* gtest - An excellent C++ testing library.
* gflags - The best way to make your C++ program accept command line flags, be documented, and configurable all in one fell swoop.
* breakpad - A good multi-platform crash reporting system for C++ apps.
* gperftools - Faster heap memory and a bunch of tools similar to valgrind. Not as well maintained as it should be.
* sparsehash - An awesome hash map container library for both performance and low memory use cases.
* cityhash - Perhaps the best non-crypto hashing algorithm. 2x faster than MurmurHash.
* re2 - A drop-in replacement for PCRE (Perl Compatible Regular Expressions) that doesn't introduce security and performance risks. Most other regex libraries will run potentially boundless operations which can have surprising performance impacts and allow attackers to perform denial of service attacks.
@jart
jart / motd
Created September 28, 2013 02:56 — forked from anonymous/motd
                                                                       
                                                                         
                                                                            
                                                                              
                                         [48;5;237