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
@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
# 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
@solisoft
solisoft / image_processing.rb
Created September 8, 2011 06:24
image processing
require 'base64'
require 'uri'
require 'net/http'
if ARGV[0]
data = Base64.encode64(IO.read(ARGV[0])) rescue nil
unless data.nil?
# First Resize to 640x>
options = "-resize '640x>'"
res = Net::HTTP.post_form(URI.parse('http://img.idfuze.com/api'), {'picture' => data, 'options' => options, 'output' => "o.jpg" })
@solisoft
solisoft / rs.php
Created November 20, 2011 02:37
PHP replicaSet connection
<?php
// connecting to mongood.com cluster
$m = new Mongo("mongodb://mongo1.mongood.com:27017,mongo2.mongood.com:27017,mongo3.mongood.com:27017", array("replicaSet" => "cluster"));
var_dump($m);
$db = $m->selectDB('my_database');
$db->authenticate("my_login", "my_password");
$collection = new MongoCollection($db, 'my_collection');
$cursor = $collection->find();
foreach ($cursor as $doc) {
var_dump($doc);
@solisoft
solisoft / chatify.html
Created December 4, 2011 07:01
chatify usage
<link rel="stylesheet" href="chatify.css" type="text/css" media="screen">
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="underscore.js"></script>
<script src="jQuery.jPlayer.2.1.0/jquery.jplayer.min.js"></script>
<script src="http://servername:8080/socket.io/socket.io.js"></script>
<script src="jquery-chatify.js"></script>
<script>
var login = "Teacher";
$(function() {
$("#chat").chatify({ login: login, rooms: ["teacher-student1", "teacher-student2"]});
@solisoft
solisoft / server.sh
Created December 4, 2011 07:14
server configuration
cd /path/to/jquery-chatify.js
npm install
node server.js