This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HMM | |
using Distributions | |
import Distributions.rand | |
import Distributions.fit | |
immutable HiddenMarkovModel{TP, K} | |
theta::Vector{TP} | |
A::Matrix{Float64} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Role < ActiveRecord::Base | |
ROLES = [ :group_admin, :agency_admin ] | |
# - Relationships - | |
has_many :user_roles | |
has_many :users, :through => :user_roles | |
# - Class Methods - | |
class << self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
has_many :tag_links, :as => :tags | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
has_many :tag_links | |
has_many :tags, :through => :tag_links | |
# ... | |
end |
OlderNewer