Skip to content

Instantly share code, notes, and snippets.

@aninder
aninder / gist:f7bdc8b3632451c64179a18d92a2cece
Created May 3, 2017 19:16
rupsy.ru goa current song details from discogs
require 'mechanize'
playlist = []
playlist_details = []
def find_more(song)
page=Mechanize.new.get("https://www.discogs.com/search/?q=#{song}")
links=page.search('#search_results .card').map{|f| f.search('a').first[:href]}
link = find_link(links)
if link
get_details("http://#{page.uri.host}#{link}")
else
@aninder
aninder / block_news_websites
Created February 2, 2017 02:27
scrape alexa for news sites links
require 'mechanize'
@all_links = []
m=Mechanize.new
p=m.get("http://www.alexa.com/topsites/category/News")
while true
puts "current page url #{p.uri}"
links=p.css('li.site-listing .desc-paragraph a').map { |l| l.text }
if(links.size ==0)
puts "no links found on current page #{p.uri}"
break
ActiveRecord cheat sheet / EXAMPLES
INSTALL
=======
$ gem install activerecord
in GEMFILE: gem ‘activerecord’
REQUIRE
=======
require ‘active_record’
@aninder
aninder / cookie.rb
Created March 25, 2013 01:17
cookie encrypt rails style
# extracted and prettified from the exploit gem metadata (https://gist.github.com/d891e876c53e55bf0920)
# context: https://news.ycombinator.com/item?id=5139720
require 'net/http'
require 'digest'
require 'openssl'
require 'base64'
aes = proc { |text|
aes_256 = OpenSSL::Cipher.new('aes-256-cbc')
aes_256.encrypt
aes_256.key = Digest::MD5.hexdigest(`uname -r`)
@aninder
aninder / change_ruby_system_version.sh
Created March 25, 2013 00:55
change ruby system version for those times
sudo ln -fs `which ruby` /usr/bin/ruby
sudo ln -fs `which erb` /usr/bin/erb
sudo ln -fs `which gem` /usr/bin/gem
sudo ln -fs `which irb` /usr/bin/irb
sudo ln -fs `which rake` /usr/bin/rake
sudo ln -fs `which rdoc` /usr/bin/rdoc
sudo ln -fs `which ri` /usr/bin/ri
sudo ln -fs `which testrb` /usr/bin/testrb
@aninder
aninder / .vimrc
Created March 25, 2013 00:49
my .vimrc
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'vim-ruby/vim-ruby'
Bundle 'skalnik/vim-vroom'
Bundle 'vim-scripts/L9'
Bundle 'vim-scripts/FuzzyFinder'
Bundle 'vim-scripts/rubycomplete.vim'
Bundle 'ervandew/supertab'
@aninder
aninder / .bash_profile
Last active December 15, 2015 08:49
my .bash_profile
#enable globals terminal colors
export CLICOLOR=1
export LSCOLORS=exfxcxdxbxegedabagacad
# terminal hist config
export HISTFILESIZE=100000
export HISTCONTROL=ignoredups
export HISTSIZE=20000
export HISTIGNORE="[ ]*:&:bg:fg:ls -l:ls -al:ls -la:ls1:lsa:lsr:gits:gits?"
@aninder
aninder / redflag.rb
Created March 5, 2013 12:05
fix for bug in "metaprogramming ruby" book code snippet on page 121 (creating DSL). It calls events of previous files again for each new file loaded and redflag2.rb is another way creating it.
lambda {
setups = []
events = {}
Kernel.send :define_method, :event do |name, &block|
events[name] = block
end
Kernel.send :define_method, :setup do |&block|
setups << block