Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
jgrahamc / gist:3039800
Created July 3, 2012 13:51
Unique ID generator
id := make(chan string)
go func() {
h := sha1.New()
c := []byte(time.Now().String())
for {
h.Write(c)
id <- fmt.Sprintf("%x", h.Sum(nil))
}
}()
package counter
import "io"
type Counter struct {
w io.Writer
c int
}
func New(w io.Writer) (h *Counter) {
@jgrahamc
jgrahamc / gist:3039932
Created July 3, 2012 14:08
Counting ID generator
id := make(chan string)
count := make(chan int)
go func() {
h := sha1.New()
w := counter.New(h)
c := []byte(time.Now().String())
w.Write(c)
for {
select {
@jgrahamc
jgrahamc / gist:3058887
Created July 6, 2012 08:15
Alan Turing script
use strict;
use warnings;
use WWW::Mechanize;
use DB_File;
my %signed;
tie %signed, "DB_File", "signed", O_RDWR|O_CREAT,
0666, $DB_HASH or die "Failed to open signed\n";
@jgrahamc
jgrahamc / gist:3476754
Created August 26, 2012 10:00
Poor APRS Code
alt0=0;
alt1=0;
alt2=0;
alt3=0;
alt4=0;
alt5=0;
d=getch();
c=0;
if (d!='-') do {
alt5=alt4;
var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
board.withLED({pin: 13}, function(err, LED) {
if (err) { return console.log(err); }
LED.blink(250);
LED.on('on', function() }
console.log('LED is on!');
});
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(250);
func redirect(to string, from *os.File) (err error) {
if out, err := os.Create(name); err == nil {
err = syscall.Dup2(int(out.Fd()), int(from.Fd()))
} else {
err = fmt.Errorf("Unable to create file %s", to)
}
return
}
package counter
import (
"io"
)
type Counter struct {
w io.Writer // Underlying writer to send data to
c int // Number of bytes written since last call to Count()
}
@jgrahamc
jgrahamc / gist:5137943
Created March 11, 2013 21:29
A system to save the location (line number) of every file edited with Emacs and let the user jump there with C-l
(setq last-location-file (concat my-emacs-d "/last-location"))
(defun load-last-location-file ()
(if (file-exists-p last-location-file)
(read (with-temp-buffer
(insert-file-contents last-location-file)
(buffer-string)))
(make-hash-table :test 'equal)))
(setq last-location-table (load-last-location-file))