Skip to content

Instantly share code, notes, and snippets.

@igul222
igul222 / gist:4249569
Created December 10, 2012 09:24
bloo.tk
# totally untested bloo.tk in 5 lines, one of which is a comment ;)
require 'json', 'sinatra'
get '/*' do
redirect JSON.parse(`curl http://api.duckduckgo.com/?q=#{params[:splat].join(' ')}&format=json`)['Results']['FirstURL']
end
@igul222
igul222 / gist:4256102
Created December 11, 2012 05:23
Gangsta-to-english
require 'mechanize'
module Gangsta
def self.to_gangsta(english)
agent = Mechanize.new
page = agent.get "http://gizoogle.net/textilizer.php"
search_form = page.form_with :name => "query"
search_form.field_with(:name => "translatetext").value = english
search_results = agent.submit search_form
arr2_pos = 0
product = 0
for each thing1 in arr1:
while arr2[arr2_pos][0] <= thing1[0]:
arr2_pos++
if arr2[arr2_pos][0] == thing1[0]:
product += arr2[arr2_pos][1] * thing1[1]
return product
class C<T> {}
protocol P {
typealias E : C<Self>
}
final class A : P {
typealias E = C<A>
}
class C<T> {}
protocol P {
typealias E : C<Self>
}
class A : P {
typealias E = C<A>
}
class Game
@XMax: 25
@YMax: 15
@DotsPerPlayer: 2
@FunctionAnimationSpeed: 0.005 # graph units per ms
@DotRadius: 1
@TurnTime: 60000 # ms
@ObstacleCount: 10
@ObstacleRadiusMin: 0
@ObstacleRadiusMax: 5
Moves =
start: () ->
{type: 'start'}
class Players
constructor: (@game) ->
@teams: [
active: true
players: []
class Node(object):
def __init__(self, _children):
self.memo = None
self.children = _children
dest = Node([])
source = Node([
dest, # source -> dest
Node([dest]), # source -> intermediate -> dest
Node([Node([dest])]), # source -> a -> b -> dest
# Balanced binary tree of height 2. Boring, I know...
node_count = 7
edges = [
(0,1),
(0,2),
(1,3),
(1,4),
(2,5),
(2,6)
]
@igul222
igul222 / ctc.py
Last active March 22, 2016 09:36
Theano CTC implementation with performance and numerical stability optimizations
# Author: Ishaan Gulrajani
# License: BSD 3-clause
import numpy
import theano
import theano.tensor as T
# log(0) = -infinity, but this leads to
# NaN errors in log_add and elsewhere,
# so we'll just use a large negative value.