Skip to content

Instantly share code, notes, and snippets.

@philangist
philangist / bron_kerbosch.py
Last active August 29, 2015 14:08
Bron Kerbosch solution to facebook's peak traffic engineering challenge
import sys
class Node(object):
def __repr__(self):
return 'Node(value=%s)' % self.value
def __init__(self, value):
self.value = value
self.neighbors = set()
2014-10-05 11:40:18,301 - WebSocketHandler - INFO - [On Message]: {"id":42,"command":"query_page","params":{"type":"query_page","findGUID":"26112cd97a623df8cb4f852911172583b06489c6"}}
2014-10-05 11:40:18,301 - [1] ProtocolHandler - INFO - (I) ws.ProtocolHandler.handle_request of: query_page
2014-10-05 11:40:18,301 - [1] ProtocolHandler - DEBUG - found a handler!
2014-10-05 11:40:18,301 - [1] Market - INFO - Searching network for node: 26112cd97a623df8cb4f852911172583b06489c6
2014-10-05 11:40:18,301 - [1] CryptoTransportLayer - DEBUG - Outgoing Data: {'findGUID': u'26112cd97a623df8cb4f852911172583b06489c6', 'type': 'query_page', 'uri': 'tcp://69.142.134.112:12345', 'senderGUID': u'1e42b94d3f3183e9989975280ce9a6d753bdce2c', 'pubkey': u'04470cc0fb7764d2e8b31edc0ac1018d775c0bf5a799811058050d1e6c51f3f144a2d7e0409e89daca046256aa661704b3c66eacb893f31545a83b31e9b4747467', 'sin': u'9xHVXEzK2JrAnRvDuD4PnPJqAnXYi1UghhVSr9'} 26112cd97a623df8cb4f852911172583b06489c6
2014-10-05 11:40:18,301 - [1] KBucket - DEBUG - [getCo
@philangist
philangist / last_two_seen.py
Created October 2, 2014 14:29
Threes/2048 style merge-if-seen
class SeenQueue(object):
def __init__(self):
self.seen = [None, None]
def is_double(self):
if (self.seen[0] == None and self.seen[1] == None):
return False
if self.seen[0] == self.seen[1]:
return True
@philangist
philangist / adt_sketch.go
Created September 19, 2014 02:29
Abstract Data Type skeletons
// Quick sketch of what some common ADT implementations might look like in Golang.
// I'm thinking about maybe building some sort of very basic program off them.
// Like a stack-based Polish notation calculator (or something)>
type Entity struct {
Content interface{} // generic?
}
type Stack struct {
Values []Entity
@philangist
philangist / tinder_bot.py
Last active November 16, 2015 12:32
Tinder Bot
import requests
import time
# Tinder beefed up their API security, so it's no longer possible to grab the facebook OAuth
# token and use it to dynamically retreive this value. You'll have to manually inspect the returned
# call using Charles or some other reverse https proxy for now.
access_token = "SOME_SESSION_KEY"
# some very simple backoff logic
backoff = [1,2,4,8,16,0]
import random
#Face Cards
ACE = 'Ace'
JACK = 'Jack'
KING = 'King'
QUEEN = 'Queen'
#Suits
CLUBS = 'Clubs'
@philangist
philangist / binary_decimal_hexadecimal.py
Last active August 29, 2015 14:02
Base 2 to Base 10 and Base 10 to Base 16 interger conversion
BASE_16 = 16
HEXADECIMAL_CHARACTERS = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'A', 'B', 'C', 'D', 'E', 'F',
]
DECIMAL_TO_HEXADECIMAL_MAPPING = {
x: HEXADECIMAL_CHARACTERS[x]
for x in range(len(HEXADECIMAL_CHARACTERS))
}
@philangist
philangist / Emacs_Commands.md
Created September 9, 2013 21:18
Emacs commands

Emacs Commands

File

ctrl+x, ctrl+f Open file
ctrl+x, ctrl+s Save
ctrl+x, ctrl+w Save As
ctrl+x, s Save All

{% extends "base.html" %}
{% block content %}
<h2>Dry Cleaning Orders</h2>
{% url 'dry_cleaning_add' as add_dry_cleaning_url %}
<div class="btn-toolbar">
<a href="{{ add_dry_cleaning_url }}">
<button class="btn btn-primary">New Order</button>
</a>
</div>
import md5
import requests
from requests.auth import HTTPBasicAuth
class DigestClient(object):
def __init__(self, url, username, password):
self.url = url
self.username = username