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
# coding=utf8 | |
# Copyright (C) 2011 Saúl Ibarra Corretgé <saghul@gmail.com> | |
# | |
import hashlib | |
import os | |
import re | |
import socket | |
import struct |
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: "foo@bar.com") |
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) |
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 "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
<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 />'); |
NewerOlder