Skip to content

Instantly share code, notes, and snippets.

View thiagomoretto's full-sized avatar

Thiago Moretto thiagomoretto

View GitHub Profile
@thiagomoretto
thiagomoretto / optics.py
Created December 20, 2016 21:19
Optics clustering algorithm
from math import sqrt
from geopy.distance import great_circle
from collections import defaultdict
def km(a, b):
return great_circle(a, b).km
def euc2d(a, b):
@thiagomoretto
thiagomoretto / .gvimrc
Last active December 15, 2015 02:24
vim+iTerm
macm Window.Select\ Next\ Tab key=<nop>
nmap <D-}> :bnext<CR>
macm Window.Select\ Previous\ Tab key=<nop>
nmap <D-{> :bprev<CR>
map <D-\|> :blast <CR>
map <D-+> :BufExplorer<CR>
map <D-S-BS> :bdelete<CR>
@thiagomoretto
thiagomoretto / bfs.clj
Created August 10, 2015 00:56
Breadth-first
(defn bfs [sz ef ff]
"Initial state sz, expansion function ef [s] and feasibility function ff [s]"
(loop [queue (conj clojure.lang.PersistentQueue/EMPTY sz)
ef ef
ff ff]
(if (seq queue)
(let [nx (peek queue)]
(if (ff nx) nx (recur (into (pop queue) (ef nx)) ef ff)))
nil)))
require 'rubygems'
require 'json'
@products = {
1 => { :name => 'A' },
2 => { :name => 'B' },
3 => { :name => 'C' },
4 => { :name => 'D' },
5 => { :name => 'E' },
6 => { :name => 'F' }
@thiagomoretto
thiagomoretto / 0_reuse_code.js
Created January 7, 2014 11:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@thiagomoretto
thiagomoretto / nutcracker.sh
Created January 22, 2013 19:47
example of nutcracker init.d script (to CentOS)
#!/bin/sh
#
# nutcracker - this script starts and stops the nutcracker-server daemon
#
# chkconfig: - 85 15
# description: Nutcracker is a proxy-server to Redis and/or Memcached
# processname: nutcracker-server
# config: /etc/nutcracker/nutcracker.conf
# config: /etc/sysconfig/nutcracker
# pidfile: /var/run/nutcracker.pid
@thiagomoretto
thiagomoretto / inflections.rb
Created June 13, 2012 20:10 — forked from mateusg/inflections.rb
pt-BR inflections file for Ruby on Rails applications
# encoding: utf-8
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
[core]
editor = vim
[user]
name = "Thiago Moretto"
email = "thiago.moretto@gmail.com"
[alias]
co = checkout
ci = commit
@thiagomoretto
thiagomoretto / .vimrc
Created December 28, 2011 21:17
Mini .vimrc
set nocompatible
syntax on
set ruler
set background=dark
set wildmenu " turn on wild meno :e <Tab>
set wildmode=list:longest,list:full
set completeopt=menu,longest,preview " autocomplete opts <C-p>
set encoding=utf-8
@thiagomoretto
thiagomoretto / StringUtil.java
Created December 2, 2011 17:20 — forked from ar/StringUtil.java
String[] Encode/Decode (my attempt)
import java.util.*;
public class StringUtil {
public static String encode (String[] ss) {
StringBuilder sb = new StringBuilder();
for (String s : ss) {
if (sb.length() > 0)
sb.append(',');
if (s != null)
sb.append(s.replaceAll("\\\\", "\\\\\\\\")