Skip to content

Instantly share code, notes, and snippets.

View ys's full-sized avatar
💭
Doing stuff with computers

Yannick Schutz ys

💭
Doing stuff with computers
View GitHub Profile
@ys
ys / gist:1171106
Created August 25, 2011 16:38
Hack embedly regexp return to accept all top level domains from google
#this is a simple hack that replace the .com by a regexp for all top level domains
regexp = 'http:\\/\\/maps\\.google\\.com\\/maps\\?.*|http:\\/\\/maps\\.google\\.com\\/\\?.*|http:\\/\\/maps\\.google\\.com\\/maps\\/ms\\?.*'
regexp.gsub!( 'com', '[a-z]{2,}')
@ys
ys / gist:1197294
Created September 6, 2011 11:13
Google maps regexp for ruby
(http|https):\\/\\/maps\\.google\\.(co\\.[a-z]{2}|com\\.[a-z]{2}|([a-z]{2,}))\\/maps\\?.*|(http|https):\\/\\/maps\\.google\\.(co\\.[a-z]{2}|com\\.[a-z]{2}|([a-z]{2,}))\\/\\?.*|(http|https):\\/\\/maps\\.google\\.(co\\.[a-z]{2}|com\\.[a-z]{2}|([a-z]{2,}))\\/maps\\/ms\\?.*
@ys
ys / gist:1247437
Created September 28, 2011 09:12
url ruby regexp
/\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\`!()\[\]{};:\'\".,<>?]))/i
@ys
ys / second test
Created July 19, 2012 07:11
Test article
jepogjep
--------
@ys
ys / heroku_migration.rb
Created August 2, 2012 11:52
Script for the migration of your Heroku app's database from Shared DB to Postgres 'dev' Plan
#!/usr/bin/env ruby
##
# This script migrates your Heroku app from a Shared DB to a Postgres `dev` Plan
#
# Usage:
# ruby heroku_migration.rb [apps_name(separated by spaces)]
# Example:
# $ ruby heroku_migration.rb app_1 app_2 app_3
#
@ys
ys / progress_indicators.rb
Created August 12, 2012 19:21 — forked from beanieboi/progress_indicators.rb
Ruby CLI Progress Indicators
# Terminal Progress Indicators. Four examples are included: percentage,
# spinner, progress bar, and combined. This script has been tested on
# Mac OS X 10.8 with Ruby 1.8.7, 1.9.1, 1.9.2, and 1.9.3
class Spinner
include Enumerable
def each
loop do
yield '|'
yield '/'
@ys
ys / My_first_thought.rb
Created August 23, 2012 11:11
How would you align these kind of things in Ruby?
local_var.method_with_hash_and_block(
mandatory_param,
option_1: a,
option_2: blabla,
option_3: blablablablablabla,
option_4: bblablablablablablablabla,
option_5: bblablablabla,
) do |v|
d = v.bla
e = v.bla
@ys
ys / ProjectController.rb
Created August 29, 2012 12:29
Service Layer kind of
class ProjectController < ApplicationController
def create
service_layer.save(project)
end
private
def service_layer
@service_layer ||= ServiceLayer.instance
end
@ys
ys / stored_procedure_service.rb
Created September 13, 2012 12:50
Execute stored procedure
class StoredProcedureService
def self.instance
@instance ||= StoredProcedureService.new
end
def execute(name, *args)
results = []
begin
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row|
@ys
ys / gist:3901406
Created October 16, 2012 19:26
chekku tests for fun
describe '.check_version' do
it 'should be ~> 5.5 for mysql' do
definition.check_version('~> 5.5').should be_true
end
it 'should be >= 5.3 for mysql' do
definition.check_version('>= 5.3').should be_true
end
it 'should be <= 5.6 for mysql' do
definition.check_version('<= 5.6').should be_true
end