Skip to content

Instantly share code, notes, and snippets.

View cypres's full-sized avatar

Hans Arnholm cypres

View GitHub Profile
@cypres
cypres / baraction.sh
Created January 3, 2021 23:29
baraction.sh script for spectrwm status bar
#!/bin/bash
# baraction.sh script for spectrwm status bar
print_backlight() {
if [ -e /sys/class/backlight/intel_backlight/brightness ]; then
BL=$(oled-backlight current)
echo -n " BL:$BL%"
else
echo -n " BL:Unknown"
fi
@cypres
cypres / race.go
Last active August 28, 2019 12:30
libheif segfault reproduce script
package main
import (
"flag"
"image"
"io/ioutil"
"log"
"sync"
"github.com/strukturag/libheif/go/heif"
@cypres
cypres / gatewayapi.php
Last active April 7, 2017 12:03
WHMCSnow integration with GatewayAPI.com
<?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() {
#!/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
@cypres
cypres / mosh.py
Last active December 13, 2015 20:53
Workaround mosh wrapper
#!/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')
@cypres
cypres / pf.conf
Created October 14, 2015 12:37
NPF Firewall Config
# 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
@cypres
cypres / norm.shar
Created June 25, 2015 16:50
norm FreeBSD port
# 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
@cypres
cypres / protoSocket.diff
Created June 25, 2015 13:56
Patches for protolib
--- 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>
@cypres
cypres / cidr_trim.cc
Created May 28, 2015 09:49
Trim a CIDR string to make it compatible with inet_net_pton
#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
@cypres
cypres / smslen.cc
Last active August 29, 2015 14:20
Sample code to count number of chars in a SMS
#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.