Skip to content

Instantly share code, notes, and snippets.

View elrikdante's full-sized avatar

Dante Haskell Elrik elrikdante

View GitHub Profile
@mgpb
mgpb / .bashrc
Created April 19, 2011 05:03
bash prompt with git branch name and time since commit, based on what @garybernhardt did.
# It looks like this but with color and stuff:
# (macbot • sample_app ┣master ∆68m)$
# (macbot • autumn ┣master ∆2yr8mo)$
function relative_time_since_last_commit {
last_commit=`git log --pretty=format:'%ar' -1`
echo ${last_commit}
}
@mbalayil
mbalayil / quick_sort.c
Created May 2, 2011 18:12
Quick Sort using recursion in C
/** Divide : Partition the array A[low....high] into two sub-arrays
* A[low....j-1] and A[j+1...high] such that each element
* of A[low....j-1] is less than or equal to A[j], which
* in turn is is less than or equal to A[j+1...high]. Compute
* the index j as part of this partitioning procedure.
* Conquer : Sort the two sub-arrays A[low....j-1] and A[j+1....high]
* by recursive calls to quicksort
**/
#include<stdio.h>
@jamiew
jamiew / eventmachine url expansion tests.rb
Created May 13, 2011 05:53
Noodling with different ways of expanding short URLs in bulk
require 'rubygems'
require 'benchmark'
require 'pp'
require 'mechanize'
require 'eventmachine'
require 'em-http-request'
def syncronous(urls)
agent = Mechanize.new
expanded_urls = urls.map{|url|
@resistorsoftware
resistorsoftware / ShopifyAPICallLimit.rb
Created May 14, 2011 16:01 — forked from christocracy/ShopifyAPICallLimit.rb
Hacking ActiveResource::Connection for Shopify API in order to read HTTP response header 'http_x_shopify_api_call_limit'. Simply require this code after your gems have been loaded.
class ActiveResource::Connection
# HACK 1: Add an attr_reader for response
attr_reader :response
def request(method, path, *arguments)
result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
payload[:method] = method
payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
payload[:result] = http.send(method, path, *arguments)
end
@acowley
acowley / PipelineMutation.hs
Created May 20, 2011 05:06
Fused in-place updates of mutable values
{-# OPTIONS -O #-}
-- Perform in-place updates on mutable data.
import Control.Applicative
import Control.Monad
import Data.IORef
import Data.Monoid
import Debug.Trace
import System.IO.Unsafe
-- Presumably we can duplicate the values we want to mutate. Here, we
@mizzy
mizzy / node-simple-proxy.js
Created November 6, 2011 09:07
Simple proxy made by node.js
var http = require('http');
var url = require('url');
var proxy = http.createServer(function(req, res) {
var request = url.parse(req.url);
options = {
host: request.hostname,
port: request.port || 80,
path: request.path,
method: req.method,
@austinmarton
austinmarton / sendRawEth.c
Created February 27, 2012 08:40
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@casschin
casschin / gist:1990245
Created March 7, 2012 01:16
Python webdriver api quick sheet
### Locating UI elements ###
# By ID
<div id="coolestWidgetEvah">...</div>
element = driver.find_element_by_id("coolestWidgetEvah")
or
from selenium.webdriver.common.by import By
element = driver.find_element(by=By.ID, value="coolestWidgetEvah")
# By class name:
@clm-a
clm-a / hash_checkboxes_rails.rb
Created March 22, 2012 11:48
Checkboxes for rendering an Hash in Rails
# file mood.rb
Mood = Struc.new(:happy)
# file user.rb
class User
serialize mood, Mood
def mood=(attr={})
@jeroenr
jeroenr / Accommodation.rb
Created August 7, 2012 17:09
Use ActiveResource with non-Rails REST API
class Accommodation < ActiveResource::Base
class << self
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end
def collection_path(prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"