Skip to content

Instantly share code, notes, and snippets.

View ivangonekrazy's full-sized avatar

Ivan Tam ivangonekrazy

View GitHub Profile
@ivangonekrazy
ivangonekrazy / gist:7681057
Created November 27, 2013 18:49
Example for how to use CORS with Loggly's APIv2.
function basicAuth() {
return "Basic " + btoa("<username>:<password>");
};
$.ajax({
url: 'https://<subdomain>.loggly.com/apiv2/customer',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", basicAuth());
},
success: function(data) {
@ivangonekrazy
ivangonekrazy / gist:3990985
Created November 1, 2012 01:09
Send events to Loggly from ActionScript
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
@ivangonekrazy
ivangonekrazy / all_the_method.py
Created April 3, 2012 20:38
<method> ALL THE <type>!!!!!
from inspect import ismethoddescriptor, getmembers
def all_the_methods(_type):
"""
example usage:
all_the_methods(str)
sample elided output:
capitalize() ALL THE <type 'str'>!!!!
center() ALL THE <type 'str'>!!!!
@ivangonekrazy
ivangonekrazy / hack.sh
Created April 1, 2012 01:17 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@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
@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 / 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 / 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