Skip to content

Instantly share code, notes, and snippets.

View hosh's full-sized avatar

Ho-Sheng Hsiao hosh

  • Remine
  • Phoenix, AZ
View GitHub Profile
@hosh
hosh / some_api.rb
Last active August 29, 2015 14:16
A neat thing you can do with Intermodal + functional Ruby
require 'rlet/functional'
module SomeApi
module API
class V1_0 < Intermodal::API
using RLet::Functional
self.default_per_page = 25
map_data do
require 'pp'
class HeighwayDragon
class Turtle
attr_accessor :x, :y, :direction, :dragon, :step
def initialize
@x = 0
@y = 0
@direction = :N
@step = 0
end
def blah(x)
return 1 if x == 1 # Special case
return nil unless x > 1
y = x.to_i/10.0
z = 10**(Math.log10(y).ceil)
return (z/2).ceil if y <= z/2
return z
end
# Does this work?
#!/bin/sh
# README:
# Having had to use MacOSX, I still prefer using Visor + MacVIM. However, Visor uses Terminal.app.
# Unlike iTerm, Terminal does not support changing the name of the tab. There are two hacks out in
# the wild:
# (1) Run a background process with the name you want to use
# (2) Hardlink ssh, then call that hardlinked ssh
#
# This script automates the method (2), however, instead of using ssh, we use screen. This has the
# additional bonus of being able to access screen's ability to detach sessions.
task :after_update_code, :roles => [:db] do
run <<-EOF
cd #{release_path} &&
rm -fr db && ln -ns #{shared_path}/db db &&
cp config/database.yml.production config/database.yml &&
git submodule update --init
EOF
end
# Package for inspecting descendents of ActiveRecord and ActionMailer in a simple tree form.
# Works with Rails 2.3.5
# INSTALL
# Drop this into lib/tasks
# USAGE
# rake stats:models
# rake stats:mailers
I don't need this right now but I will need them for this current project over the summer.
Here's what I'm thinking:
- Build it on top of RESTClient
- On the surface, it should be compatible with ActiveResource
- Maybe take advantage of .to_model interface with ActiveORM in Rails3
- Use Addressable as Jesse suggests, to construct the URL
- Defaults to Yajl, switchable to JSON gem
- Defaults to Nokogiri + libxml2
- Pluggable backend: Net::HTTP or EventMachine's HTTP
# Mock, this isn't real
$ rake db:schema:version
-> saves to db/schema/schema-20100403232.rb
# Now you don't have the problem with the timestamp embedded
# into the db/schema.rb every time you do a db:schema:dump
#!/usr/bin/env ruby
def hello_loop(names)
names.each do |name|
puts "Hello #{name}"
end
end
hello_loop(%w(
Gafitescu
# app/concerns/let.rb
# Ripped from Rspec 2.0 beta.12
# I've found it so useful in Rspec, I made it into a module. Controller code with shared
# code seem to have a lot of use for this. For example, in inherited_resources, you would
# typically override model, parent, etc. to configure it. You would typically memomize it
# as well. With this, you can use a more compact let() syntax.
# (Note: This code will only work in Rails 3)
module Let