This file contains 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
If you have a packaged ruby / rails / rvm / rbenv etc installed, get rid of them all, eg: | |
$ ruby --version | |
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux] | |
$ sudo apt-get remove ruby | |
if that didn't work, you can do: | |
$ aptitude purge ruby |
This file contains 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
To be able to utilize more than one key in your github environment on one computer, and assuming we have the 2 following keys: | |
~/.ssh/id_rsa_personal_key | |
~/.ssh/id_rsa_company_key | |
Create the file ~/.ssh/config with the follwoing content: | |
### Default (Personal) GitHub | |
Host github.com | |
HostName github.com | |
User git |
This file contains 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
alias glog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" | |
alias mycukes= 'RAILS_ENV="development" bundle exec cucumber' | |
alias myspecs= 'RAILS_ENV="development" bundle exec rspec spec' | |
alias vim='vim +NERDTree' | |
alias rspecc='clear && bundle exec rspec' | |
alias drspecc='clear && RAILS_ENV=development bundle exec rspec' | |
alias mygit='git config --global user.name "SOME-NAME-HERE" && git config --global user.email SOME-EMAIL-HERE && echo "************" && echo "switched git user name to:" && git config user.name && echo "and git user email to:" && git config user.email && echo "************"' |
This file contains 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 'resolv' | |
def validate_email_domain(email) | |
domain = email.match(/\@(.+)/)[1] | |
Resolv::DNS.open do |dns| | |
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) + dns.getresources(domain, Resolv::DNS::Resource::IN::A) | |
end | |
@mx.size > 0 ? true : errors.add(:email, "Invalid email id") | |
end |
This file contains 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
When installing passenger, Nginx, Ruby and Rails on Ubuntu 12.04 (without RVM/without rbenv): | |
First: installing Ruby (without RVM): | |
sudo apt-get update | |
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \ | |
rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \ | |
build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev | |
This file contains 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
Experimenting with Ruby 2.0 and DTrace scripts | |
I was very excited when I heard about the new Ruby 2.0 features. I am not going to delve into Ruby 2.0 features here, but I will talk about one feature I consider the best of Ruby 2: integration of DTrace. | |
I've never used DTrace before, much less I thought it can be used efficiently with Ruby the same way debugger is being used with ruby on rails. | |
DTrace has been for years the most famous tracing framework and now it's time to start using it with Ruby 2. So, after readings about DTrace, I tried to put it in action. I will be using Mac OS X 10.7. | |
Installing Ruby 2.0 |
This file contains 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 BinaryTree | |
class Node | |
attr_reader :word, :count, :left, :right | |
include Enumerable | |
def initialize(word) | |
@word, @count = word, 1 | |
end |
This file contains 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 | |
def aghyad_counting_sort | |
count = [] | |
a = self | |
puts a.inspect | |
m = a.first | |
a.each do |x| | |
m = x if m < x |
This file contains 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 | |
def aghyad_radix_sort | |
round = 0 | |
bucket = [[],[],[],[],[],[],[],[],[],[]] #bucket of 10 sub-arrays | |
self.each do |x| | |
bucket[x.to_s.split('')[-1*(round+1)].to_i] << x | |
end | |
a = bucket.flatten |
This file contains 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 | |
def aghyad_quick_sort | |
return self if length <= 1 | |
pivot = self[length/2] | |
return find_all { |i| i < pivot }.quick_sort + find_all { |i| i == pivot } + find_all { |i| i > pivot }.quick_sort |
NewerOlder