This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bag do | |
defstruct store: %{} | |
def new do | |
%Bag{} | |
end | |
def put(%Bag{store: store}, thing) do | |
%Bag{store: Map.update(store, thing, 1, &( &1 + 1))} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@proto_version "1.0" | |
def process_options(opts) do | |
ret = Enum.reduce(opts, [], fn | |
{:in, _}, ret -> ["-in"|ret] | |
{:err, :out}, ret -> ["-err", "out"|ret] | |
{:err, :err}, ret -> ["-err", "err"|ret] | |
{:dir, dir}, ret -> ["-dir", dir|ret] | |
_ -> ret | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Chat.Client do | |
def join(server) do | |
client_send server, :join | |
end | |
def say(server, message) do | |
client_send server, { :say, message } | |
end | |
def leave(server) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
@import url("http://github.com/simplegeo/polymaps/raw/v2.4.0/examples/example.css"); | |
html, body {height: 100%;} | |
svg {display: block;} | |
.layer circle {fill: #f00;stroke: #000;stroke-width: 2px;} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# producer | |
import zmq | |
context = zmq.Context() | |
socket = context.socket(zmq.PUB) | |
socket.setsockopt(zmq.LINGER, 0) # discard unsent messages on close | |
socket.connect('epgm://239.192.1.1:5000') | |
while True: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>ZWS Example</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script> | |
<script language='javascript'> | |
$(document).ready(function() { | |
var ws = new WebSocket("ws://localhost:9999/test"); | |
ws.onmessage = function(evt) { | |
$('#output').append(evt.data+'<br />'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "math" | |
func FastInvSqrt(x float32) float32 { | |
xhalf := float32(0.5) * x | |
i := math.Float32bits(x) | |
i = 0x5f3759df - i>>1 | |
x = math.Float32frombits(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
m "math" | |
) | |
const LIMIT = 100 | |
func main() { | |
// They don't recomend working with raw arrays, so use a slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "net" | |
import "bufio" | |
func main() { | |
conn, err := net.Dial("tcp", ":8080") | |
if err != nil { | |
println("There was an error:", err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "net/rpc" | |
type Region struct { | |
X, Y int | |
} | |
func main() { | |
client, _ := rpc.Dial("tcp", ":8080") |
OlderNewer