Skip to content

Instantly share code, notes, and snippets.

View pelf's full-sized avatar

Pedro Freitas pelf

  • London
View GitHub Profile
@pelf
pelf / Anonymiser.py
Last active June 16, 2020 15:41
Sublime plugin for anonymising bank statement data
import sublime, sublime_plugin, random, string, re
class AnonymiseCommand(sublime_plugin.TextCommand):
def replacement(self, s):
# Figure out which chars to use
chars = []
if re.search("[a-z]", s):
chars += string.ascii_lowercase
if re.search("[A-Z]", s):
@pelf
pelf / arrays.rb
Last active March 13, 2019 10:35
Quick and simple interview coding exercises
# When given an array with a single duplicate number,
# it returns that number.
def find_duplicate_number(arr)
arr
end
puts '# find_duplicate_number:'
puts find_duplicate_number([5,3,7,2,3,1]) == 3
@pelf
pelf / pre-push
Last active July 24, 2017 17:07
Handy git pre-push script for ruby specs
#!/bin/sh
echo "🌀 Checking for focus: true..."
# Check for focus in spec files
grep -r --include \*_spec.rb "focus:" spec || grep -r --include \*_spec.rb ":focus" spec
if [[ $? == 0 ]]
then
echo >&2 "❌ Found focus in spec file, not pushing"
@pelf
pelf / indianagem-fantasy.markdown
Last active December 26, 2015 10:39
Indianagem @ UEFA Fantasy League

2013 / 2014

cpt | L | L | L | L | | | | | | | | |
naito | L | L | L | W | | | | | | | | |
rattao | L | W | L | L | | | | | | | | |
gui | L | W | W | W | | | | | | | | |
distro | W | L | W | L | | | | | | | | |
pelf | L | W | W | W | | | | | | | | |
cioga | L | W | L | L | | | | | | | | |

@pelf
pelf / p1.rb
Created July 10, 2012 21:57
Project Euler in Ruby
puts (1...1000).inject(0) {|sum,i|
sum = (sum + i) if i%5 == 0 or i%3 == 0
sum
}
@pelf
pelf / 1686.rb
Created June 26, 2012 22:53
Simple ruby scripts coded to help solve new scientist enigmas. They're not meant to be complete or even efficient solutions, only give a little boost in finding the answer as quickly as possible.
# radius: exact nr meters
# slabs: 1x1m
# cut 1/3 of slabs
# total nr slabs?
# ----
MAX_SLABS_RADIUS = 100
# check only a quarter of the circle, the rest is simetric
# try different radiuses
@pelf
pelf / brickset.rb
Created March 22, 2012 02:17
Brickset.com scraper
require 'rubygems'
require 'nokogiri'
require 'open-uri'
class Brickset
@@db = nil # database / cache
class Set
attr_accessor :id, :year, :pieces, :rrpp, :rrpd, :rating, :theme, :subtheme
def initialize(id)
@pelf
pelf / lastfm.rb
Created November 18, 2011 10:57
Last.fm loved tracks -> html with youtube links
require 'rubygems'
require 'util'
module Lastfm
class Artist
attr_accessor :name
def initialize(name)
@name = name
require 'rubygems'
require 'nokogiri'
require 'open-uri'
class Amazon
class Book
attr_accessor :title, :author, :amazon_id, :img
def initialize(url)
url =~ /\/(\d+)\//
@pelf
pelf / snow.html
Created November 26, 2010 02:51
html5 canvas snow flakes (as seen on http://goplanapp.com/home/blackfriday)
<!DOCTYPE html>
<head>
<title>Snow</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="snow.js" type="text/javascript"/></script>
</head>
<body onload="init();">
<canvas id="bgcanvas" width="410" height="316" style="position:absolute;z-index:2"></canvas>
<img src="globe_layers_2.png" style="position:absolute;z-index:3">
<canvas id="fgcanvas" width="410" height="316" style="position:absolute;z-index:4"></canvas>