Skip to content

Instantly share code, notes, and snippets.

View arademaker's full-sized avatar
🎯
Focusing

Alexandre Rademaker arademaker

🎯
Focusing
View GitHub Profile
@arademaker
arademaker / crawler.R
Created June 2, 2012 12:47
A simple crawler and indexer based on Collective Intelligence chapter 4
library(RCurl)
library(XML)
joinURL <- function(base, u){
sbase <- parseURI(base)
su <- parseURI(u)
if( su$scheme != "")
return(u)
su$scheme <- sbase$scheme
@arademaker
arademaker / sentences.py
Created July 19, 2012 23:59
count of sentences in a set of markdown files
# A simple script to calculate the number of sentences per markdown
# file in a given directory.
#
# Reference:
# - http://nltk.googlecode.com/svn/trunk/doc/howto/portuguese_en.html
# Author: Alexandre Rademaker
import os
import glob
import re
@arademaker
arademaker / statistics.py
Created July 26, 2012 14:36
simple statistics in a markdown corpora
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import glob
import re
import codecs
import nltk
from random import *
from nltk.probability import *
(defun normalize-agents ()
(labels ((compare-agents (agent1 agent2)
(let ((u1 (nth 0 agent1))
(u2 (nth 0 agent2)))
(if (upi= u1 u2)
(list u1 u2 0)
(list u1 u2
(loop for i in (cdr agent1)
for j in (cdr agent2)
summing (numeric-upi-equal i j) into total
(ql:quickload :drakma)
(ql:quickload :st-json)
(defun show-google-hits (term key ck)
(let* ((query (list (cons "key" key)
(cons "cx" ck)
(cons "q" term)))
(stream (drakma:http-request "https://www.googleapis.com/customsearch/v1"
:parameters query
@arademaker
arademaker / reading-stream.lisp
Last active August 29, 2015 14:02
CL example of reading a stream...
(let ((data (make-array 20 :initial-element nil)))
(values(read-sequence data (make-string-input-stream "testing things")) data))
@arademaker
arademaker / stable-matching.R
Last active August 29, 2015 14:03
code of stable matching problem in R
# Solucao baseada no pseudo-codigo apresentado em:
# http://en.wikipedia.org/wiki/Stable_marriage_problem
stable.match <- function(hprefs, mprefs, debug=FALSE){
proposed <- matrix(rep(FALSE,25), ncol = 5, dimnames = list(Homens = 1:5, Mulheres = 1:5))
alloc <- matrix(rep(FALSE,25), ncol = 5, dimnames = list(Homens = 1:5, Mulheres = 1:5))
# os nomes das linhas e colunas irao ser usados para indicar os
# indices para selecao de elementos das matrizes proposed e alloc,
# por isso precisam ser renomeados.
@arademaker
arademaker / fibonacci.lisp
Last active August 29, 2015 14:03
Fibonacci functions in CL. Used in the presentation of Chapter 0 of http://books.google.com/books?id=3sCxQgAACAAJ
(defun fib1 (n)
(cond
((equal n 0) 0)
((equal n 1) 1)
(t (+ (fib1 (- n 1))
(fib1 (- n 2))))))
(defun fib2 (n)
(labels ((calc-fib (n a b)
@arademaker
arademaker / linked-lists.lisp
Last active August 29, 2015 14:03
linked lists and vectors
; first version: procedural
(defun nth-1 (n alist)
(let ((current alist))
(dotimes (v n current)
(if (equal v n)
(car current)
(setf current (cdr current))))))
; second version: functional
@arademaker
arademaker / processing.py
Created July 17, 2014 13:15
using freeling from Python
#!/opt/local/bin/python3.2
# -*- encoding: utf-8 -*-
import sys
import json
sys.path.append('.../myfreeling/APIs/python')
import freeling
import codecs
import re