Skip to content

Instantly share code, notes, and snippets.

View agocs's full-sized avatar

Christopher Agocs agocs

View GitHub Profile
@agocs
agocs / centroidfinder.py
Last active December 11, 2015 13:48
Easy way to find the centroid of a bunch of placemarks from a KML file.
from xml.dom.minidom import parseString
def findCentroidGivenKML(location):
#Read KML file as a string
file = open(location)
data = file.read()
file.close()
#Parse that string into a DOM
dom = parseString(data)
@agocs
agocs / PlacemarkExample.kml
Created January 23, 2013 18:03
Example of a Placemark
<Placemark>
<name>Tag #58 - White Brothers Auto Parts</name>
<description><![CDATA[]]></description>
<styleUrl>#style29</styleUrl>
<Point>
<coordinates>-84.357826,33.754772,0.000000</coordinates>
</Point>
</Placemark>
@agocs
agocs / kmlasstring.py
Created January 23, 2013 18:06
Read KML as String
#Read KML file as a string
file = open(location)
data = file.read()
file.close()
@agocs
agocs / urlencode.cs
Last active December 16, 2015 14:08
How to URL Encode a string in C#
private string urlencode(string input_url)
{
StringBuilder b = new StringBuilder(100);
foreach (char c in input_url)
{
b.Append(replace(c));
}
return b.ToString();
}
@agocs
agocs / binary8.py
Created October 29, 2013 20:55
A way to find the binary value of an 8 bit number in python.
n = 100
for i in range(8):
print((n>>i)%2)
@agocs
agocs / dumbclient.go
Last active August 29, 2015 13:56
A dumb http client that GETs a few different URLs.
package main
import "net/http"
import "fmt"
import "time"
type http_req struct {
req_time time.Duration
url string
status string
@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
(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 / 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
@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)"
}