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
class IbanConverter
function convert_dk($input) {
$iban = "DK00" .
str_pad($input['dk_bank_reg_number'], 4, "0", STR_PAD_LEFT) .
str_pad($input['dk_bank_account_number'], 10, "0", STR_PAD_LEFT);
troelskn / AppServiceProvider.php
Created Feb 23, 2017
Laravel workaround for broken openssl
View AppServiceProvider.php
// app/Providers/AppServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
public function register()
troelskn / wphack_payload.php
Created Mar 23, 2016
Partially de-obfuscated payload script from a hacked wp site
View wphack_payload.php
if (FALSE == nplqy70($u11, $pakfn17)) {
echo PHP_OS . '+' . md5(0987654321) . '+01+[[]]
$jkber87 = array();
troelskn / Capfile
Created Jan 26, 2016
Sample cap setup
View Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
# For documentation on these, see for example:
troelskn / mysql2excel
Last active Sep 15, 2015
On mac osx, turn a mysql console result into something that can be pasted into excel
View mysql2excel
#!/usr/bin/env ruby
# put in /usr/local/bin/mysql2excel
buffer = []
input = `pbpaste`.strip
input.split("\n").each do |line|
unless line =~ /^([+-]+|\d+ rows in set.*|mysql>)$/
buffer << line.gsub(/^[|]/, "").gsub(/[|]$/, "").strip.gsub(/\s*[|]\s*/, "\t")
IO.popen "pbcopy", "w" do |pipe|
View gist:221aec3bfdfd3d86d069
// Take XmlReader node and read it into an assoc array
function xml2assoc($xml) {
$buffer = null;
while ($xml->read()) {
switch ($xml->nodeType) {
case XMLReader::END_ELEMENT:
return $buffer;
case XMLReader::ELEMENT:
View simple_xls_writer.php
* Write with file extension xls and you should be fine.
* This format is called SpreadsheetML
class SimpleXlsWriter {
protected $filename;
protected $handle;
protected $title = "No Title";
protected $author = "No Author";

Keybase proof

I hereby claim:

  • I am troelskn on github.
  • I am troelskn ( on keybase.
  • I have a public key whose fingerprint is FCE4 73F5 52AA C2B0 B73D FEC2 680B 1145 00F1 D09E

To claim this, I am signing this object:

troelskn / Rakefile
Created Sep 26, 2014
Simple deployment via ftp
View Rakefile
require 'rubygems'
require 'rake'
require 'ostruct'
require 'fileutils'
module Ftp
def self.invoke(config = {}, &block)
commands = []
commands << "set ftp:list-options -a"
commands << "set ftp:ssl-allow no" if config.disable_ssl
View geoip.rb
require 'ipaddr'
require 'net/http'
require 'uri'
require 'json'
module GeoIP
def self.configuration
@configuration ||= {}
You can’t perform that action at this time.