Skip to content

Instantly share code, notes, and snippets.

View felipecruz's full-sized avatar

Felipe Cruz felipecruz

  • Berlin, Germany
View GitHub Profile
>>> data = ['aa', 'bb', 'ab', 'bc']
>>> def _filter_native(data):
... sts = ['a', 'b']
... rets = []
... for st in sts:
... rets.append((st, filter(lambda x: x.startswith(st), data)))
... return rets
...
>>> rdds = _filter_native(data)
>>> for st, rdd in rdds:
def _filter(st):
return filter(lambda x: x.startswith(st), ['aa', 'bb', 'ab', 'cc'])
fa = _filter('a')
print(next(fa)) # aa
print(next(fa)) # ab
fa = _filter('a')
st = 'b'
print(next(fa)) # aa
r1 = (u'1', 'a1')
r2 = (u'1', 'a2')
r3 = (u'2', 'a3')
r4 = (u'2', 'a4')
r5 = (u'2', 'a5')
r6 = (u'2', 'a6')
r7 = (u'4', 'a7')
r8 = (u'4', 'a8')
r9 = (u'3', 'a9')
@felipecruz
felipecruz / livro.py
Created October 29, 2015 19:57
livropython
>>> impostos = ['MEI', 'Simples']
>>> for imposto in impostos:
... if imposto.startswith('S'):
... print(imposto)
...
Simples
>>> impostos = ['MEI', 'Simples']
>>> for imposto in impostos:
... print(imposto.startswith('S'))
...
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@felipecruz
felipecruz / linear_regression_hr.cpp
Last active September 22, 2015 14:46
cpp linear regression - no regularization
/* Author: felipe cruz felipecruz@gmail.com
*/
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <random>
@felipecruz
felipecruz / perceptron.cpp
Created November 19, 2014 04:28
Perceptron
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
class Perceptron {
vector<double> w;
double learning_rate;
bool error;
@felipecruz
felipecruz / kamikaze_trader.txt
Last active August 29, 2015 14:06
kamikaze trader
Profit é o lucro total e não lucro da operação.
Buy 5000 PETRF20 at: 0.140000
Buy 1000 PETRF18 at: 0.200000
Sell 1000 PETRF18 at: 0.220000
Profit: -20.000000
Buy 1200 PETRF18 at: 0.220000
Sell 5000 PETRF20 at: 0.230000
Profit: 390.000000
Buy 1300 PETRF16 at: 0.770000
@felipecruz
felipecruz / gurobi_cffi.py
Last active August 29, 2015 14:05
gurobi cffi interface major WIP
import cffi
GRB_EQUAL = 61
ffi = cffi.FFI()
ffi.cdef('''
typedef ... GRBenv;
typedef ... GRBmodel;
@felipecruz
felipecruz / bind_local_names.py
Last active August 29, 2015 14:04
Bind in outer scope variables from a dict
def bind_local_names(params):
'''create outer scope vars from a dict'''
import sys
for k, v in params.items():
sys._getframe(1).f_locals[k] = v
params = dict(b='test', c=10)
bind_local_names(params)