Skip to content

Instantly share code, notes, and snippets.

View ivangonekrazy's full-sized avatar

Ivan Tam ivangonekrazy

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ivangonekrazy on github.
  • I am IvanTam (https://keybase.io/IvanTam) on keybase.
  • I have a public key whose fingerprint is 92A4 A414 9C77 BEC7 2097 97BC F46D 97C8 44F0 5D8E

To claim this, I am signing this object:

@ivangonekrazy
ivangonekrazy / tweep
Created August 25, 2014 16:49
Output of `nslookup` and `curl`
Last login: Fri Aug 22 16:51:51 on ttys000
Traphaus:~ ivan$ nslookup community.loggly.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
community.loggly.com canonical name = loggly-haproxy-1333703238.us-west-2.elb.amazonaws.com.
Name: loggly-haproxy-1333703238.us-west-2.elb.amazonaws.com
Address: 54.201.53.220
Name: loggly-haproxy-1333703238.us-west-2.elb.amazonaws.com
import logging
# Get the top-level logger object
log = logging.getLogger()
# make it print to the console.
console = logging.StreamHandler()
log.addHandler(console)
# emit a warning to the puny Humans
import logging
log = logging.getLogger() # 'root' Logger
console = logging.StreamHandler()
format_str = '%(asctime)s\t%(levelname)s -- %(processName)s %(filename)s:%(lineno)s -- %(message)s'
console.setFormatter(logging.Formatter(format_str))
log.addHandler(console) # prints to console.
import logging
log = logging.getLogger()
# Set a severity threshold to one above WARN
log.setLevel(logging.ERROR)
# This WARNING will not reach the Humans.
log.warn('Citizens of Earth, be warned!')
# This CRITICAL message, however, will not be ignored.
import logging import logging.config
LOGGING_CONFIG = {
'version': 1, # required
'disable_existing_loggers': True, # this config overrides all other loggers
'formatters': {
'simple': {
'format': '%(asctime)s %(levelname)s -- %(message)s'
},
'whenAndWhere': {
@ivangonekrazy
ivangonekrazy / word_counter.py
Created February 2, 2011 01:05
Reports a count of words for a given file.
import re
from collections import defaultdict
SHORT_WORD_LEN = 4
WORD_REGEX = '\w+'
TEXT_FILE_PATH = 'text.txt'
word_counter = defaultdict(int)
# read in all the words, cull out the ones that aren't long enough
@ivangonekrazy
ivangonekrazy / collect_frame_contexts.py
Created April 15, 2011 08:05
Idea for how to walk up the stack frames, accumulating some attribute along the way.
import inspect
def collect_frame_contexts(attr='__frame__', start_depth=1, **immediatecontext):
"""
Bubbles up the call stack, accumulating
__frame__ context dicts.
"""
contexts = []
frames = inspect.getouterframes( inspect.currentframe() )
@ivangonekrazy
ivangonekrazy / gist:1135416
Created August 9, 2011 22:53 — forked from anonymous/gist:1135410
Draw pie charts
// Draw pie charts
var charts = [];
function createPie(statsjson, type, div, title) {
if(document.getElementById(div)){
data = createDataArray(statsjson, type, title, 'reg');
if(data.getNumberOfRows() > maxResults){
data.removeRows(maxResults, 999999)
}
@ivangonekrazy
ivangonekrazy / cors_resource.py
Created December 4, 2011 03:30
CORS Resource for Django Piston
from django.http import HttpResponse
from piston.resource import Resource
from piston.handler import AnonymousBaseHandler, BaseHandler
class CORSResource(Resource):
"""
Piston Resource to enable CORS.
"""
# headers sent in all responses