Skip to content

Instantly share code, notes, and snippets.

View jtoy's full-sized avatar

jtoy

View GitHub Profile
@tmm1
tmm1 / em-irb-console.rb
Created July 12, 2009 01:17
networked irb server/client in EM
require 'rubygems'
require 'eventmachine'
module Console
PROMPT = "\n>> ".freeze
def post_init
send_data PROMPT
send_data "\0"
end
class FanCount
@queue = "FanCount"
include Mongoid::Document
field :page_id
field :fans
field :date, :type => DateTime
index :page_id, :unique => true, :background => true
index(
coll = db.foo
coll.drop()
coll.insert( { arr : [ { a : 1 } , { b : 2 } , { c : 3 } ] } )
coll.insert( { arr : [ { a : 2 } , { b : 3 } , { c : 1 } ] } )
coll.insert( { arr : [ { a : 3 } , { b : 1 } , { c : 2 } ] } )
coll.ensureIndex( { arr : -1 } )
@misshie
misshie / viterbi.rb
Created September 18, 2011 12:05
A Ruby implementation of the Viterbi algorithm based on the hidden Markov model (HMM)
# A Ruby implementation of
# the Viterbi algorithm based on the hidden Markov model (HMM)
#
# An original Python code: a Wikipedia page "Viterbi algorithm" at
# http://en.wikipedia.org/wiki/Viterbi_algorithm
#
# Author: MISHIMA, Hiroyuki
#
require 'pp'
@yagays
yagays / naive-bayes.clj
Created February 3, 2012 05:21
naive-bayes(clojure)
;; 訓練データ
(def text_classified_p '(["good" "bad" "good" "good"]
["exciting" "exciting"]
["good" "good" "exciting" "boring"]))
(def text_classified_n '(["bad" "boring" "boring" "boring"]
["bad" "good" "bad"]
["bad" "bad" "boring" "exciting"]))
;;多変数ベルヌーイモデル
(defn train [features]
@bigsur0
bigsur0 / parallel_find_in_batches_start_end
Created September 23, 2011 16:53
Parallel gem and find_in_batches with start, end
num_processes = 2
batch_size = 1000
threads_per_process = 10
Parallel.map(0...num_processes, :in_processes => num_processes) do |i|·
User.connection.reconnect!
User.find_in_batches(:batch_size => batch_size,·
:start => (User.count/num_processes) * i,·
:conditions => ["id <= ?", (User.count/num_processes)*(i+1)]) do |batch|·
Parallel.map(batch, :in_threads => threads_per_process) do |record|
@timcharper
timcharper / console
Created July 9, 2010 06:08
script/console that loads your .irbrc before activating bundler
#!/usr/bin/env ruby
require "irb"
load "#{ENV['HOME']}/.irbrc"
def IRB.run_config; end
ARGV.unshift "console"
load File.dirname(__FILE__) + "/rails"
@t-vi
t-vi / validation_set_split.py
Last active August 18, 2017 16:08
Torch validation set split (MNIST example)
import torch.utils.data
from torchvision import datasets, transforms
class PartialDataset(torch.utils.data.Dataset):
def __init__(self, parent_ds, offset, length):
self.parent_ds = parent_ds
self.offset = offset
self.length = length
assert len(parent_ds)>=offset+length, Exception("Parent Dataset not long enough")
super(PartialDataset, self).__init__()
@baku89
baku89 / export_video_inceptionism.py
Created October 30, 2016 01:03
My first video deep-dream
from batcountry import BatCountry
import numpy as np
from PIL import Image
from glob import glob
import os
import random
CAFFE_ROOT = '../caffe'
INPUT_PATH = 'input.jpg'
@DrustZ
DrustZ / pvanet.py
Last active January 20, 2018 07:59
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
def debug(debug_open, x, layername):
if debug_open:
print x.size(), 'after', layername
class PVANet(nn.Module):