Skip to content

Instantly share code, notes, and snippets.

recv := make(chan int)
send := make(chan int)
go func() {
queue = make([]int, 0)
done := false
for !done {
if len(queue) == 0 {
select {
@jamesharr
jamesharr / gist:8186831
Created December 30, 2013 19:31
Table naming bug in gorm
package main
import "github.com/jinzhu/gorm"
import (
_ "github.com/lib/pq"
"fmt"
)
type Foo struct {
Id int64
@jamesharr
jamesharr / foo.go
Created January 4, 2014 03:18
For go-lang-idea-plugin bug #115
// $GOPATH/foopkg/whatever.go
package asdf
var X = "Hello"
package main
import (
"fmt"
"play/pkgaccess/pkg"
)
func main() {
fmt.Println(pkg.Bar) // Huh, I an access it
lcl := pkg.Bar // Huuuh, I can create a copy of it.
@jamesharr
jamesharr / tmpclean-mac.sh
Created January 6, 2014 20:32
Script for managing ~/Downloads. Works relatively well, though it sometimes misses things.
#!/bin/bash
# Keep Downloads folder clean on a mac using xattr to track age.
# Normally, stick something like this in your crontab. It's pretty quick
# and not I/O intentisve, so I run every hour on some random time.
#
# Example crontab:
# 37 * * * * LOGME=1 /Users/james/bin/tmpclean-mac.sh /Users/james/Downloads 7
dir="$1"
@jamesharr
jamesharr / example.go
Last active January 2, 2016 16:09
Get around Go's lack of type parameterization with pointers. It's about a 40% performance hit to do it with reflection, but that's 900ns vs 500ns, so as long as a majority of your work doesn't involve fetching things this way, it's a pretty effective way to services in Go.
package main
import (
"fmt"
. "play/fill"
)
func main() {
var a Foo // Foo is just an interface, not a concrete type.
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def http = new HTTPBuilder('https://grickle.org/')
http.get( path: '/myip.php', contentType: TEXT ) { resp, reader ->
printn "Status: ${resp.statusLine}" // <-- typo right here
System.out << reader
}
package controllers
import (
"github.com/astaxie/beego"
"io/ioutil"
)
type MainController struct {
beego.Controller
}
@jamesharr
jamesharr / output.txt
Created October 29, 2018 19:33
weekly quiz
$ time go run random-quiz-crypto.go
decryptKey 239333
decrypt 375289 -> 230801
decrypt 485994 -> 200009
decrypt 047367 -> 190020
decrypt 543573 -> 051400
decrypt 785337 -> 131504
decrypt 477107 -> 002023
decrypt 727268 -> 150000
"WHAT IS TEN MOD TWO "
#!/usr/bin/env python3
import networkx as nx
import community
G = nx.Graph()
G.add_node('node_a')
G.add_node('node_b')
G.add_node('node_c')
G.add_node('node_d')