Skip to content

Instantly share code, notes, and snippets.

View thepug's full-sized avatar

Nathan Zorn thepug

View GitHub Profile
@thepug
thepug / collatz.rb
Created October 10, 2017 16:29 — forked from trishume/collatz.rb
Collatz conjecture chains in ruby
# small recursive version
def collatzr(num,arr = [])
return arr if arr.unshift(num)[0] == 1
num.even? ? collatzr(num / 2,arr) : collatzr(num * 3 + 1,arr)
end
# pretty looping version
def collatz(num,arr = [])
while num != 1
arr << num
num = num.even? ? num / 2 : num * 3 + 1
@thepug
thepug / imgblur-refactor.rb
Created August 31, 2017 15:37 — forked from spilledmilk/imgblur-refactor.rb
Refactored code for Image Blur challenges (incl. Manhattan Distance)
class Image
attr_accessor :array
def initialize(array)
@array = array
end
def blur(distance = 1)
distance.times do
transform
talkto.com.access.log:180.194.172.72 - - [08/Apr/2013:12:03:53 +0000] "GET /media/images/static/1x1.png?js_error_log=Script+error.&url=&line=0 HTTP/1.1" 200 179 "http://workflow.talkto.com/workflow/ticket/b68fe20b-f2bd-4724-b9f6-db5219a11115/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31" "c64895a7-85ba-4ccc-b3c0-9aea4f4f480d" "-"
talkto.com.access.log:110.55.5.91 - - [08/Apr/2013:12:24:47 +0000] "GET /media/images/static/1x1.png?js_error_log=Uncaught+TypeError:+Cannot+read+property+'$el'+of+undefined&url=http://talkto.com/media/min/agent-r1364744048.js&line=102 HTTP/1.1" 200 179 "http://talkto.com/workflow/ticket/c1badfcf-6fe1-45b7-888a-49e2ea9ad08f/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31" "11858155-f7a7-4c9c-b67b-700245e86f06" "-"
talkto.com.access.log:121.97.142.47 - - [08/Apr/2013:13:07:02 +0000] "GET /media/images/static/1x1.png?js_error_log=TypeError:+document.activeElement.getAtt
class ApiTTests(TestCase):
fixtures = ['auth_views_testdata.json']
def setUp(self):
email = "w0"
user = User.objects.create_user(username=email, email=email)
user.set_unusable_password()
user.jid = email
user.save()
user.apikey = get_api_key(user)
print "Created user: %s" % user.username
@thepug
thepug / fabfile.py
Created March 20, 2012 14:24 — forked from cyberdelia/fabfile.py
Fabric deploy script with : south migrations, rollback and maintenance page.
from fabric.api import env, run, sudo, local, put
def production():
"""Defines production environment"""
env.user = "deploy"
env.hosts = ['example.com',]
env.base_dir = "/var/www"
env.app_name = "app"
env.domain_name = "app.example.com"
env.domain_path = "%(base_dir)s/%(domain_name)s" % { 'base_dir':env.base_dir, 'domain_name':env.domain_name }
@thepug
thepug / gist:936790
Created April 22, 2011 14:35
export functions for ejabberd_http_bind.erl
%% External exports
-export([start_link/3,
init/1,
handle_event/3,
handle_sync_event/4,
code_change/4,
handle_info/3,
terminate/3,
send/2,
send_xml/2,
@thepug
thepug / Pre-Bind using Strophe
Created January 3, 2011 19:47
javascript code example for connecting with http_pre_bind
var PREBIND_URL = "/http-pre-bind";
var BOSH_URL = "/http-bind";
var conn = new Strophe.Connection(PREBIND_URL);
var prebindCallback = function(status) {
var $status = $(status);
var jid = $status.find("jid").text();
var sid = $status.find("body").attr("sid");
var rid = parseInt($status.find("body").attr("rid"), 10)+1;
conn.service = BOSH_URL;
@thepug
thepug / crashdumperl
Created October 18, 2010 16:56
show the erlang proc with highest heap allocation
filename = File.expand_path(File.join(File.dirname(__FILE__), "erl_crash.dump"))
next_line = false
heapallocs = []
counters = []
File.open(filename, "r") do |crashfile|
while (line = crashfile.gets)
if (line =~ /^Stack\+heap:\s(\d)/)
heapallocs.push(Integer(line.split(':')[1]))
end
if (line =~ /^Program\scounter:/)