Skip to content

Instantly share code, notes, and snippets.

View gerhard's full-sized avatar

Gerhard Lazu gerhard

View GitHub Profile
@gerhard
gerhard / serenade.js.error.sh
Created February 1, 2012 09:40
serenade.js
Calista ➜ serenade.js git:(master) ./node_modules/coffee-script/bin/coffee web.coffee
Listening on 3000
127.0.0.1 - - [Wed, 01 Feb 2012 09:38:59 GMT] "GET / HTTP/1.1" 200 511 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11"
127.0.0.1 - - [Wed, 01 Feb 2012 09:38:59 GMT] "GET /favicon.ico HTTP/1.1" 200 182 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11"
127.0.0.1 - - [Wed, 01 Feb 2012 09:39:01 GMT] "GET /advanced.coffee HTTP/1.1" 200 190 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11"
Error: EBADF, Bad file descriptor './extras/serenade.js'
at Object.openSync (fs.js:221:18)
at Object.readFileSync (fs.js:112:15)
at /Users/gerhard/code/serenade.js/web.coffee:49:29
at callbacks (/Users/gerhard/code/serenade.js/node_modules/express/lib/router/index.js
@gerhard
gerhard / gist:1707291
Created January 30, 2012 22:44
This is how New Relic follows up on their trials
This was sent by a New Relic account executive to one of my co-workers as a
follow-up to the trial. Generally speaking, it's a good idea to not patronise
your potential customers. There's no room for more than a single dot in a
business e-mail. Use a spell-checker for your e-mails if you can't spell. Write
in clear English. What do you think?
Hello <name>,
@gerhard
gerhard / gist:1669340
Created January 24, 2012 09:56
Exposing Recipe DSL to a Library
# cookbooks/website/libraries/plain.rb
#
module Website
class Plain
attr_reader :resource, :node
def initialize(resource, node)
@resource, @node = resource, node
end
@gerhard
gerhard / rvm_providers_user.rb
Created January 9, 2012 21:57
Extending chef providers
include Chef::Provider::SystemUser
action :create do
# super ?
# rvm specific work...
end
09/01/2012 21:02:12.000 kernel: MacAuthEvent en1 Auth result for: 00:50:7f:a2:a3:78 MAC AUTH succeeded
09/01/2012 21:02:12.000 kernel: wlEvent: en1 en1 Link UP
09/01/2012 21:02:12.000 kernel: en1: BSSID changed to 00:50:7f:a2:a3:78
09/01/2012 21:02:13.000 kernel: AirPort: RSN handshake complete on en1
09/01/2012 21:08:21.309 SystemUIServer: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.
09/01/2012 21:08:21.310 Twitter: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.
09/01/2012 21:08:36.000 kernel: MacAuthEvent en1 Auth result for: 00:50:7f:a2:a3:78 MAC AUTH succeeded
09/01/2012 21:08:36.000 kernel: wlEvent: en1 en1 Link UP
09/01/2012 21:08:36.000 kernel: en1: BSSID changed to 00:50:7f:a2:a3:78

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource:

Calista ➜ /tmp dd if=/dev/zero of=ddfile.big bs=1048576 count=4k
4096+0 records in
4096+0 records out
4294967296 bytes transferred in 19.222645 secs (223432690 bytes/sec)
Calista ➜ /tmp dd if=ddfile.big of=/dev/null
8388608+0 records in
8388608+0 records out
4294967296 bytes transferred in 33.803309 secs (127057600 bytes/sec)
direct = 0
while ((command | getline response) > 0) {
if (response ~ /direct/) {
direct++
} else if (direct != 0) {
if (direct == 2) {
direct = 0
DIRECT += strtonum(response)
} else {
direct++
name "router"
description "Ganglia gmond, only needs to report"
run_list "role[base]",
"recipe[bootstrap]",
"recipe[ganglia]",
"recipe[ganglia::python_modules]",
"recipe[ganglia::gmetad]",
"recipe[ganglia::web2]"
ddefault_attributes(
Calista ➜ local git:(master) rabbitmq-server
Activating RabbitMQ plugins ...
0 plugins activated:
+---+ +---+
| | | |
| | | |
| | | |
| +---+ +-------+