Skip to content

Instantly share code, notes, and snippets.

View alexcp's full-sized avatar

Alexandre Croteau-Pothier alexcp

View GitHub Profile
@alexcp
alexcp / .gitconfig
Created May 6, 2012 11:52
My Git Configs
[user]
name = Alexandre Croteau-Pothier
email = alexcp.com@gmail.com
[color]
ui = true
[alias]
ci = commit
co = checkout
di = diff
aa = add --all
@alexcp
alexcp / redis-server
Created June 13, 2012 18:35
Redis-server init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@alexcp
alexcp / distance_of_time_in_days.rb
Created July 3, 2012 19:28
rails distance_of_time_in_days helper
def distance_of_time_in_days(from_time, to_time = 0)
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
from_time, to_time = to_time, from_time if from_time > to_time
distance_in_days = (((to_time - from_time).abs) / 86400).round
end
@alexcp
alexcp / nginx.conf
Created July 4, 2012 12:04
nginx configuration for a rails application
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
@alexcp
alexcp / rails-server
Created July 17, 2012 17:33
run rails server at startup
#!/bin/bash
#
set -e
. /lib/lsb/init-functions
start() {
echo "Starting the Rails Server.."
cd /home/operation/server/operation/current && bundle exec thin start -e production -s3
@alexcp
alexcp / convert_iso-8859-1_to_utf8.rb
Created September 25, 2012 01:02
I had to convert a bunch of file to utf8
Dir.foreach("src") do |filename|
unless filename == "." or filename == ".."
newfilename = "src/#{filename}.utf8"
filename = "src/#{filename}"
p `iconv -f iso-8859-1 -t utf-8 #{filename} > #{newfilename}`
end
end
@alexcp
alexcp / .zshrc
Created September 26, 2012 18:23
Some alias to control Rhythmbox from the command line
function rh() {
case $1 in
n)
rhythmbox-client --next
;;
pr)
rhythmbox-client --previous
;;
p)
rhythmbox-client --play-pause
@alexcp
alexcp / Commande.java
Created October 30, 2012 17:26
Refactoring example
package refactoring;
public class Commande {
public int id;
public int montant;
public int date;
public Commande(int id,int montant,int date){
this.id = id;
this.montant = montant;
@alexcp
alexcp / poweroff_in.rb
Created January 8, 2013 20:25
A script to poweroff a system after a delay.
#!/usr/bin/env ruby
MINUTE = 60
HOUR = 3600
def sudome
if ENV["USER"] != "root"
exec("sudo #{ENV['_']} #{ARGV.join(' ')}")
end
end
@alexcp
alexcp / delayed_paperclip.rb
Created February 20, 2013 21:26
Clear cache DelayJobPaperclip This is a monkey patch to clear a cache after an image is done processing.
module DelayedPaperclip
module Jobs
class DelayedJob
def perform
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name)
clear_cache(instance_klass, instance_id)
end
def clear_cache(instance_klass, instance_id)
begin