Skip to content

Instantly share code, notes, and snippets.

View iepathos's full-sized avatar
🥊
Taking care of business

Glen Baker iepathos

🥊
Taking care of business
  • Headspin
  • Mountain View, CA
  • 13:23 (UTC -07:00)
  • LinkedIn in/glenbbaker
View GitHub Profile

Keybase proof

I hereby claim:

  • I am iepathos on github.
  • I am iepathos (https://keybase.io/iepathos) on keybase.
  • I have a public key ASD9gj36Xvfv8VyEEwuWO1EpimNbmXS9Hk5Yqzs7XICj7wo

To claim this, I am signing this object:

'''
Simple socket server using threads
'''
import socket
import sys
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import SocketServer
class MyTCPHandler(SocketServer.BaseRequestHandler):
"""
The RequestHandler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
@iepathos
iepathos / sorting_example_by_subdict_key
Last active May 4, 2018 15:11
Explicitly sorting a dictionary by a sub-dictionary subkey into an ordered list.
# Dictionaries are inherently orderless, but lists are ordered!
import collections
d = { '123': { 'key1': 3, 'key2': 11, 'key3': 3 },
'124': { 'key1': 6, 'key2': 56, 'key3': 6 },
'125': { 'key1': 7, 'key2': 44, 'key3': 9 } }
results_list = []
sort_by_dict = {}
@iepathos
iepathos / Flask-Mega-Tutorial-manager.py
Created September 23, 2013 23:09
Manager script I created after running through Miguel Grinberg's excellent Flask Mega-Tutorial which starts at: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world - I used the Flask-Script extension to create a manager.py script where I organized the translation and database management scripts from the tutorial as com…
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask.ext.script import Manager, Command, Option
from app import app, db
import os
import imp
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
@iepathos
iepathos / python_primal_numbers.py
Last active December 17, 2015 12:59
Python Primal Number functions
import random, sys
"""
Miller Rabin Probabilistic Primality Test
"""
def miller_rabin_pass(a, s, d, n):
a_to_power = pow(a, d, n)
if a_to_power == 1:
return True
for i in xrange(s-1):
@iepathos
iepathos / python_factorization.py
Last active December 17, 2015 12:19
This is a very fast factorization algorithm. I've concocted it from several sources. It would be hard to find one faster than this.
from math import sqrt
"""
Fast factorization algorithm. Uses tuples instead of lists
and sqrt over exponentiation.
"""
def factors(n):
return set(x for tup in ([i, n//i]
for i in range(1, int(sqrt(n))+1) if n % i == 0) for x in tup)
@iepathos
iepathos / Chrome and Django favicon fix
Last active October 4, 2022 17:06
Fix for Google Chrome favicon loading in Django. You may have noticed that Chrome has issues loading the appropriate favicon on Django if you have it in a different path other than just '/favicon.ico'. Firefox follows the template icon links no problem, but Chrome needs a little more help. I fixed this issue by adding this quick line to the urls…
#urls.py
from django.conf import settings
urlpatterns = patterns('',
url(r'^favicon.ico/$', lambda x: HttpResponseRedirect(settings.STATIC_URL+'ico/favicon.ico')), #google chrome favicon fix
)
# base.html
<link rel="shortcut icon" href="{{ STATIC_URL }}ico/favicon.ico">