Skip to content

Instantly share code, notes, and snippets.

View tokestermw's full-sized avatar

Motoki Wu tokestermw

View GitHub Profile
# Incomplete row major matrix implementation.
type RowMajorMatrix{T} <: AbstractMatrix{T}
col_major::Matrix{T}
end
row_major{T}(c::Matrix{T}) = RowMajorMatrix{T}(c)
Base.size{T}(m::RowMajorMatrix{T}, n::Int) = if n == 1 size(m.col_major, 2) elseif n == 2 size(m.col_major, 1) else size(m.col_major, n) end
Base.getindex{T}(m::RowMajorMatrix{T}, i, j) = m.col_major[j, i]
function setindex!{T}(m::RowMajorMatrix{T}, value, i, j)
@hemanth
hemanth / linkedin_parse.rb
Created July 10, 2012 05:03 — forked from tomdepplito/linkedin_parse.rb
Linkedin Parsing Example
require 'oauth'
require 'launchy'
require 'nokogiri'
class User
def authenticate(consumer_key, consumer_secret, site)
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site)
request_token = consumer.get_request_token
puts "Authorize Follower and then paste in the PIN:"
@skryv
skryv / scikit-learn
Created January 28, 2013 07:15
Parameters required for skikit-learn installation
echo "-----> Installing via pip, but setting environment vars first."
export BLAS=$(pwd)/vendor/lib/atlas-base/atlas/libblas.a
export LAPACK=$(pwd)/vendor/lib/atlas-base/atlas/liblapack.a
export ATLAS=$(pwd)/vendor/lib/atlas-base/libatlas.a
export LIBRARY_PATH=$(pwd)/vendor/lib:$(pwd)/lib/atlas-base:$(pwd)/lib/atlas-base/atlas
export LD_LIBRARY_PATH=$(pwd)/vendor/lib:$(pwd)/vendor/lib/atlas-base:$(pwd)/vendor/lib/atlas-base/atlas
pip install --use-mirrors scikit-learn
@skryv
skryv / gist:4653684
Created January 28, 2013 07:36
Adding the buildpack to your heroku app.
heroku config:add BUILDPACK_URL=https://github.com/ToonTimbermont/heroku-buildpack-python
def get_H_n(X):
return X[:, -1, :] # get last element from time dim
def get_Y(X):
return X[:, :110, :] # get first xmaxlen elem from time dim
def get_R(X):
Y, alpha = X.values() # Y should be (L,k) and alpha should be (L,) and ans should be (k,)
@sbos
sbos / HMM.jl
Created November 1, 2013 11:25
Hidden Markov Model in Julia
module HMM
using Distributions
import Distributions.rand
import Distributions.fit
immutable HiddenMarkovModel{TP, K}
theta::Vector{TP}
A::Matrix{Float64}
@jiumem
jiumem / Callback.md
Last active May 8, 2018 22:45
keras for deep learning
class LossHistory(Callback):
    def __init__(self, X_train, y_train, layer_index):
        super(Callback, self).__init__()
        self.layer_index = layer_index
        if X_train.shape[0] >= 1000:
            mask = np.random.choice(X_train.shape[0], 1000)
            self.X_train_subset = X_train[mask]
            self.y_train_subset = y_train[mask]
        else:
@elmarhaussmann
elmarhaussmann / text_classification_character_rnn.py
Created February 23, 2018 05:12
Character based text classification with TPUEstimator
# Based on the example from the TensorFlow repository: https://github.com/tensorflow/tensorflow/
# https://github.com/tensorflow/tensorflow/blob/671baf080238025da9698ea980cd9504005f727c/tensorflow/examples/learn/text_classification_character_rnn.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
@elijahmanor
elijahmanor / fake-server-unit-test.js
Last active August 28, 2018 09:23
Unit Test like a Secret Agent with Sinon.js
describe("getTweets - Server", function () {
var server, fakeData = [ /* ... */ ];
before(function () {
// Doesn’t work :( It’s JSONP!
server = sinon.fakeServer.create();
server.respondWith(
"GET",
"https://api.twitter.com/.../elijahmanor.json?count=5",
[200, { "Content-Type": "application/json" }, JSON.stringify(fakeData)]
#!/usr/bin/env python
# coding: utf-8
"""Sampling Sequence Data from model"""
import numpy as np
import tensorflow as tf
import json
import cPickle as pickle
import itertools as it
from rnnlib import PTBModel