Skip to content

Instantly share code, notes, and snippets.

View tivtag's full-sized avatar
😄

Paul Ennemoser tivtag

😄
View GitHub Profile
@tivtag
tivtag / rename.rb
Last active December 16, 2015 18:19
Super simple multi-file rename ruby-script for episodic files. ToDo: Add support for seasons and in-between episode identifiers
folder_path = "E:/path_to_files/"
regexp = /(Ep_(?<episode>\d+)_'(?<episode_name>[A-Za-z]+))/
new_filename = "Testname - E<episode> - <episode_name>"
accepted = false
Dir.glob(folder_path + "/*").sort.each do |file|
ext = File.extname(file)
old_filename = File.basename(file, File.extname(file))
matches = old_filename.match(regexp)
@tivtag
tivtag / template_cycles.cpp
Created September 10, 2011 13:50
silly (working!) attempt at cyclic template types
#include <iostream>
template <template <class X> class V, class TV,
template <class Y> class E, class TE>
struct VT
{
typedef VT<V, TV, E, TE> Combo;
typedef TV VertexDataType;
typedef TE EdgeDataType;
@tivtag
tivtag / Eratosthenes2.hs
Created September 6, 2011 16:10
Sieve of Eratosthenes in Haskell (much faster second try)
-- Sieve of Eratosthenes
sieve :: [Int] -> [Int]
sieve [] = []
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p /= 0]
primes :: Int -> [Int]
primes n = sieve [2..n]
@tivtag
tivtag / Eratosthenes.hs
Created September 5, 2011 20:36
Sieve of Eratosthenes in Haskell (slow slow slow first try)
-- Sieve of Eratosthenes
import Data.List
primes n = sieve [2..n] 2
sieve [] _ = []
sieve xs n =
n : (sieve left (head left))
where marked = [x | x <- xs, x `rem` n == 0]
left = xs \\ marked
@tivtag
tivtag / hash symbol_to_hash
Created May 9, 2011 19:43
Ruby method that takes [Symbol -> Function]
# Ruby 1.9.2
# Attempt at creating a method that takes a string and mappings of symbols to functions.
#
# Is there a better way that does not require as many {} and ->s?
choice 'A monster appears behind you! Start [run]ning away or [jump] from the cliff?',
run:-> {
puts "You just got eaten. Sorry."
},
@tivtag
tivtag / hierarchical_locations.rb
Created November 3, 2010 18:48
Just some odd (incomplete) specification file that verifies a module that reads in locations (in a text adventure) described in a DSL. Also includes the location data files.
location :street do
location :park do
location :bank do
end
end
location :house do
location :door do
end
end