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
# encoding: UTF-8 | |
require 'nokogiri' | |
require 'open-uri' | |
doc = Nokogiri::XML(open('https://www.jogossantacasa.pt/web/SCRss/rssFeedCartRes')) | |
@items = doc.xpath('//item').map do |i| | |
{'title' => i.xpath('title').inner_text, 'description' => i.xpath('description').inner_text} | |
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
" https://github.com/tpope/vim-pathogen | |
call pathogen#infect() | |
syntax on | |
set number | |
set expandtab " no real tabs | |
set softtabstop=2 | |
set tabstop=4 | |
" make backspace work normally |
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 Person | |
attr_reader :position, :succ, :alive | |
attr_writer :position, :succ, :alive | |
# Everyone is alive, initially | |
def initialize(pos) | |
@position = pos | |
@alive = true | |
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
# If we list all the natural numbers below 10 that are multiples of 3 or 5, | |
# we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
# Find the sum of all the multiples of 3 or 5 below 1000. | |
def multiples(number, *multipliers) | |
count = 0 | |
list = [] | |
# This range excludes the number you give |
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
filetype off | |
set rtp+=~/.vim/bundle/vundle | |
call vundle#rc() | |
" General Configuration | |
set nocompatible " disable vi compatibility. | |
set history=256 " Number of things to remember in history. | |
set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay |
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
Skipping some of the very basic commands, to use this cheat sheet you need atleast some vim knowledge. | |
; # repeat last search done using f | |
, # undo last search done using f | |
u # undo last change | |
ctrl+r # redo last change | |
:%s/t/r/g # replace all 't' by 'r' | |
~ # change case | |
gu # to lower case | |
gU # to upper case |
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
# This are examples of how to implement a factorial in Ruby | |
def ft(n) | |
return 1 if n <= 1 | |
n.downto(1).inject(:*) | |
end | |
def factorial(n) |
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
#!/usr/bin/env ruby | |
def r! | |
reload! | |
end | |
if ENV['RAILS_ENV'] | |
load "#{ENV['HOME']}/.railsrc" | |
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
#!/usr/bin/env ruby | |
# show queries | |
def logs_on | |
if defined?(ActiveRecord) | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.clear_reloadable_connections! | |
"Logs on!" | |
end | |
end |
OlderNewer