Skip to content

Instantly share code, notes, and snippets.

from rx import Observable, Observer
from collections import defaultdict
users = [
{ "id" : 0, "name" : "Hero" },
{ "id" : 1, "name" : "Dunn" },
{ "id" : 2, "name" : "Sue" },
{ "id" : 3, "name" : "Chi" },
{ "id" : 4, "name" : "Thor" },
{ "id" : 5, "name" : "Clive" },
@eenblam
eenblam / GameDataInPython.md
Last active June 21, 2017 14:49
A quick write-up on representing game data in Python for a friend

Basic idea with a dict

p = {
        'name': 'Ystr',
        'age': 119,
        'skills': ['spamming', 'egging']
    }
print(p['name']) # => Ystr
print(p['skills'][1]) # => egging
@eenblam
eenblam / consumer.py
Created September 12, 2016 21:09
Generating and consuming infinite unix pipes with Python
#!/usr/bin/env python
import fileinput
import sys
# Reverse each incoming line
input_lines = fileinput.input(sys.argv[2:])
for line in input_lines:
line = line.strip()[::-1] + '\n'
sys.stdout.write(line)
#!/usr/bin/env python
import math
from Crypto.Util.number import *
import Crypto.PublicKey.RSA as RSA
with open('key1','r') as f1, open('key2', 'r') as f2:
# Short n
n1 = long(f1.readline().strip())
# Long n
#!/usr/bin/env python
from pwn import *
from itertools import permutations
def check_palindrome(s):
length = len(s)
half = length / 2
return s[:half] == s[-half:][::-1]
@eenblam
eenblam / index.html
Last active October 28, 2016 15:13 — forked from gka/index.html
(TODO: Update to D3v4) simple tables in D3
<!DOCTYPE html>
<!-- Source: http://bl.ocks.org/gka/17ee676dc59aa752b4e6 -->
<html>
<head>
<meta charset="utf-8">
<style>
.dash { width: 100%; }
table, #toggles { display: inline-block; }
@eenblam
eenblam / Autotest.md
Last active October 25, 2016 21:08
quick autotesting with pyinotify

Inspired by Building robust software in Python using unit tests. I didn't want to bother with fswatch, and I found a similar script in the pyinotify wiki.

With the included Makefile, you can just run make dev_test, and your tests will execute whenever you make an edit! Better for the early stages of a TDD project.

Note that you can add more than just .py files. autotest.py ~/path/to/project .py,.js,.html "clear && make tests" will run your test suite whenever you create, delete, or edit a file with a .py, .js, or.html extension.