Skip to content

Instantly share code, notes, and snippets.

View shanemhansen's full-sized avatar

Shane Hansen shanemhansen

View GitHub Profile
@shanemhansen
shanemhansen / multi.py
Created October 2, 2011 23:41
creating a simple python thread
import thread
import time
def run():
start=1
while 1:
start=start*2
thread.start_new_thread(run,())
thread.start_new_thread(run,())
time.sleep(1000)
@shanemhansen
shanemhansen / gist:1503826
Created December 20, 2011 23:39
Using the /proc filesystem
shansen@bazinga:~/Documents/dev/looplingo$ ls -hal /proc/22499/fd
total 0
dr-x------ 2 shansen shansen 0 2011-12-20 16:27 .
dr-xr-xr-x 8 shansen shansen 0 2011-12-20 16:27 ..
lrwx------ 1 shansen shansen 64 2011-12-20 16:28 0 -> /dev/pts/0
lrwx------ 1 shansen shansen 64 2011-12-20 16:28 1 -> /dev/pts/0
lrwx------ 1 shansen shansen 64 2011-12-20 16:27 2 -> /dev/pts/0
lr-x------ 1 shansen shansen 64 2011-12-20 16:28 3 -> /home/shansen/VirtualBox VMs/looplingodev/looplingodev.vdi
l-wx------ 1 shansen shansen 64 2011-12-20 16:28 4 -> /home/shansen/VirtualBox VMs/looplingodev/looplingodev.vdi.bz2
shansen@bazinga:~/Documents/dev/looplingo$ cat /proc/22499/fdinfo/3
install(Word,none) ->
{Word,1,none,none};
install(Word,Tree) when Word<element(1,Tree) ->
{OtherWord,Count,Left,Right}=Tree,
{
OtherWord,
Count,
install(Word,Left),
Right
};
print(none)->
none;
print(Tree) ->
{Word,Count,Left,Right}=Tree,
print(Left),
io:fwrite("~s ~B",[Word,Count]),
print(Right).
-module(tree).
-export([test_with_file/1,install/2,print/1]).
test_with_file(Name)->
{ok,Device} = file:open(Name,[read]),
test(none,Device).
test(Tree,Device) ->
case io:get_line(Device,"") of
eof ->
print(Tree);
@shanemhansen
shanemhansen / go defer for python.py
Created May 16, 2012 17:43
Don't try this at home
import inspect
frames={}
class MyObj:
def __init__(self):
self.callbacks = []
def __del__(self):
print "callbacks"
for thing in self.callbacks:
try:
@shanemhansen
shanemhansen / gist:2716681
Created May 17, 2012 05:32
Go syntax checking
;;optional, but awesome way to install packages like flymake and go-mode on emacs24
;;(require 'package)
;;(add-to-list 'package-archives
;; '("marmalade" . "http://marmalade-repo.org/packages/"))
;;M-x list-packages
;; install flymake, go mode
;;
;; To activate syntax checking in buffer: M-x flymake-mode
(require 'flymake)
(require 'flymake-cursor)
@shanemhansen
shanemhansen / gist:2897962
Created June 8, 2012 20:22
Computing Euler's number in pure bash
#!/bin/bash
function numerator() {
local __resultvar=$1
local fraction=$2
if [[ $fraction =~ (.*)/.* ]] ; then
eval $__resultvar="'${BASH_REMATCH[1]}'"
fi
}
function denominator() {
@shanemhansen
shanemhansen / gist:2963924
Created June 21, 2012 05:01
Go SSL Echo server
package main;
import "crypto/tls"
import "net"
import "fmt"
import "bufio"
func main() {
cert, err := tls.LoadX509KeyPair("/home/shane/.ssh/shared-space-node.crt",
"/home/shane/.ssh/shared-space-node.key")
config := tls.Config{Certificates: []tls.Certificate{cert}}
import sys
map = {}
while True:
line = sys.stdin.read(8)
if not line:
break
map[line] = map.get(line, 0) + 1
for key in map: