Skip to content

Instantly share code, notes, and snippets.

View depy's full-sized avatar
💨

Matjaz Muhic depy

💨
  • Codeable
  • Slovenia
View GitHub Profile
@depy
depy / rbf_test.ipynb
Created September 4, 2018 18:31
rbf_test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
###############
# Rules #
###############
FIND the most valuable path within range
# I could only do 5 cells away/levels deep before my code was timing out
# Partly because Ruby is not the fastest
# Partly because I started to think about performance too late
IF enemy 1 cell away and possible to eat them
import Foundation
protocol Addable {
func add(tx: Transaction) -> Double
}
enum TransactionType {
case credit
case debit
}
redisSrc = Redis.connect :timeout => 20, :url => "redis://some.host.com:11111"
redisDest = Redis.connect :timeout => 20, :url => "redis://other.host.com:22222"
redisSrc.keys("*").each do |key|
data = redisSrc.dump key
redisDest.restore key, 0, data
end
@depy
depy / gist:7713078
Created November 29, 2013 22:54
Simple composition of ruby lambdas.
class Proc
def *(f)
->(*args) { self.(f.(*args)) }
end
end
plus2 = ->(n) { n+2 }
plus3 = ->(n) { n+3 }
plus5 = plus2 * plus3
@depy
depy / gist:7239146
Created October 30, 2013 19:56
Need to sort list of points depending on angle between each of them and another point and axis x.
import Data.Monoid
data Point = Point { x :: Float, y :: Float} deriving (Show, Eq)
data Dir = DL | DR | DS deriving (Show)
instance Ord Point where
compare (Point x y) (Point x' y') = mappend (compare y y') (compare x x')
distance :: Point -> Point -> Float
distance p0 p1 = sqrt ((x p0 - x p1)**2 + (y p0 - y p1)**2)
class Iter
def initialize(arr)
@f = Fiber.new do
while item = arr.shift
Fiber.yield item
end
end
end
def next
@f.resume
main :: IO()
main = mapM_ putStrLn $ take 30 fizzBuzz
fizzBuzz = let nums = map show [1..]
fizzs = cycle $ ["", "", "Fizz"]
buzzs = cycle $ ["", "", "", "", "Buzz"]
in zipWith3 (\f b n -> if f++b == "" then n else f++b) fizzs buzzs nums