Skip to content

Instantly share code, notes, and snippets.

View erubboli's full-sized avatar

Enrico Rubboli erubboli

View GitHub Profile
parent.image.combine_options do |c|
c.fill hex_color
c.pointsize @obj.media.font_size
#c.font "#{RAILS_ROOT}/public/images/fonts/#{@obj.font.downcase}.ttf"
draw_params = ''
draw_params += "gravity #{gravity} " if gravity
#cmd += "scale #{scale},#{scale} " if scale
draw_params += "rotate #{degrees} " if degrees
##TODO: escape text characters!!
res = `file "#{ARGV[0]}"`
#puts "#{ARGV[0]} -> #{res}"
if res.match /Microsoft/
fn = ARGV[0].split('.')
fn[fn.size-1] = 'lit'
puts "mv \"#{ARGV[0]}\" \"#{fn.join('.')}\""
end
User.include_root_in_json = true
User.first.to_json(:only => [:screen_name,:id])
#=> {"user":{"id":1,"screen_name":"test"}}
User.include_root_in_json = false
User.first.to_json(:only => [:screen_name,:id])
#=> {"id":1,"screen_name":"test"}
#Zero-width positive lookbehind
"Enrico.Rubboli".match(/(?<=\.)(\w+)/)
# => #<MatchData "Rubboli" 1:"Rubboli">
#Zero-width negative lookbehind
"Enrico.Rubboli".match(/(?<!\.)(\w+)/)
# => #<MatchData "Enrico" 1:"Enrico">
re = /(?<nome>[\S]+)\s(?<cognome>[\S]+)/
result = re.match "Enrico Rubboli"
#=> #<MatchData "Enrico Rubboli" nome:"Enrico" cognome:"Rubboli">
result[:nome]
#=> "Enrico"
"Enrico Rubboli".sub re, '\k<cognome> \k<nome>'
#=> "Rubboli Enrico"
erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ ruby -rubygems clean.rb
erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$
erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ gem list sinatra
*** LOCAL GEMS ***
sinatra (1.0)
erubboli@kyoto:~/Progetti/clean-pm/new_design/clean_pm$ gem list rack
class ClientsController < ApplicationController
respond_to :html, :xml, :json
# [..] removed code [..]
# DELETE /clients/1
# DELETE /clients/1.xml
def destroy
@client = Client.find(params[:id])
module Leaf
# ..omitted code..
def total_leafs
1
end
end
module Composite
# .. omitted code..
def total_leafs
class City
include Composite
def initialize
@children = []
end
def count_children
@children.lenght
end
module Leaf
def land_size
@land_size || 0
end
end
module Composite
def append_child(child)
@children << child
end