Skip to content

Instantly share code, notes, and snippets.

Avatar

Bastien Gysler basgys

View GitHub Profile
View main.java
package ch.hegarc.ig.person;
import ch.hegarc.ig.person.business.Person;
public class Main {
public static void main(String[] args) {
Person p1 = new Person(1, "Bastien", "Gysler");
p1.print();
View person.java
package ch.hegarc.ig.person.business;
public class Person {
private Integer number;
private String firstName;
private String lastName;
public Person() {
this(null, null, null);
@basgys
basgys / gist:1482038
Created Dec 15, 2011
Trigger call to all passenger instances
View gist:1482038
#!/bin/bash
if [ -z $1 ]; then
echo "Usage : "$0" http://passenger_address"
else
echo "address to call: "$1
passenger-status --verbose | grep 'Password:' | cut -d ':' -f2 | while read line; do
echo "Calling : "$line # Passenger instance password
curl --header "X-Passenger-Connect-Password: "$line $1 > /dev/null 2>&1
@basgys
basgys / gist:2192992
Created Mar 25, 2012
Roman to Arabic number converter
View gist:2192992
input = "MCMXCIX" # 1999
# Roman to Arabic mapper
r2a = {"I" => 1, "V" => 5, "X" => 10, "L" => 50, "C" => 100, "D" => 500, "M" => 1000}
# Translate input to an array of arabic numbers
numbers = input.split(//).map {|c| r2a[c]}
count = numbers.count-1
# Compute result (more infos @ http://en.wikipedia.org/wiki/Roman_numerals)
@basgys
basgys / gist:2193099
Created Mar 25, 2012
Morse to english
View gist:2193099
map = {
'.-' => 'A',
'-...' => 'B',
'-.-.' => 'C',
'-..' => 'D',
'.' => 'E',
'..-.' => 'F',
'--.' => 'G',
'....' => 'H',
'..' => 'I',
@basgys
basgys / logs.rake
Created May 11, 2012
Rake task to tail multiple log files
View logs.rake
desc "Tail logs"
task :logs => :environment do |t, args|
log_files = ['log/searchd.log', 'log/searchd.query.log', 'log/resque.log', 'log/development.log']
system "tail -f -n 2 #{log_files.map {|f| "#{Rails.root}/#{f}"}.join(' ')} | perl -pe 's/^(==>)(.*)(<==)$/\e[1;33;40m$&\e[0m/g'"
end
@basgys
basgys / gist:2823166
Created May 29, 2012
Creates an accessible URL to your local machine via SSH
View gist:2823166
# config/tunnel.yml
public_host_username: username_ssh
public_host: my_public_domain
public_port: 8000
local_host: 0.0.0.0
local_port: 3000
# lib/tasks/tunnel.rake
namespace :tunnel do
desc "Start a ssh tunnel"
@basgys
basgys / gist:3181680
Last active Oct 7, 2015
Retryable transaction
View gist:3181680
class ActiveRecord::Base
# Retryable transaction
# =====================
#
# Author : Bastien Gysler (http://www.bastiengysler.com)
#
# ActiveRecord::Base.retryable_transaction(tries: 1, :when => ActiveRecord::RecordNotUnique) do |on|
# on.transaction do
# # transaction code here
@basgys
basgys / gist:3358471
Created Aug 15, 2012
Reload image on failure with exponential backoff
View gist:3358471
$("img.thumb").error(function() {
var path = $(this).data('src');
var img = $(this);
// Put back mock image
$(img).attr('src', 'http://placehold.it/56x56');
// Increment loading counter
var attempt = ($(img).data('attempt') || 0);
attempt++;
@basgys
basgys / gist:3482915
Created Aug 26, 2012
Transfer BLOB to Amazon S3 with Paperclip
View gist:3482915
# loop on something .each do |my_model|
blob_to_file(my_model.blob_image) do |image_file|
my_model.update_attributes(s3_image: image_file)
end
# end
def blob_to_file(blob)
tfile = Tempfile.new('blob_to_file')
tfile.write(blob.force_encoding("UTF-8"))
yield(tfile) if block_given?
You can’t perform that action at this time.