Skip to content

Instantly share code, notes, and snippets.

Troels Knak-Nielsen troelskn

Block or report user

Report or block troelskn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View remove-image-background.sh
# Requires ImageMagick
# Converting the source from JPEG to PNG - if necessary
convert my_src_image.jpg my_src_image.png
# Option A
# - Requires a temporary intermediate file
# - Drill more than 10 might result in poor results
@troelskn
troelskn / levenshtein.rb
Last active Dec 17, 2015 — forked from sunlightlabs/levenshtein.rb
Fixed to build on mac + 64 bit
View levenshtein.rb
# C implementation of Levenshtein text distance algorithm, uses RubyInline to call from within Ruby
# Wildly faster than the Text gem's Text::Levenshtein
# Example:
# l = Levenshtein.new
# l.distance 'hello', ' hello'
# => 1
# Taken from http://www.benallfree.com/2008/10/05/finding-duplicate-text-with-ruby/
View net-http-debug.rb
module Net
class HTTP
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
ensure
@debug_output = $stderr ### if ENV['HTTP_DEBUG']
end
end
View gist:4336581
require 'sinatra/base'
require 'eventmachine'
require 'em-http-request'
EM.run do
class App < Sinatra::Base
helpers do
def wait_for(&block)
while block.call.nil?
@troelskn
troelskn / app.rb
Last active Jul 14, 2019 — forked from dstrelau/app.rb
Gollum protected by HTTP Basic
View app.rb
require 'gollum/frontend/app'
require 'digest/sha1'
class App < Precious::App
User = Struct.new(:name, :email, :password_hash, :can_write)
before { authenticate! }
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end
helpers do
View pre-receive.py
import sys
import os
import subprocess
def git(args, **kwargs):
environ = os.environ.copy()
if 'repo' in kwargs:
environ['GIT_DIR'] = kwargs['repo']
if 'work' in kwargs:
environ['GIT_WORK_TREE'] = kwargs['work']
View git build-failed file for cijoe
#!/usr/bin/env bash
# Note the use of env. This is because executables may not be placed in the same place on all systems. Notoriously, bsd (and thus mac osx) differs from linux. However, /usr/bin/env always exists in the same place, and it can tell you where other executables are. Thus, the above is good style for portability.
COMMIT_VERSION=$(git rev-parse --verify HEAD)
# You could also use backticks, but the $() syntax is generally more readable
# Convention is to put variables in uppercase in shell script
curl -k -u user:password \
-d "to=lsolesen&msg=%22Intraface+build+failed%22&title=Intraface+build+failed&uri=https%3A%2F%2Fgithub.com%2Fintraface%2Fintraface.dk%2Fcommit%2F${COMMIT_VERSION}" \
https://api.notifo.com/v1/send_notification > /dev/null
View gist:148380
phpsh (c)2006 by Charlie Cheever and Dan Corson and Facebook, Inc.
type 'h' or 'help' to see instructions & features
New Feature: You can use the -c option to turn off coloring
php> var_dump(null > 10);
bool(false)
php> var_dump(null < 10);
bool(true)
php> var_dump(null == 10);
bool(false)
php> var_dump(null == null);
You can’t perform that action at this time.