Skip to content

Instantly share code, notes, and snippets.

View korny's full-sized avatar

Kornelius Kalnbach korny

View GitHub Profile
@korny
korny / git-publish-branch
Created January 21, 2019 13:33
git-publish-branch
#!/usr/bin/env ruby
## git-publish-branch: a simple script to ease the unnecessarily complex
## task of "publishing" a branch, i.e., taking a local branch, creating a
## reference to it on a remote repo, and setting up the local branch to
## track the remote one, all in one go. you can even delete that remote
## reference.
##
## Usage: git publish-branch [-d] <branch> [repository]
##
@korny
korny / sphinx.rb
Created June 13, 2018 23:21
Sphinx Homebrew formula for MySQL 5.7
class Sphinx < Formula
desc "Full-text search engine"
homepage "http://www.sphinxsearch.com"
url "http://sphinxsearch.com/files/sphinx-2.2.11-release.tar.gz"
sha256 "6662039f093314f896950519fa781bc87610f926f64b3d349229002f06ac41a9"
head "https://github.com/sphinxsearch/sphinx.git"
bottle do
sha256 "b890cf523db9777c7d125842fd6b0a53fe9a7a5a4cb816389ba6f5ee6483c78d" => :high_sierra
sha256 "55ce34bdedf13946fa614bde50839d93135eae720f1021e2c87807d04515ab18" => :sierra
@korny
korny / overviewer_config.py
Last active September 26, 2015 17:14
Minecraft Overviewer config file (N/W/S/E+Nether, Markers for Signs, Players, and Chests with Iron or Diamonds)
# coding=utf-8
worlds['Beteigeuze'] = "~/minecraft-saves/Beteigeuze"
outputdir = "/var/www/Kornelius-Kalnbach/minecraft.murfy.de/Beteigeuze"
rendermode = "smooth_lighting"
def signFilter(poi):
if poi['id'] == 'Sign':
return "\n".join([poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']])
@korny
korny / markdown-parser.rb
Last active August 29, 2015 14:26
Super Markdown Parser (Ruby flavored)
def markdown_h(input)
input.gsub(/^(?'hashtag'#+) (?'title'.*)/) do
level = [$~[:hashtag].size, 6].min
"<h#{level}>#{$~[:title]}</h#{level}>"
end
end
def markdown_em(input)
input.gsub(/\*(?'text'\S+)\*/) do
"<em>#{$~[:text]}</em>"
@korny
korny / git-restore
Created January 8, 2015 10:03
Copy a file's master version to your working directory (prefixed with old_)
#!/usr/bin/env ruby
source = ARGV.first or raise 'need a file name'
basename = File.basename(source)
target = File.join File.dirname(source), (basename[/^_/] ? '_old' : 'old_') + basename
exec "git show master:#{source} > #{target}"
@korny
korny / gist:4f6ea67986d3d5efa462
Created December 17, 2014 11:14
Ruby 1.8/1.9 change regarding super inside a proc
class Human
def self.speak what
what
end
end
class Pirate < Human
def self.speak what
proc { super }.call
end
@korny
korny / srt-parser.js
Created July 3, 2014 13:00
Simple SRT parser in JavaScript
function srtTimeToSeconds(time) {
var match = time.match(/(\d\d):(\d\d):(\d\d),(\d\d\d)/);
var hours = +match[1],
minutes = +match[2],
seconds = +match[3],
milliseconds = +match[4];
return (hours * 60 * 60) + (minutes * 60) + (seconds) + (milliseconds / 1000);
}
@korny
korny / block_given.rb
Created January 8, 2014 19:05
block_given? doesn't work in a delegating BasicObject
class Foo < BasicObject
def test_block_given?
block_given?
end
private
def method_missing(method, *args, &block)
3.send(method, *args, &block)
end
end
@korny
korny / shadowrun-dice-calculator.rb
Created January 6, 2014 02:38
A helper script for Shadowrun dice calculations, especially the probability of Glitches. Includes Shadowrun 5 rules. This is public domain.
module Math
class << self
def fac n
return 1 if n < 2
(1..n).inject { |prod, i| prod * i }
end
def choose n, k
fac(n) / (fac(n-k) * fac(k))
end