Skip to content

Instantly share code, notes, and snippets.

View alep's full-sized avatar
🐙
Vamo' a calamarno

Alejandro Peralta alep

🐙
Vamo' a calamarno
View GitHub Profile
import nltk
from collections import namedtuple
from sklearn.linear_model import LogisticRegression
from sklearn.feature_extraction import FeatureHasher
Data = namedtuple('Data', [
'word_i_minus_2',
@alep
alep / id3.py
Created September 1, 2014 20:19 — forked from cmdelatorre/id3.py
"""
http://en.wikipedia.org/wiki/ID3_algorithm
http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm
"""
from collections import namedtuple, Counter, defaultdict
from math import log2
# coding: utf-8
import scipy as sp
from sklearn.feature_extraction.text import CountVectorizer, HashingVectorizer
from sklearn.naive_bayes import BernoulliNB
from sklearn.linear_model import LogisticRegression
from sklearn import cross_validation
from sklearn import metrics
datafile = open("data.tsv")

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@alep
alep / ipython output
Created February 13, 2015 19:42
Strange results when pivoting, doesnot group by day as expected.
In [1]: %load test.py
In [2]: import pandas as pd
import numpy as np
frame = pd.read_csv("table.csv", engine="python", parse_dates=['since'])
print frame
d = pd.pivot_table(frame, index=pd.TimeGrouper(key='since', freq='1d'), values=["value"], columns=['id'], aggfunc=np.sum, fill_value=0)
print d
print "^that is not what I expected"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alep
alep / introrx.md
Last active August 29, 2015 14:26 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

[Desktop Entry]
Version=24.5
Name=Emacs
Exec=env UBUNTU_MENUPROXY=0 /usr/local/bin/emacs-24.5
Terminal=false
Icon=/usr/local/share/icons/hicolor/128x128/apps/emacs.png
Type=Application
Categories=IDE
X-Ayatana-Desktop-Shortcuts=NewWindow
[NewWindow Shortcut Group]
@alep
alep / main.go
Last active August 29, 2015 14:27
Web crawler from the tour of go.
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage', 'filtrate', 'sort_by');
typeof(options) != 'undefined' || (options = {});
typeof(this.limit) != 'undefined' || (this.limit = 20);
typeof(this.offset) != 'undefined' || (this.offset = 0);
typeof(this.filter_options) != 'undefined' || (this.filter_options = {});
typeof(this.sort_field) != 'undefined' || (this.sort_field = '');