Skip to content

Instantly share code, notes, and snippets.

View solisoft's full-sized avatar
🏠
Working from home

BONNAURE Olivier solisoft

🏠
Working from home
View GitHub Profile
class Array
# Split an array with defined size
# [1,2,3,4,5,6,7].split_by_size(2) #=> [[1, 2], [3,4], [5,6], [7]]
def split_by_size(size = 500)
tmp = []
newarray = []
self.each_with_index do |a, i|
if i % size == 0
unless tmp.blank?
newarray.push tmp + [a]
environment = "www"
mongrel_rails = "/usr/local/bin/mongrel_rails"
result = `cd #{environment}/current && #{mongrel_rails} cluster::status`.split("\n")
result = result.map{|r| r unless r == ""}.compact
check = result.map{|r| r =~ /^found/}.compact
pids = []
ports= []
result.each do |r|
pid = r.scan /pid (\d+)$/
# Install Erlang R12B and Couchdb
sudo apt-get install automake autoconf libtool subversion-tools help2man
sudo apt-get install build-essential erlang libicu38 libicu-dev libcurl4-gnutls-dev
sudo apt-get install libreadline5-dev checkinstall libmozjs-dev wget
sudo apt-get build-dep erlang
sudo apt-get install java-gcj-compat java-gcj-compat-dev
wget http://www.erlang.org/download/otp_src_R12B-4.tar.gz
tar -xf otp_src_R12B-4.tar.gz
cd otp_src_R12B-4
@solisoft
solisoft / mongodb
Created September 10, 2009 07:47
mongodb start script
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mongodb startup script
# Description: Mongodb start stop daemon sends SIGINT to terminate
# say man signal to see details
# Please check the startup params and replication options
# Ubuntu 32bits Nginx / Passenger / Ruby on Rails
apt-get update
apt-get upgrade
aptitude install build-essential ruby1.8 ruby1.8-dev imagemagick libmagick++9-dev rdoc libopenssl-ruby libxslt-dev libssl-dev
aptitude install make g++ openssl libcurl4-openssl-dev sendmail git-core
aptitude install fail2ban chkrootkit mailx
mkdir /home/src
# FTP authentification -- see OVH FTP Backup guides
server, user, pass = ["your_server", "your_user", "your_pass"]
keep = 15 # keep last 15 days
what_to_save = ["/home/save/*.tar.gz"] # no subdirs
class SaveFtp
require "net/ftp"
require "time"
# Extend MongoMapper Objects
# Usage :
# -------
# MyModel.search(["title", "text"], "my search", { :flag => nil }, { :limit => 10 })
module MongoMapper
module Document
module ClassMethods
def search(fields, words, conditions = {}, options = {})
filters = []
module MongoMapper
module Plugins
module Querying
module ClassMethods
def search(fields, words, conditions = {}, options = {})
filters = []
fields = fields.split(",").map {|l| l.strip } if fields.class.to_s == "String"
words.split(" ").each do |word|
ftemp = []
fields.each {|field| ftemp << "(String(this.#{field}).replace('null', '').match(/#{word}/i))" }
@solisoft
solisoft / gist:1064455
Created July 5, 2011 08:12
Ubuntu 10.04 + mongodb + nodejs + nginx + ruby 1.9.2
Cloud
=====
apt-get update ; apt-get upgrade
apt-get install ruby rubygems curl git-core build-essential libssl-dev libcurl4-openssl-dev
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
# Node.js
curl -O http://nodejs.org/dist/node-v0.4.9.tar.gz
tar -xf node-v0.4.9.tar.gz
cd node-v0.4.9
@solisoft
solisoft / rs.rb
Created August 1, 2011 16:30
Connexion au ReplicaSet avec Ruby
require "rubygems"
require "mongo" # gem install mongo
include Mongo
@connection = ReplSetConnection.new(['mongo1.mongood.com', 27017], ['mongo2.mongood.com', 27017], ['mongo3.mongood.com', 27017], :read_secondary => true)
@connection.add_auth("<base>", "<login>", "<motdepasse>") # Modifiez avec vos informations
@connection.apply_saved_authentication()
@db = @connection['<base>'] # Modifiez avec le nom de votre base de données