Skip to content

Instantly share code, notes, and snippets.

View gabrielmansour's full-sized avatar

Gabriel Mansour gabrielmansour

View GitHub Profile
@gabrielmansour
gabrielmansour / twelve_days.rb
Last active December 15, 2015 18:20
How many of each gift will you have received at the end of the twelve days of Christmas?
gifts_on_days = {
1 => :partridge_in_a_pear_tree,
2 => :turtle_doves,
3 => :french_hens,
4 => :calling_birds,
5 => :golden_rings,
6 => :geese_a_laying,
7 => :swans_a_swimming,
8 => :maids_a_milking,
9 => :ladies_dancing,
@gabrielmansour
gabrielmansour / word_enumerator.rb
Created March 21, 2013 03:54
Finds the most frequently used words
MIN_COUNT = 2
COMMON_WORDS = %w(to a an the it and at in of was is as or)
text = File.read(ARGV.first)
frequencies = text.gsub(/[—–-]/,' ').gsub(/[^a-z0-9\s]/i,'').downcase.split(/\s+/).inject(Hash.new) do |memo,word|
memo[word] ||= 0
memo.merge(word => memo[word] + 1)
end
puts frequencies.sort_by(&:last).reverse.select{|word,count| count >= MIN_COUNT && !COMMON_WORDS.include?(word) }.map{|word,count| "#{count}\t#{word}" }
noremap <c-tab> :tabnext<cr>
set expandtab
set smarttab
" enable line numbers
set number
setlocal numberwidth=5
inoremap jj <Esc>
set softtabstop=2
set shiftwidth=2
require 'pp'
data = [
{"name" => "42nd Street","startDate" => 1334203200,"endDate" => 1351396800},
{"name" => "A Word or Two","startDate" => 1343188800,"endDate" => 1345953600},
{"name" => "The Best Brothers","startDate" => 1340683200,"endDate" => 1347768000},
{"name" => "Cymbeline","startDate" => 1336622400,"endDate" => 1348977600},
{"name" => "Elektra","startDate" => 1343534400,"endDate" => 1348891200},
{"name" => "Hirsch","startDate" => 1340164800,"endDate" => 1347595200},
{"name" => "MacHomer","startDate" => 1335931200,"endDate" => 1338004800},
mappings = { // table of character substitutions
'“': '"',
'—': '-',
'–': '-',
// etc
};
@gabrielmansour
gabrielmansour / gist:2431199
Created April 20, 2012 19:30
Google Places Autocomplete output
[
0,
[
[
"Toronto, ON, Canada",
null,
[
"locality",
"political",
"geocode"
RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
jQuery.placeholder = function() {
var p='placeholder',s='['+p+']';
$(s).live('focus',function() {
var input = $(this);
if (input.hasClass(p)) {
input.val('').removeClass(p);
}
}).live('blur', function() {
var input = $(this);
if (input.val() === '') {
<?php
function _mirror_page_parameters(){
if (isset($_GET['page'])) {
$_GET['paged'] = $_GET['page'];
} elseif (isset($_GET['paged'])) {
$_GET['page'] = $_GET['paged'];
}
}
add_action('plugins_loaded', '_mirror_page_parameters');
@gabrielmansour
gabrielmansour / gist:877195
Created March 19, 2011 03:32
wp to tumblr redirection
if (is404()) {
var uri = document.URL.split('?')[0];
var domain = {wp: 'old.matchers.com', tumblr: 'www.mattdemers.com'};
var wp_pages = "about|";
var re_wp = new RegExp("^\/(page\/\d+|2\d{3}\/.+|)", "i");
if re_wp.test(uri)
window.location.href= document.URL.replace(domain.wp, domain.tumblr);
}