Some exercises from the Falsy Values workshops.
The good parts:
- HTTP server and client in same script
- Express cookies example
- Express routing example
- Express error handling
- Express middlewares example
- Simple HTTP proxy
anand@anand-laptop:~/node.native$ make | |
g++ -std=gnu++0x -g -O0 -I/home/anand/libuv/include -I/home/anand/http-parser -I. -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -o webclient webclient.cpp /home/anand/libuv/uv.a /home/anand/http-parser/http_parser.o -lrt -lm -lpthread | |
In file included from ./native/native.h:5, | |
from webclient.cpp:4: | |
./native/loop.h: In destructor ‘native::loop::~loop()’: | |
./native/loop.h:21: error: ‘nullptr’ was not declared in this scope | |
In file included from ./native/handle.h:5, | |
from ./native/tcp.h:5, | |
from ./native/native.h:7, | |
from webclient.cpp:4: |
#!/usr/bin/env node | |
CHANNEL = '#bozler' | |
MINIMUM_HUMAN_REACTION = 2 | |
DIALOGUE = | |
ACTIONS_IN_REPLY: [ | |
"I vote for pizza", | |
"Disregard that, I vote for pizza", | |
"Another vote for pizza!" |
/** | |
* Read Linux mouse(s) in node.js | |
* Author: Marc Loehe ([email protected]) | |
* | |
* Adapted from Tim Caswell's nice solution to read a linux joystick | |
* http://nodebits.org/linux-joystick | |
* https://github.com/nodebits/linux-joystick | |
*/ | |
var fs = require('fs'), |
Some exercises from the Falsy Values workshops.
The good parts:
var io = require('socket.io').listen(8000), | |
nicknames = {}; | |
io.sockets.on('connection', function (socket) { | |
socket.on('user message', function (msg) { | |
socket.broadcast.emit('user message', socket.nickname, msg); | |
}); | |
socket.on('nickname', function (nick, fn) { | |
if (nicknames[nick]) { |
// The code is based on a MongoDB database myhome with a typical record as below: | |
// { | |
// "rec_time" : ISODate("2013-11-25T16:53:43.808Z"), | |
// "rec_data" : { | |
// "power" : 372.201, | |
// "current" : 1.73, | |
// "voltage" : 221.678, | |
// }, | |
// "rec_asset" : { | |
// "name" : "Airconditioner", |
iex> i 'hello'
Term
population = for _ <- 1..100, do: for _ <- 1..1000, do: Enum.random(0..1) | |
# evaluate, selection, crossover and algorithm are anonymous functions. | |
evaluate = | |
fn population -> | |
# population is a list of lists [[1,1,0,0,1...1,1,0],[1,1,1,0,0...0,1,1]] 100 lists, 1000 bits each | |
Enum.sort_by(population, &Enum.sum/1, &>=/2) | |
# sort the list of lists by sum of bits so lists with higher number of one's are at the top. Mapper sums each row. Sorter is descending &>=/2 | |
# note the use of anonymous functions defined by &. |
I started with Elixir just a couple weeks after the switch from 1.4 to 1.5, so the bulk of online resources were out of date (or at least resulted in deprecation warnings). This guide is for defining Elixir 1.5 supervised modules.
It's not actually terribly complicated. It's just sometimes unclear from examples what's implemented by the language and what you actually have to implement yourself.
Say we want a supervision tree like this (where each atom is a process):
:a
/ \
defmodule Game do | |
use GenServer | |
def init(game_id) do | |
{:ok, %{game_id: game_id}} | |
end | |
def start_link(game_id) do | |
GenServer.start_link(__MODULE__, game_id, name: {:global, "game:#{game_id}"}) | |
end |