(C-x means ctrl+x, M-x means alt+x)
The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:
| def login(username, password) | |
| page.visit("http://#{username}:#{password}@#{page.driver.rack_server.host}:#{page.driver.rack_server.port}/") | |
| end |
| #! /usr/bin/env ruby | |
| # usage: | |
| # $ das_download.rb email password [download_directory] | |
| require 'mechanize' | |
| # gem 'mechanize-progressbar' | |
| email = ARGV[0] or raise('Please provide the email address for your account') | |
| password = ARGV[1] or raise('Please provide the password for your account') | |
| path = ARGV[2] || './' |
| class Lisp | |
| Fs = { | |
| :label => lambda {|name,value| Fs[name] = lambda { value } }, | |
| :car => lambda {|sexp| sexp.first }, | |
| :cdr => lambda {|sexp| sexp.slice(1, sexp.size) }, | |
| :cons => lambda {|head,tail| [head] + tail }, | |
| :atom => lambda {|sexp| !sexp.is_a?(Array) }, | |
| :eq => lambda {|a,b| a == b }, | |
| :if => lambda {|cnd,thn,els| cnd ? thn : els } | |
| } |
| require 'sinatra' | |
| require 'eventmachine' | |
| get '/' do | |
| stream(:keep_open) do |out| | |
| count = 0 | |
| timer = EM.add_periodic_timer(1) do | |
| out << "<p>ohai</p>\n" | |
| count += 1 | |
| if count == 10 |
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'rotp' | |
| require 'time' | |
| user = ARGV[0] | |
| secret = ARGV[1] | |
| abort unless user and secret | |
| trap("INT") do |
The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.
The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.
This gist is no longer valid. Please see Compass-Rails for instructions on how to install.
| require 'mechanize' | |
| @username = 'user@domain.com' | |
| @password = 'hi2u' | |
| @download_path = File.expand_path 'downloads' | |
| @wget_cookie = File.expand_path(File.dirname(__FILE__)) + '/wget-cookies.txt' | |
| unless File.directory? @download_path | |
| puts "@{download_path} doesn't exist!" | |
| exit |
| require 'ostruct' | |
| class OpenStruct | |
| DEPTH = 5 | |
| def self.deep(data, depth=0, &blck) | |
| return data if depth > DEPTH | |
| return data unless data.class == Hash | |
| hash = {} | |
| data.each do |key, value| | |
| key = blck.call(key) if block_given? |