Skip to content

Instantly share code, notes, and snippets.

View guilherme's full-sized avatar
🤔

Guilherme Campos guilherme

🤔
View GitHub Profile
#!/bin/bash
ifconfig eth0 192.168.0.65/24 up
hostname pc2
/etc/rc.d/rc.drbd stop
modprobe drbd
dd if=/dev/zero bs=1M of=/dev/sdb1 count=1
curl https://gist.github.com/raw/2240291/addabf203f711db2c23fcd717a821321cad64e11/drbd.conf > /etc/drbd.conf
drbdadm create-md r0
drbdadm up r0
/etc/rc.d/rc.drbd start
@guilherme
guilherme / drdb_setup_master.sh
Created March 29, 2012 17:32
setup drbd master
#!/bin/bash
ifconfig eth0 192.168.0.35/24 up
hostname pc1
/etc/rc.d/rc.drbd stop
modprobe drbd
dd if=/dev/zero bs=1M of=/dev/sdb1 count=1
curl https://gist.github.com/raw/2240291/addabf203f711db2c23fcd717a821321cad64e11/drbd.conf > /etc/drbd.conf
drbdadm create-md r0
drbdadm up r0
drdbadm -- -o primary r0
include "/etc/drbd.d/global_common.conf";
resource r0 {
protocol C;
syncer {
rate 100M;
}
on pc1 {
device /dev/drbd1;
disk /dev/sdb1;
@guilherme
guilherme / fuck_msnbot.sh
Created March 22, 2012 12:52
aliviando o trafego da aplicação
#!/bin/sh
iptables -A INPUT -s 64.4.0.0/18 -p tcp -j DROP
iptables -A INPUT -s 65.52.0.0/14 -p tcp -j DROP
iptables -A INPUT -s 157.56.0.0/14 -p tcp -j DROP
iptables -A INPUT -s 157.60.0.0/16 -p tcp -j DROP
iptables -A INPUT -s 157.54.0.0/15 -p tcp -j DROP
iptables -A INPUT -s 207.46.0.0/16 -p tcp -j DROP
@guilherme
guilherme / gist:1989028
Created March 6, 2012 21:19
schedule.rb
# encoding : utf-8
class Schedule
TITLE = /([\p{Word} ]*)/
TIME_ADVERB = /(hoje|amanhã|depois de amanhã|semana que vem)/i
DAY_OF_WEEK = /(Domingo|Segunda|Terca|Quarta|Quinta|Sexta|Sabado|Dom|Seg|Ter|Qua|Qui|Sex|Sab)/
MINUTE = /([0-6][0-9])/
HOUR = /([0-2][0-9])/
@guilherme
guilherme / gist:1988720
Created March 6, 2012 20:13
Regexp ruby
1.9.2p290 :013 > "abcd test 123".match(/(?<title>([\p{Word} ]*))((?<test>test 123)|(?<test>123))/)
=> #<MatchData "abcd test 123" title:"abcd test " test:nil test:"123">
# REGEXP Y U NO MATCH THE ENTIRE STRING (test 123) ?
1.9.2p290 :018 > "abcd test 123".match(/([\p{Word} ]*)(test 123|123)/)
=> #<MatchData "abcd test 123" 1:"abcd test " 2:"123">
@guilherme
guilherme / gist:1747696
Created February 5, 2012 19:53
bookmailer test.
# application.rb
to(:tag, "put") do
subject = request.subject
title,url = subject.split(' ').map { |x| x.strip }
note = request.body
params = { :title => title, :url => url, :note => note }
bookmarks.add_bookmark(params)
respond :subject => "Bookmark saved #{title}"
end
@guilherme
guilherme / gist:1734930
Created February 4, 2012 03:21
simpler extension to newman applications
module Newman
module ActAsPingPong
def self.extended(klass)
klass.instance_eval do
to(:tag, "ping") do
respond(:subject => "pong")
end
end
end
end
@guilherme
guilherme / gist:1732428
Created February 3, 2012 20:48
functional error
# acid_tests.rb
# Add another case:
# as you may see it not raises a logical error. it accepts multiple applications
describe "Two applications on the same server" do
it "emulates a simple mail list and respond to ping pongs" do
mailer.deliver_message(:from => "tester@test.com",
:to => "test@test.com")
server.tick([Newman::Examples::SimpleList,Newman::Examples::PingPong])
@guilherme
guilherme / refresh_in_batches.rb
Created January 24, 2012 20:52
monkey patch for a more light approach to rake paperclip:refresh
module Paperclip
class << self
def each_instance_with_attachment(klass, name)
unscope_method = class_for(klass).respond_to?(:unscoped) ? :unscoped : :with_exclusive_scope
class_for(klass).send(unscope_method) do
class_for(klass).find_in_batches(:batch_size => 20) do |instance_batches|
instance_batches.each do |instance|
yield(instance) if instance.send(:"#{name}?")
end
end