Skip to content

Instantly share code, notes, and snippets.

View ferreiro's full-sized avatar
👨‍🎤
Dancing in the rain

Jorge Ferreiro ferreiro

👨‍🎤
Dancing in the rain
View GitHub Profile
@ferreiro
ferreiro / probabilityMedian.js
Last active August 29, 2015 14:27
Cheat mathematics: Simple programs to make my "Probabilty and staditics" problems for the university.
// Calculate the mean of a set.
var i;
var result = 0;
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // age.
var absFrec = [9, 8, 7, 6, 5, 4, 3, 2, 1]; // absolute frecuency.
var N = 0; // Total value of the set.
for (i = 0; i < data.length; i++) {
N += absFrec[i];
@ferreiro
ferreiro / TextFrecuency
Last active August 29, 2015 14:27
Code for extracting all the words on a webpage and get the absolute frecuency of that elements
var words = (function(){
var sWords = document.body.innerText.toLowerCase().trim().replace(/[.,;?¿@]/g,' ').split(/[\s\/]+/g).sort();
var iWordsCount = sWords.length; // count w/ duplicates
// array of words to ignore
var ignore = ['and','the','to','a','of','for','as','i','with','it','is','on','that','this','can','in','be','has','if',
'de', 'del', 'y', 'en', 'que', 'para', 'tu', 'con', 'su', 'mas', 'o',
'el','te', 'ti', 'un', 'lo', 'los', 'la', 'las', 'una', 'más', 'sus', 'este', 'desde', 'tras',
@ferreiro
ferreiro / poissonDistribution.js
Last active February 8, 2024 13:48
Poisson distribution formula in javascript
var k_total = 10; // number of times the event is repeated
var landa = 8; // Promedian number of error expected in a given time (Landa symbol)
var exponential = 2.718281828;
var total = 0;
var numerator, denominator;
// Sumatorio de k terminos usando la formula de poisson
function poisson(k, landa) {
@ferreiro
ferreiro / BinomialCoefficient.js
Created August 29, 2015 11:32
Binomial coefficient in javascript
// Binomial coefficient
// Credits: github.com/jgferreiro
examples();
function examples() {
var a, b; // numerator and denominator of our coeffiecient
a = 2; b = 1;
console.log('Binomial for a = ' + a + " and b = "+ b + ' is ' + binomialCoefficient(a, b));
# MapReduce: gasto total realizado por las mujeres que han realizdo EXACTAMENTE
# 3 compras.
@get('/spending_female_3_orders_mr')
def spending_female_3_orders_mr():
mapper = Code("""
function countryMap()
{
if (this.gender == "Female") {
# Subject classs. That has a constructor (__init__) and a method (getSubjectInfo)
class Subject:
def __init__(self, name, teacher, year, degree):
self.name = name
self.teacher = teacher
self.year = year
self.degree = degree
def getSubjectInfo(self):
info = "-------------------------------------\n"
@ferreiro
ferreiro / GenerateGames.py
Created February 7, 2016 23:22
Generate a list of games as prolog deffacts using a simple python program.
from random import randint
games = [] # It's a list og games where each element is a dictionary {'name': '', 'type':'', 'used': False|True}
cons_type = ['inteligencia','deporte','aventura','familiar']
cons_numPlayers = ['uno', 'dos', 'MasDeDos']
cons_difficulty = ['facil', 'media', 'dificil']
cons_time = ['poco', 'medio', 'mucho']
cons_age = ['TP', 'Mas13', 'Mas18']
git config credentials.helper osxkeychain
@ferreiro
ferreiro / Git-shortcuts
Created March 1, 2016 17:02
Github commands
log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow) %d%C(reset)' --all
git config --global alias.superlog "PONER LO DE ARRIBA"
class CracklePop(object):
def __init__(self, left, right):
self.left = left
self.right = right
# Private methods
def valid_bounds(self):
left = self.left
right = self.right