Monday, July 18, 2011
Read input from console in Ruby
puts "Enter A"
a = gets.chomp
puts "Enter B"
b = gets.chomp
c = Integer(a) + Integer(b)
puts cyou can also pass the parameters through the command line. Command line arguments are stores in the array ARGV. so ARGV[0] is the first number and ARGV[1] the second number#!/usr/bin/ruby
first_number = ARGV[0].to_i
second_number = ARGV[1].to_i
puts first_number + second_number
and you call it like this% ./plus.rb 5 6
==> 11
Tuesday, June 21, 2011
Wednesday, June 15, 2011
Http delete with authentication ruby
require 'rubygems'
require "net/http"
Net::HTTP.start('www.example.com') {|http|
req = Net::HTTP::Delete.new("/api/products/#{product_id}")
req.basic_auth '#{user_name}', '#{password}'
response = http.request(req)
}
Monday, June 13, 2011
Install sendmail
I used:
It installed sendmail and by this command I could test it:
Result:
Code:
sudo apt-get install sendmail
Code:
sudo ps aux | grep sendmail
Quote:
| sudo ps aux | grep sendmail root 10366 0.0 0.7 8216 2020 ? Ss 09:50 0:00 sendmail: MTA: accepting connections 1000 10376 0.0 0.3 2880 796 pts/0 S+ 09:56 0:00 grep sendmail |
Monday, May 30, 2011
How to “flush tor circuit”
tor already switches the route roughly every 10 minutes. Sometimes you may need to get new tor ip or new route programatically. Here is how to do it in ruby.
What we are doing is "Send a SIGHUP to Tor. According to its man page this should make Tor fetch a new directory".
We can send a SIGHUP to tor get new route, thus a new tor ip.
require 'rubygems'
require 'sys/proctable'
include Sys
you can schedule this script to run periodically, say every 1 minutes. Then you will be getting new tor ip every minutes.
https://svn.torproject.org/svn/incognito/trunk/root_overlay/etc/NetworkManager/dispatcher.d/50-tor-sighup.sh
What we are doing is "Send a SIGHUP to Tor. According to its man page this should make Tor fetch a new directory".
We can send a SIGHUP to tor get new route, thus a new tor ip.
require 'rubygems'
require 'sys/proctable'
include Sys
Sys::ProcTable.ps.each { |ps|
if ps.name.downcase == "tor"
Process.kill('SIGHUP', ps.pid)
end
}
https://svn.torproject.org/svn/incognito/trunk/root_overlay/etc/NetworkManager/dispatcher.d/50-tor-sighup.sh
Kill process by his name ruby
require 'rubygems'
require 'sys/proctable'
include Sys
Sys::ProcTable.ps.each { |ps|
if ps.name.downcase == "process name"
Process.kill('KILL', ps.pid)
end
}
#Run script as root user
Subscribe to:
Posts (Atom)