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 iban_converter.inc.php
<?php
class IbanConverter
{
function convert_dk($input) {
// DKkk BBBB CCCC CCCC CC
$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);
$this->iban_replace_checksum($iban);
@troelskn
troelskn / AppServiceProvider.php
Created Feb 23, 2017
Laravel workaround for broken openssl
View AppServiceProvider.php
<?php
// app/Providers/AppServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
@troelskn
troelskn / wphack_payload.php
Created Mar 23, 2016
Partially de-obfuscated payload script from a hacked wp site
View wphack_payload.php
<?php
if (FALSE == nplqy70($u11, $pakfn17)) {
echo PHP_OS . '+' . md5(0987654321) . '+01+[[]]
';
exit;
}
$jkber87 = array();
@troelskn
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
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")
end
end
IO.popen "pbcopy", "w" do |pipe|
View gist:221aec3bfdfd3d86d069
<?php
// 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
<?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";
View keybase.md

Keybase proof

I hereby claim:

  • I am troelskn on github.
  • I am troelskn (https://keybase.io/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
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 ||= {}
end
You can’t perform that action at this time.