Skip to content

Instantly share code, notes, and snippets.

View franckverrot's full-sized avatar
📚
🥋

Franck Verrot franckverrot

📚
🥋
View GitHub Profile
@franckverrot
franckverrot / gist:4008539
Created November 3, 2012 20:05 — forked from chrismdp/gist:2768532
Paypal IPN integration in about 30 lines of Sinatra.
diff --git a/app/account.rb b/app/account.rb
index a108685..c89ad34 100644
--- a/app/account.rb
+++ b/app/account.rb
@@ -1,4 +1,22 @@
+require 'open-uri'
+
module Sol
+ class Url
+ def self.get(url)
@franckverrot
franckverrot / test_case.rb
Created September 14, 2012 14:26
Subclassing validators
module ActiveModel::Validations
class EmailWithMxValidator < ActiveModel::Validations::EmailValidator
def validate_each(*args)
super
check_for_mx(*args)
end
def check_for_mx(record, attribute, value)
record.errors.add attribute, 'MX not found' unless options[:mock_mx]
end
@franckverrot
franckverrot / gist:3435648
Created August 23, 2012 11:09 — forked from joelmoss/gist:2470666
Capistrano recipe for Puma start/stop/restarts
set :shared_children, shared_children << 'tmp/sockets'
namespace :deploy do
desc "Start the application"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{stage}.log 2>&1 &", :pty => false
end
desc "Stop the application"
task :stop, :roles => :app, :except => { :no_release => true } do
@franckverrot
franckverrot / output.txt
Created July 22, 2012 16:36
Ruby's parser activity
>> ruby -y -e 'def hello; world; end'
Starting parse
Entering state 0
Reducing stack by rule 1 (line 782):
-> $$ = nterm $@1 ()
Stack now 0
Entering state 2
Reading a token: Next token is token keyword_def ()
Shifting token keyword_def ()
Entering state 7
@franckverrot
franckverrot / test.rb
Created July 17, 2012 21:43
each and for loops
>> class Array
>> def each(&block)
>> reverse_each { |x| yield x }
>> end
>> end
=> nil
>> [1,2,3].each { |a| puts a }
3
2
1
@franckverrot
franckverrot / dtrace_rubymotion_repl
Created May 18, 2012 15:41 — forked from fpotter/dtrace_rubymotion_repl
DTrace script to observe UNIX socket traffic to/from a RubyMotion app
#!/usr/bin/env dtrace -s
/*
* DTrace script to observe UNIX socket reads/writes for RubyMotion apps running
* in the iOS Simulator.
*
* Usage: sudo dtrace_rubymotion_repl <pid of running RubyMotion iOS app>
*
*/
syscall::sendto:entry
Originally:
https://gist.github.com/7565976a89d5da1511ce
Hi Donald (and Martin),
Thanks for pinging me; it's nice to know Typesafe is keeping tabs on this, and I
appreciate the tone. This is a Yegge-long response, but given that you and
Martin are the two people best-situated to do anything about this, I'd rather
err on the side of giving you too much to think about. I realize I'm being very
critical of something in which you've invested a great deal (both financially
@franckverrot
franckverrot / stuff.rb
Created September 30, 2011 17:29
versioning an api
# routes, api_version is provided by the biceps gem
My::Application.routes.draw do
api_version 1 do
resources :users
end
api_version 2 do
resources :users
end
end
@franckverrot
franckverrot / Questions
Created August 13, 2011 12:53
Frozen Rails Give-away
Day job: Lead Dev at @Leadformance
Your Rails contributions (if any): 26 commits, [#84](http://contributors.rubyonrails.org/contributors/franck-verrot/commits)
What's your Ruby/Rail experience?: ± 4-5 years
How do you use GitHub?: Professionnal and Personal projects, both paid accounts. Lots of contributions too.
require 'rubygems'
require 'nokogiri'
require 'net/http'
require 'cgi'
res = Net::HTTP.get 'maps.google.co.uk','/maps/ms?ie=UTF8&oe=UTF8&msa=0&output=kml&msid=207192798388318292131.0004aa01af6748773e8f7'
doc = Nokogiri::XML(res)
placemarks = doc.css('Placemark')
puts "Name\tLatitude\tLongitude\tDescription"
placemarks.each do |placemark|
description = CGI::escapeHTML(placemark.css('description').first.content)