Skip to content

Instantly share code, notes, and snippets.

View code-shoily's full-sized avatar

Code Shoily code-shoily

  • Toronto, ON
  • 01:38 (UTC -12:00)
View GitHub Profile
@code-shoily
code-shoily / gps_server_twisted.py
Last active December 31, 2015 20:38
Twisted version of a much more featured Netty Server I coded a couple of years back. Going to separate out the parsers and Mongofy the DB.
import string
import simplejson
from twisted.internet import protocol, reactor
from twisted.protocols.basic import LineReceiver
from twisted.enterprise import adbapi
from twisted.python import log
TABLE = 'raw_data'
{
"metadata": {
"name": "IPython Blog Part 1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
from simplejson import loads
from urllib2 import urlopen
def get_nearest_locations(lat, lng):
url = 'http://maps.google.com/maps/api/geocode/json?latlng={},{}&sensor=true'
output = loads("".join(map(lambda i: i.replace(r"\n\t ", "").strip(),
urlopen(url.format(lat, lng)).readlines())))
return {
import sys
from twisted.internet import inotify, reactor
from twisted.python import filepath
def change_handler(watch, path, mask):
# Call re-compile cmds etc on the file according to mask value via subprocess, perhaps?
print "WATCH: {}, PATH: {}, MASK: {}".format(watch, path, mask)
def crc_itu(s):
""" Function to calculate CRC-ITU value given a list of hex
>>> v0 = [0x05, 0x01, 0x00, 0x01]
>>> v1 = [0x0D, 0x01, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x00, 0x01]
... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
>>> hex(crc_itu([chr(i) for i in v0]))
'0xd9dc'
>>> hex(crc_itu([chr(i) for i in v1]))
'0x8cdd'
(defn crc-itu [s] (let [crc16tab [0x0000 0x1189 0x2312 0x329b 0x4624 0x57ad 0x6536 0x74bf
0x8c48 0x9dc1 0xaf5a 0xbed3 0xca6c 0xdbe5 0xe97e 0xf8f7
0x1081 0x0108 0x3393 0x221a 0x56a5 0x472c 0x75b7 0x643e
0x9cc9 0x8d40 0xbfdb 0xae52 0xdaed 0xcb64 0xf9ff 0xe876
0x2102 0x308b 0x0210 0x1399 0x6726 0x76af 0x4434 0x55bd
0xad4a 0xbcc3 0x8e58 0x9fd1 0xeb6e 0xfae7 0xc87c 0xd9f5
0x3183 0x200a 0x1291 0x0318 0x77a7 0x662e 0x54b5 0x453c
0xbdcb 0xac42 0x9ed9 0x8f50 0xfbef 0xea66 0xd8fd 0xc974
0x4204 0x538d 0x6116 0x709f 0x0420 0x15a9 0x2732 0x36bb
0xce4c 0xdfc5 0xed5e 0xfcd7 0x8868 0x99e1 0xab7a 0xbaf3
from StringIO import StringIO
from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter
from openpyxl.styles import Style, Font
def make_excel(dataset,
key_headers=None, # The order of attributes, or what to include
line_headers=None, # The order of table attributes, or what to include
var LIMIT = 1000000;
var cache = [];
var output = [1, 1];
for (var i = 0; i < LIMIT; i++) {
cache[i] = i==1 ? i : 0;
}
for (i = 1; i < LIMIT; i++) {
var n = i, ll = 0, Q = [];
(defn quick-sort
"Takes a list and sorts it following the quick sort algorithm"
[lst]
(if (empty? lst) []
(concat
(quick-sort (filter (partial > (first lst)) (rest lst)))
(list (first lst))
(quick-sort (filter (partial <= (first lst)) (rest lst))))))
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import imaplib
import email
from email.header import decode_header
import HTMLParser
IMAP_ADDR = 'imap.gmail.com'
USERNAME = '<EMAIL_ADDRESS>'