Skip to content

Instantly share code, notes, and snippets.

View jonbodner's full-sized avatar

Jon Bodner jonbodner

  • @jonbodner@noc.social
View GitHub Profile
@jonbodner
jonbodner / fizzbuzz.go
Created July 1, 2014 19:15
Very silly FizzBuzz in Go
package main
import "fmt"
type data struct {
i int
s string
}
func (d data) String() string {
@jonbodner
jonbodner / firstNonRepeat.go
Created July 1, 2014 19:20
First non-repeated character in a string in Go
package main
import "fmt"
func firstNonRepeatChar(s string) rune {
useMap := make(map[rune]bool)
for _, v := range s {
_, ok := useMap[v]
useMap[v] = ok
}
@jonbodner
jonbodner / monty_hall.go
Created July 5, 2014 22:54
Simple implementation to demonstrate the Monty Hall Problem (http://en.wikipedia.org/wiki/Monty_Hall_problem)
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
@jonbodner
jonbodner / star_solve.go
Created July 14, 2014 04:10
Solver for the 6-point Magic Star Problem
package main
import (
"fmt"
)
type ValSet struct {
one, two, three, four *int
}
@jonbodner
jonbodner / fizzbuzz_no_cond.go
Last active August 29, 2015 14:12
FizzBuzz for Go with no conditionals.
package main
import "fmt"
type fber func(int)string
func fizzer(i int) string {
return "fizz"
}
@jonbodner
jonbodner / YFact.go
Created May 3, 2012 01:50
Y Combinator in Go
package main
import "fmt"
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html
type Func func (interface{}) interface{}
type FuncToFunc func (Func) Func
@jonbodner
jonbodner / even_first.go
Created May 7, 2012 17:03
Even-Odd Partition in Go
package main
import "fmt"
import "math/rand"
import "time"
func main() {
rand.Seed(time.Now().UnixNano())
vals := rand.Perm(10)
fmt.Println(vals)
package main
import (
"fmt"
"math/rand"
)
/*
A famous problem of computer science is the knapsack problem, in which you are to find a combination of items from a population that sums to a given target,
often with some kind of constraint such as maximizing the value of the items. In today’s problem we want to find the first possible combination
@jonbodner
jonbodner / map_red.go
Created June 6, 2012 21:43
Trivial map/reduce in Go
package main
import "fmt"
type FSlice []interface{}
type Collector func(interface{}) interface{}
type Reducer func(*interface{}, interface{})
@jonbodner
jonbodner / gist:8263779
Created January 5, 2014 03:04
xorg file for my crouton environment
[ 36.904]
X.Org X Server 1.14.3
Release Date: 2013-09-12
[ 36.904] X Protocol Version 11, Revision 0
[ 36.905] Build Operating System: Linux 3.2.0-37-generic x86_64 Ubuntu
[ 36.905] Current Operating System: Linux localhost 3.8.11 #1 SMP Tue Dec 17 23:30:18 PST 2013 x86_64
[ 36.905] Kernel command line: cros_secure console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=/dev/dm-0 rootwait ro dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=1 dm="1 vroot none ro 1,0 2097152 verity payload=PARTUUID=2c4281de-eb40-5845-b5d3-3abb5bec426c/PARTNROFF=1 hashtree=PARTUUID=2c4281de-eb40-5845-b5d3-3abb5bec426c/PARTNROFF=1 hashstart=2097152 alg=sha1 root_hexdigest=026a06e3907ed6c5d49c5fc171be6f96c9d4748f salt=f1eaf5d4d293e159349aed39e38e6965934873a4409313af98a350450a7ec894" noinitrd vt.global_cursor_default=0 kern_guid=2c4281de-eb40-5845-b5d3-3abb5bec426c add_efi_memmap boot=local noresume noswap i915.modeset=1 tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapi