Skip to content

Instantly share code, notes, and snippets.

View agocs's full-sized avatar

Christopher Agocs agocs

View GitHub Profile
@agocs
agocs / OnAir.md
Created October 28, 2015 19:46
Instructions for Hangouts On Air

Here's how you create a Hangout On Air for internal DramaFever meetings

  • Go here: https://plus.google.com/hangouts/onair
  • "Create a Hangout On Air"
  • Name it something useful
  • Under the Audience
    • Delete "Public"
    • Add yourself
  • Click "Start"
  • It'll open up a more Youtube-y interface. Click "Start"
@agocs
agocs / foo.go
Created September 30, 2015 20:48
Playing with interfaces
package main
type something struct {
somevalue int
}
type ISomething interface {
isPositive() bool
}
@agocs
agocs / memtest.go
Created September 25, 2015 17:15
Determining how much memory we're using as a percentage of total system memory
package main
import (
"bufio"
"errors"
"fmt"
"os"
"runtime"
"strconv"
"strings"
@agocs
agocs / sysmem.go
Created September 25, 2015 15:13
How to find system memory in Go
func getTotalSystemMemory() (uint64, error) {
var memorySizeBytes uint64 = 1
meminfo, err := os.Open("/proc/meminfo")
if err != nil {
return 10 * 1024 * 1024 * 1024, errors.New("Unable to open /proc/meminfo, probably because you're on a Mac. Returning 10GB for testing purposes.")
}
defer meminfo.Close()
meminfoReader := bufio.NewReader(meminfo)
mkdir byobu
cd byobu/
wget https://launchpad.net/byobu/trunk/5.94/+download/byobu_5.94.orig.tar.gz
tar -zxvf byobu_5.94.orig.tar.gz
cd byobu-5.94
# the INSTALL file contains installation instructions. It says the following should work:
./configure
make
make install
@agocs
agocs / blinks.go
Created April 13, 2015 21:28
Web to Firmata
@agocs
agocs / channels.go
Last active August 29, 2015 14:12
Channel example
package main
func main() {
stringChannel = make(chan string)
go sendToZMQ(stringChannel)
stringChannel <- "Hello there"
stringChannel <- "How are you"
stringChannel <- "shopBot.explode(Now)"
}
@agocs
agocs / squares.py
Created January 5, 2015 22:02
What is the probability that two random lines drawn inside a square will intersect?
import random
#Orientation and doIntersect mostly copied wholesale from here:
# http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
# with some modifications because I can safely ignore their special cases.
def orientation(p, q, r):
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
return val #colinear
(defmacro time-limited
"Use this macro to cause a function to time out after a little while"
[seconds & body]
`(let [f# (future ~@body)]
(try
(.get f# ~seconds java.util.concurrent.TimeUnit/SECONDS)
(catch java.util.concurrent.TimeoutException x#
(do (future-cancel f#)
(throw x#)))
(catch Exception e#
@agocs
agocs / Console_output
Last active August 29, 2015 13:57
What happens when you create a data race in Go?
cagocs:examples christopheragocs$ go run shared_memory.go
I am a very global string.I have been to LondonI have been to France
I am a very global string.I have been to London
I am a very global string.I have been to LondonI have been to France
cagocs:examples christopheragocs$ go run -race shared_memory.go
==================
WARNING: DATA RACE
Write by goroutine 4:
main.writeToSomeString()
/Users/christopheragocs/personal/golangIntro/examples/shared_memory.go:26 +0x38