Skip to content

Instantly share code, notes, and snippets.

Matjaz Muhic depy

View GitHub Profile
View pac_rules.rb
###############
# 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
View enum_struct_procotol.swift
import Foundation
protocol Addable {
func add(tx: Transaction) -> Double
}
enum TransactionType {
case credit
case debit
}
View rbf_test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gist:49fee95a49525a729e91
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
View Redis to redis data copy
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 Nov 29, 2013
Simple composition of ruby lambdas.
View gist:7713078
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 Oct 30, 2013
Need to sort list of points depending on angle between each of them and another point and axis x.
View gist:7239146
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)
View gist:5843359
class Iter
def initialize(arr)
@f = Fiber.new do
while item = arr.shift
Fiber.yield item
end
end
end
def next
@f.resume
You can’t perform that action at this time.