Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
<!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>
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
@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)
@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 / gist:7785628
Last active December 30, 2015 05:49 — forked from Andy-Richards/gist:7785272
defmodule A do
defmacro __before_compile__(_env) do
funs = Enum.map([:a, :b], fn(name) ->
quote do
def unquote(name)(), do: unquote(name)
end
end)
quote do
unquote_splicing(funs)
@alco
alco / macro.ex
Last active December 26, 2015 07:59 — forked from 5HT/gist:7117914
# If you need to invoke a macro at the top level of a module definition (i.e. not inside a "def"),
# extract it into another module
defmodule N2OMACRO do
defmacro element_base(mod) do quote do [ancestor: :element, module: unquote(mod), id: :undefined,
actions: [], class: [], style: [], source: [],
data_fields: [], aria_states: [], body: [], role: [],
tabindex: 0, show_if: false, html_tag: :undefined, title: []] end end
end
@alco
alco / crays.cpp
Created September 24, 2013 14:03 — forked from kidoman/crays.cpp
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef int i; //Save space by using 'i' instead of 'int'
typedef float f; //Save even more space by using 'f' instead of 'float'
//Define a vector class with constructor and operator: 'v'
struct v {
f x,y,z; // Vector has three float attributes.
@alco
alco / gist:6353899
Last active December 21, 2015 19:20 — forked from chrismccord/gist:6349128
defrecord User, email: nil
defimpl Access, for: User do
def access(record, attr) do
index = record.__record__(:index, attr)
elem(record, index)
end
end
user = User.new(email: "foo@bar.com")
@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")
@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)