Skip to content

Instantly share code, notes, and snippets.

View demimismo's full-sized avatar

David Arango demimismo

View GitHub Profile
# convert multibyte strings to an url-safe encoding
class String
def to_permalink
(Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv self).gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase
end
end
# I use this method to parse large csv files, clean the data and insert
# it in a database after some cleaning, it's pretty fast
# you can use it like this:
load_csv_data(PRELOAD_DIR+'socios.csv', 'users') do |csv, thing_id, row|
csv << [thing_id,
row['NOMBRE'].to_s.to_permalink+'.'+row['APELLIDOS'].to_s.to_permalink, # login
row['E_MAIL'], # email
row['SEXO'], # gender
A backup of http://sites.google.com/site/redcodenl/creating-shazam-in-java-1 just in case
Why is this necessary? Read http://sites.google.com/site/redcodenl/patent-infringement
Please fork, tweet about, etc.
----
Creating Shazam in Java
A couple of days ago I encountered this article: How Shazam Works
This got me interested in how a program like Shazam works… And more importantly, how hard is it to program something similar in Java?
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
index--;
// 1
var Person = function(name) {
this.name = name;
}
// 2
Person.prototype.getName = function() {
return this.name;
}
@demimismo
demimismo / swap_lines.vim
Created July 4, 2011 07:47
Vim plugin to swap lines
function! s:swap_lines(n1, n2)
let line1 = getline(a:n1)
let line2 = getline(a:n2)
call setline(a:n1, line2)
call setline(a:n2, line1)
endfunction
function! s:swap_up()
let n = line('.')
if n == 1
set nocompatible " We don't want vi compatibility
syntax on
filetype plugin indent on " Automatically detect file types
colorscheme molokai
set nu " Insert line numbers
set tabstop=2 " Tabs are 2 spaces
set shiftwidth=2 " Tabs under smart indent
@demimismo
demimismo / gist:3359506
Created August 15, 2012 11:57
Install Postgresql on Mountain Lion

Install Postgresql on Mountain Lion

Based on: http://coderwall.com/p/1mni7w

brew install postgresql
initdb /usr/local/var/postgres -E utf8
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
@demimismo
demimismo / gist:3388600
Created August 18, 2012 17:33
Install cartodb-rb-client github version
Using bundler:
source "http://rubygems.org"
gem 'cartodb-rb-client', :git => 'git://github.com/Vizzuality/cartodb-rb-client.git'
Or manually from source:
git checkout git://github.com/Vizzuality/cartodb-rb-client.git
cd cartodb-rb-client
gem build cartodb-rb-client.gemspec
@demimismo
demimismo / combine.rb
Created August 31, 2012 21:04
Combine multiple sheets on xls into a single csv
require 'rubygems'
require 'roo'
require 'iconv'
oo = Excel.new("data.xls")
CSV.open("export.csv", "wb") do |csv|
oo.sheets.each do |s|
oo.default_sheet = s