Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
module Communicator
class Command
def initialize(cmd)
@cmd = cmd
end
def execute(params = [])
`#{@cmd} #{params.join(' ')}`
end
end
require 'communicator'
include Communicator
ls = Command.new('ls')
ls.execute().each do |l|
puts l
end
p ls.execute(['-l'])
#!/usr/bin/env ruby
require 'fileutils'
=begin
to add vhost we do the following:
1- create directory
2- create configration file
3- enable vhost with a2ensite
4- reloading apache
#!/bin/ruby
nodes = [ { :name => "station1",
:services => { :ssh => { :listenaddress => "192.168.0.254",
:sshd_port => "2222"
}
}
},
require 'logger'
require 'rubygems'
require 'wirble'
require 'pp'
Wirble.init
Wirble.colorize
# require 'utility_belt'
if ENV.include?('RAILS_ENV')&& !Object.const_defined?('RAILS_DEFAULT_LOGGER')
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
@MaherSaif
MaherSaif / kata.rb
Created October 15, 2010 19:56 — forked from notahat/kata.rb
def kata(digits = [], has_pair = false)
if digits.inject {|sum, digit| sum + digit } == 15
has_pair ? [digits] : []
else
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true)
end
end
end
@MaherSaif
MaherSaif / kata.rb
Created October 15, 2010 19:56 — forked from notahat/kata.rb
def kata(digits = [], sum = 0, has_pair = false)
if sum < 15
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result +
kata(digits + [digit], sum + digit, has_pair) +
kata(digits + [digit, digit], sum + digit + digit, true)
end
elsif sum == 15 && has_pair
[digits]
server {
access_log /opt/nginx/logs/test_server.access.log main buffer=32k;
error_log /opt/nginx/logs/test_server.error.log info;
expires 6h;
listen 2300 default rcvbuf=64k backlog=128;
root /opt/apps/test_server/current/public;
server_name test_server.com www.test_server.com;
passenger_enabled on;
}
pid /opt/nginx/logs/nginx.pid;
# Run as the nginx user
user nginx nginx;
worker_processes 2;
error_log /opt/nginx/logs/error.log notice;
events {
worker_connections 1024;
use epoll;
@MaherSaif
MaherSaif / webapp.rb
Created November 23, 2010 22:49 — forked from igrigorik/webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end