This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+)$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer