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
;; Add this to ~/.emacs | |
;; Missing from ruby-mode.el, see https://groups.google.com/group/emacs-on-rails/msg/565fba8263233c28 | |
(defun ruby-insert-end () | |
"Insert \"end\" at point and reindent current line." | |
(interactive) | |
(insert "end") | |
(ruby-indent-line t) | |
(end-of-line)) |
(ns demo.gemstoclojure | |
(:use ring.adapter.jetty) | |
(:use clojure.contrib.io) | |
(:use clojure.contrib.classpath)) | |
(import '(org.jruby.embed ScriptingContainer LocalContextScope)) | |
(def c (ScriptingContainer. LocalContextScope/THREADSAFE)) | |
(println (classpath)) | |
(println (pwd)) |
:~$ rvm use jruby | |
Using /home/saito/.rvm/gems/jruby-1.6.2 | |
:~$ gem i mvn:org.slf4j:slf4j-simple | |
Successfully installed mvn:org.slf4j:slf4j-api-1.6.2-java | |
Successfully installed mvn:org.slf4j:slf4j-simple-1.6.2-java |
# Rails 3 Config | |
# | |
# In: config/application.yml | |
# | |
# development: | |
# github: | |
# key: test | |
# secret: verysecret-dev | |
# production: | |
# github: |
$pid = fork | |
if $pid == nil | |
exec "./srvd/redis-server ./srvd/redis.conf" | |
end | |
sleep 5 | |
Process.kill(:$pid) |
module ::Guard | |
class Redis < Guard | |
def start | |
puts "Starting Redis on port #{port}" | |
IO.popen("#{executable} -", 'w+') do |server| | |
server.write(config) | |
server.close_write | |
end | |
puts "Redis is running with PID #{pid}" | |
$?.success? |
#!/usr/bin/env sh | |
# Copy public key to authorized_keys of a remote machine | |
if [ -z $1 ] || [ -z $2 ];then | |
echo "Usage" | |
echo "ssh-copy-id hostname /path/to/public/key" | |
exit | |
fi | |
KEYCODE=`cat $2` | |
ssh -q $1 "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys" |
# autoload concerns | |
module YourApp | |
class Application < Rails::Application | |
config.autoload_paths += %W( | |
#{config.root}/app/controllers/concerns | |
#{config.root}/app/models/concerns | |
) | |
end | |
end |
require 'logger' | |
class String | |
LOGGER = Logger.new($stderr) | |
def -@; LOGGER.info self; end | |
end | |
# Extracted earlier, hardcoded for speed | |
ENTITIES = %w(I-ORG O I-MISC I-PER I-LOC B-LOC B-MISC MO B-ORG) |
Some exercises from the Falsy Values workshops.
The good parts: