Skip to content

Instantly share code, notes, and snippets.

View yannlugrin's full-sized avatar

Yann Lugrin yannlugrin

View GitHub Profile
def multi_replace(string, *rules)
scanning_pattern = Regexp.union(rules.map{|e| e.first} | [/./])
string.scan(scanning_pattern).map do |match|
rules.select{|e| match =~ e.first}.flatten.last || match
end.join
end
multi_replace("the first problem is not egal to second problem", [/first problem/, "older problem"], [/second problem/, "first problem"])
# >----------------------------[ Initial Setup ]------------------------------<
# generator initializer
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
# say methods
def say_step(name); say "\033[36m" + 'step'.rjust(10) + "\033[0m" + " Running #{name} step..." end
#!/bin/bash
#
# Set our bash prompt according to the branch/status of the current git
# repository.
#
# Forked from http://gist.github.com/31967
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
cloud-start -s config/clouds.rb
Starting cloud app (/home/yann/.ec2/testpoolparty)
0 running instances (1 - 1)
/usr/lib/ruby/gems/1.8/gems/grempe-amazon-ec2-0.3.8/lib/EC2.rb:261:in `ec2_error?': The key pair 'testpoolparty' does not exist (EC2::InvalidKeyPairNotFound)
from /usr/lib/ruby/gems/1.8/gems/grempe-amazon-ec2-0.3.8/lib/EC2.rb:199:in `make_request'
from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /usr/lib/ruby/gems/1.8/gems/grempe-amazon-ec2-0.3.8/lib/EC2.rb:173:in `make_request'
from /usr/lib/ruby/gems/1.8/gems/grempe-amazon-ec2-0.3.8/lib/EC2.rb:224:in `response_generator'
from /usr/lib/rub
require 'rake/packagetask'
Rake::PackageTask.new("myapp", "1.2.3") do |p|
p.need_tar_bz2 = true
p.package_files.include("README")
p.package_files.include("lib/**/*.rb")
end
Host srv1
Hostname srv1.client.fr
User root
ProxyCommand ssh firewall nc %h %p
Host srv2
Hostname srv2.client.fr
User root
ProxyCommand ssh firewall nc %h %p
class LifeGame
attr_reader :matrix
def initialize(string)
@matrix = string_to_matrix(string)
end
def iterate
old_matrix = Marshal.load(Marshal.dump(matrix))
matrix.each_index do |y|
Dir[Rails.root.join('**', '*.rb')].each do |f|
c = File.open(f).read
File.open(f, 'w').write("# encoding: UTF-8\n" + c)
end
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
@yannlugrin
yannlugrin / update-dnsimple.plist
Last active October 13, 2016 16:05
Update DNSimple record with current ip (dynamic DNS).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.yalty.update-dnsimple</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>/.../update-dnsimple.sh</string>