$ rails g model User
belongs_to
has_one
require 'faraday' | |
require 'net/http' | |
require 'pp' | |
# Repos: | |
# https://github.com/technoweenie/faraday | |
# https://github.com/pengwynn/faraday_middleware | |
# Blog posts: | |
# http://adventuresincoding.com/2010/09/writing-modular-http-client-code-with-faraday |
# See http://rubydoc.info/gems/will_paginate/2.3.15/WillPaginate/Collection.create | |
# See https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/array.rb | |
# Do in application_helper.rb or application_controller.rb (or somewhere else application-wide) | |
require 'will_paginate/collection' | |
Array.class_eval do | |
def paginate(options = {}) | |
raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options | |
WillPaginate::Collection.create( | |
options[:page] || 1, |
require 'rubygems' | |
require 'zip/zip' | |
def unzip_file (file, destination) | |
Zip::ZipFile.open(file) { |zip_file| | |
zip_file.each { |f| | |
f_path=File.join(destination, f.name) | |
FileUtils.mkdir_p(File.dirname(f_path)) | |
zip_file.extract(f, f_path) unless File.exist?(f_path) | |
} |
module ApiPageHelper | |
PAGINATE_OPTIONS = { | |
:default_page_size => 10 | |
} | |
PAGINATE_PARAMS = [ "page", "offset", "size" ] | |
def paginate(coll, options = {}) | |
options = PAGINATE_OPTIONS.merge(options) | |
if params[:page] | |
page = params[:page].to_i | |
size = (params[:size] || options[:default_page_size]).to_i |
// ==UserScript== | |
// @id acegist | |
// @name ACEgist | |
// @author Antoine BERNIER (abernier) | |
// @version 0.1.2 | |
// @description ACE editor in your gists | |
// @match https://gist.github.com/gists/*/edit | |
// ==/UserScript== | |
(function (d, cb) { |
location /resize { | |
alias /tmp/nginx/resize; | |
set $width 150; | |
set $height 100; | |
set $dimens ""; | |
if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) { | |
set $width $1; | |
set $height $2; | |
set $image_path $3; |
/(?<area_code>\d{3}) (?<local_number>\d{3}-\d{4})/ =~ "123 456-7890" | |
local_variables # => [:area_code, :local_number] | |
area_code # => "123" | |
local_number # => "456-7890" | |
ENV['RUBY_VERSION'] # => "ruby-1.9.3-p0" |
/* | |
* nginx configuration snippet for dynamic image manipulation using HttpImageFilterModule | |
* | |
* URL example: http://www.yourserver.com/imgresize/250-100-0/demo.jpg | |
* Parameters are width-height-rotation | |
* You need to compile nginx with --with-http_image_filter_module | |
* More information at http://wiki.nginx.org/HttpImageFilterModule | |
*/ | |
location ~/imgresize/(?P<width>[0-9]+)-(?P<height>[0-9]+)-(?P<rotate>[0-9]+)/(?P<filename>.+)$ { | |
rewrite /imgresize/[0-9]+-[0-9]+-[0-9]+/(.+)$ /images/$1 break; |
#!/usr/bin/env ruby | |
# this is a test of ruby-processing (https://github.com/jashkenas/ruby-processing) with video capture | |
# use "rp5 unpack library" at a command line to install the video library, among others | |
# tested with Ruby 1.9.2 on OSX with built in web cam | |
class VideoCaptureTest < Processing::App |