Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / bag.ex
Last active August 29, 2015 14:01 — forked from knewter/word_stats_test.exs
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
@alco
alco / exercise.exs
Last active August 29, 2015 14:02 — forked from josevalim/exercise.exs
@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)
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
<!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>
@alco
alco / producer_multicast.py
Created April 24, 2012 08:25 — forked from saghul/producer_multicast.py
ZMQ multicast producer example
# 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:
@alco
alco / index.html
Created April 24, 2012 08:25 — forked from saghul/index.html
Simple HTML WebSocket client for the ZeroMQ gateway
<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 />');
@alco
alco / gist:3731366
Created September 16, 2012 07:03 — forked from james4k/gist:3730918
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)
package main
import (
m "math"
)
const LIMIT = 100
func main() {
// They don't recomend working with raw arrays, so use a slice
@alco
alco / client.go
Last active December 16, 2015 15:29 — forked from gmile/client.go
package main
import "net"
import "bufio"
func main() {
conn, err := net.Dial("tcp", ":8080")
if err != nil {
println("There was an error:", err)
@alco
alco / client.go
Last active December 16, 2015 16:49 — forked from gmile/client.go
package main
import "net/rpc"
type Region struct {
X, Y int
}
func main() {
client, _ := rpc.Dial("tcp", ":8080")