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
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
@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 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
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) |
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
# 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 |
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
#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. |
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
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: "[email protected]") |
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") |
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) |
NewerOlder