Skip to content

Instantly share code, notes, and snippets.

View fayimora's full-sized avatar
🕺

Fayi FB fayimora

🕺
  • London, England
View GitHub Profile
/**
The MIT License (MIT)
Copyright (c) 2013 Jean Helou
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
import pandas as pd
from ggplot import *
from sklearn.datasets import fetch_20newsgroups
from sklearn.metrics import roc_curve
# vectorizer
from sklearn.feature_extraction.text import HashingVectorizer
# our classifiers
from sklearn.naive_bayes import BernoulliNB, MultinomialNB
@fayimora
fayimora / HMM.jl
Last active August 29, 2015 14:12 — forked from sbos/HMM.jl
module HMM
using Distributions
import Distributions.rand
import Distributions.fit
immutable HiddenMarkovModel{TP, K}
theta::Vector{TP}
A::Matrix{Float64}
def stochastic_linear_gradient_descent(X, y, theta, alpha, tolerance):
converged = False
prev_cost = 0
n_samples = X.shape[0]
while not converged:
# use xrange so you dont have to generate the entire range of numbers
for i in xrange(n_samples):
# you have to sample x and y together
# FYI, using one example at a time can be super slow.
# you might want to consider using batches which should converge quicker
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
{
import javax.sound.midi._
val synth = MidiSystem.getSynthesizer()
synth.open()
def note(i: Int) = {
val channels = synth.getChannels()
channels(0).noteOn(i, 100)
Thread.sleep(250)
channels(0).noteOff(i)
}
@fayimora
fayimora / gist:1094465
Created July 20, 2011 06:40 — forked from JosephPecoraro/shell-execution.rb
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@fayimora
fayimora / role.rb
Created February 12, 2012 18:19 — forked from mongrelion/role.rb
Dynamic Role methods for Role and User models
class Role < ActiveRecord::Base
ROLES = [ :group_admin, :agency_admin ]
# - Relationships -
has_many :user_roles
has_many :users, :through => :user_roles
# - Class Methods -
class << self
@fayimora
fayimora / post.rb
Created February 20, 2012 20:46 — forked from davidcelis/post.rb
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links, :as => :tags
# ...
end
@fayimora
fayimora / post.rb
Created February 23, 2012 01:04 — forked from davidcelis/post.rb
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links
has_many :tags, :through => :tag_links
# ...
end