Skip to content

Instantly share code, notes, and snippets.

@Davidslv
Davidslv / gist:210103
Created October 14, 2009 14:16
[Help] HTML::Mason
We couldn’t find that file to show.
@Davidslv
Davidslv / euromilhoes
Created May 14, 2012 02:19
[Ruby + Nokogiri] Resultados do Euromilhões/Totoloto/Joker
# 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
@Davidslv
Davidslv / .vimrc
Last active December 11, 2015 04:48
My Vim configuration
" 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
@Davidslv
Davidslv / problem.rb
Created February 5, 2013 10:29
The Josephus Problem source: http://danvk.org/josephus.html Problem: "problem.rb:23:in `kill': stack level too deep (SystemStackError)"
class Person
attr_reader :position, :succ, :alive
attr_writer :position, :succ, :alive
# Everyone is alive, initially
def initialize(pos)
@position = pos
@alive = true
end
@Davidslv
Davidslv / multiplier.rb
Last active December 16, 2015 22:20
This method counts all the numbers that are multiples of the numbers you give.
# 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
@Davidslv
Davidslv / .vimrc
Created May 21, 2013 01:36
Vim with Vundle
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
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
@Davidslv
Davidslv / factorial.rb
Created October 8, 2013 23:10
factorial
# 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)
@Davidslv
Davidslv / .irbrc
Created October 14, 2013 16:29
irbrc
#!/usr/bin/env ruby
def r!
reload!
end
if ENV['RAILS_ENV']
load "#{ENV['HOME']}/.railsrc"
end
@Davidslv
Davidslv / .railsrc
Created October 14, 2013 16:30
railsrc
#!/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