Skip to content

Instantly share code, notes, and snippets.

Hans Duedal duedal

Block or report user

Report or block duedal

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
@duedal
duedal / gatewayapi.php
Last active Apr 7, 2017
WHMCSnow integration with GatewayAPI.com
View gatewayapi.php
<?php
// This is untested code
class smsGateway_gatewayapi {
public $apifields = array(
'apitoken' => array("FriendlyName" => "API Token", "Type" => "text", "Size" => "64", ),
'senderid' => array("FriendlyName" => "Sender ID", "Type" => "text", "Size" => "15", ),
);
function sendSMSMessage() {
View pg-travis-test.sh
#!/bin/bash
set -eux
sudo apt-get update
packages="postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-common"
# bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de
sudo update-alternatives --remove-all postmaster.1.gz
@duedal
duedal / mosh.py
Last active Dec 13, 2015
Workaround mosh wrapper
View mosh.py
#!/usr/bin/env python3
import subprocess
import argparse
import re
import os
parser = argparse.ArgumentParser(description='Mosh connection tool.')
parser.add_argument('target', metavar='target', type=str, help='the SSH target')
parser.add_argument('--port', type=int, default=22, help='the SSH port')
parser.add_argument('--new', help='Open a new session', action='store_true')
@duedal
duedal / pf.conf
Created Oct 14, 2015
NPF Firewall Config
View pf.conf
# Max 3 mio states
set limit states 3000000
# Adaptive state timeouts
set timeout { adaptive.start 400000, adaptive.end 3000000 }
# Own Traffic (front net does not route)
nat on ix0 from 212.98.89.24/30 -> 212.98.117.0/25 round-robin
# NAT NPF traffic with source hashing
# Use a static random hash to keep public IP across firewall changes/reloads
@duedal
duedal / norm.shar
Created Jun 25, 2015
norm FreeBSD port
View norm.shar
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# norm
# norm/distinfo
# norm/Makefile
@duedal
duedal / protoSocket.diff
Created Jun 25, 2015
Patches for protolib
View protoSocket.diff
--- protolib/src/common/protoSocket.cpp.orig 2015-06-25 13:43:52 UTC
+++ protolib/src/common/protoSocket.cpp
@@ -6,6 +6,7 @@
#ifdef MACOSX
#include <arpa/nameser.h>
#endif // MACOSX
+#include <netinet/in.h>
#include <resolv.h>
#endif // HAVE_IPV6
#include <sys/ioctl.h>
@duedal
duedal / cidr_trim.cc
Created May 28, 2015
Trim a CIDR string to make it compatible with inet_net_pton
View cidr_trim.cc
#ifdef __FreeBSD__
#include <sys/socket.h>
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <algorithm> // find, find_if_not, reverse_copy, for_each
#include <functional> // bind1st, std::equal_to
#include <string> // string
#include <iostream> // cout
@duedal
duedal / smslen.cc
Last active Aug 29, 2015
Sample code to count number of chars in a SMS
View smslen.cc
#include <cassert> // cassert
#include <cmath> // ceil
#include <iostream> // cout
#include <cstring> // memset, memcpy
// Given a UTF-8 encoded string, calculate the length of the resulting GSM
// 03.38 converted string.
// It assumes the input is valid UTF-8 and UTF-8 chars that can not be
// represented will be replaced with a single ? char.
// High optimized code, runs best with clang and optimizations (-O) enabled.
@duedal
duedal / Makefile.diff
Created Apr 16, 2015
Modified uWSGI Makefile to support multiple python version in same binary
View Makefile.diff
diff -u /var/portshaker/freebsd/www/uwsgi/Makefile /var/portshaker/ocrepo/www/uwsgi/Makefile
--- /var/portshaker/freebsd/www/uwsgi/Makefile 2015-03-17 12:00:14.000000000 +0100
+++ /var/portshaker/ocrepo/www/uwsgi/Makefile 2015-04-16 19:47:51.000000000 +0200
@@ -12,20 +12,36 @@
LICENSE= GPLv2
LICENSE_FILE= ${WRKSRC}/LICENSE
-USES= python
+USES= python:2.7
USE_RC_SUBR= uwsgi
@duedal
duedal / UIImageExt.swift
Created Mar 16, 2015
UIImage from UIImagePickerController resize + fix orientation
View UIImageExt.swift
import UIKit
extension UIImage {
// Based on http://stackoverflow.com/a/1262395/449607
// Optimized for JPEG output
func imageResized(longEdge : CGFloat) -> UIImage {
func radians (degrees : Double) -> CGFloat {
return CGFloat(degrees * M_PI/180)
}
You can’t perform that action at this time.