Skip to content

Instantly share code, notes, and snippets.

View glesica's full-sized avatar

George Lesica glesica

View GitHub Profile
@glesica
glesica / units.jl
Last active August 29, 2015 14:17
Rudimentary implementation of units of measure in Julia.
import Base.show, Base.convert
abstract Unit
abstract ScalarUnit <: Unit
abstract CompoundUnit <: Unit
abstract LinearUnit <: ScalarUnit
macro defunit(name::Symbol, parent::Symbol)
@glesica
glesica / ratelimit.ex
Last active August 29, 2015 14:19
GenServer implementation that wraps a function in order to allow calls to be rate limited.
defmodule Auscrape.RateLimit do
use GenServer
use Timex
def start_link(fun, interval, opts \\ []) do
GenServer.start_link(__MODULE__, {fun, interval}, opts)
end
def call_fun(server, args) do
GenServer.call(server, {:call, args}, :infinity)
@glesica
glesica / dynamic_pool.go
Created May 20, 2015 04:25
Dynamic pool that allows concurrency for a set of tasks to be throttled.
package main
import "sync"
func main() {
jobChan := make(chan (chan int))
resChan := make(chan int)
squareGroup := new(sync.WaitGroup)
// The workers
defmodule Units do
def add({x, :in}, {y, :in}), do: {x + y, :in}
def sub({x, :in}, {y, :in}), do: {x - y, :in}
end
Units.add({5, :in}, {4, :in})
@glesica
glesica / gist:1028630
Created June 16, 2011 03:38
Install virtualenvwrapper - .bashrc
# setup virtualenvwrapper
export WORKON_HOME=~/.envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
* POST - create a new log item with the POSTed data. The response
will include a status_code, status_message and the ID of the
newly created log item (if one was successfully created).
Request must contain a valid bot key along with enough information
to construct a valid log item.
* DELETE - delete the given log item. Must include the item ID number
or enough information to uniquely identify the item (see GET
below).
@glesica
glesica / hn.py
Created June 21, 2011 01:39
hacker news phenny module
'''
Phenny module to make Phenny fetch the highest scoring HN article and post
it for discussion.
'''
import os, urllib, json
from datetime import datetime as dt
LOG_PATH = '.'
# Generated by iptables-save v1.4.4 on Fri Jun 18 01:22:38 2010
*filter
# WHAT THE FUCK DO THE NEXT THREE LINES DO?
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [27:2732]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
attr: function( elem, name, value, pass ) {
var nType = elem.nodeType;
// don't get/set attributes on text, comment and attribute nodes
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
return undefined;
}
if ( pass && name in jQuery.attrFn ) {
return jQuery( elem )[ name ]( value );
// Mutifunctional method to get and set values to a collection
// The value/s can optionally be executed if it's a function
access: function( elems, key, value, exec, fn, pass ) {
var length = elems.length;
// Setting many attributes
if ( typeof key === "object" ) {
for ( var k in key ) {
jQuery.access( elems, k, key[k], exec, fn, value );
}