Skip to content

Instantly share code, notes, and snippets.

@hcooper
hcooper / random-password.php
Created September 19, 2012 20:23
PHP script to generate random passwords via apg
<?php
/* PHP script using apg to generate random passwords
*
* Requires: apg
* Suggested: rng-tools (to keep entropy high)
*
* Stick this in your apache/htaccess to support custom lengths
* via domain.com/12
*
@hcooper
hcooper / pound_sslv2_compression.patch
Created October 8, 2012 11:03
Disable SSLv2 and SSL Compression support in Pound.
--- config.c.orig 2012-10-05 14:57:53.000000000 +0100
+++ config.c 2012-10-08 10:29:55.523951240 +0100
@@ -1136,6 +1136,13 @@
SSL_CTX_set_app_data(pc->ctx, res);
SSL_CTX_set_mode(pc->ctx, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_options(pc->ctx, ssl_op_enable);
+
+ /* Disable compression and SSLv2 support
+ * this code isn't very portable as it presumes your OpenSSL version
+ * supports both these options, when many older versions don't. */
@hcooper
hcooper / syslog_convert.py
Created October 19, 2012 16:58
syslog priority converter
# Convert encoded syslog values into human-friendly facility and level names
severity_map = {
0: 'emergency', 1: 'alert', 2: 'critical', 3: 'error',
4: 'warning', 5: 'notice', 6: 'informational', 7: 'debug'
}
facility_map = {
0: 'kernel', 1: 'user', 2: 'mail', 3: 'daemon',
4: 'auth', 5: 'syslog', 6: 'lpr', 7: 'news', 8: 'uucp',
@hcooper
hcooper / koken-upload.py
Last active March 5, 2021 14:47
Upload photos to a koken gallery from the command line
# v1.0 of a command line uploader for the koken gallery software.
# The only non-standard requirement is pyton-requests.
import json
import requests
import os
from urllib import quote as quote
api_url = "http://yourdomain/api.php?"
common_headers = {'X-Koken-Auth':'cookie'}
@hcooper
hcooper / [koken] extract_classname.diff
Last active August 8, 2019 14:41
Koken depends on the positional output of get_declared_classes(), which can not be guaranteed. This extract the class name from the plugin instead.
diff --git a/app/application/libraries/shutter.php b/app/application/libraries/shutter.php
index 6308d6c..58f7127 100755
--- a/app/application/libraries/shutter.php
+++ b/app/application/libraries/shutter.php
@@ -68,6 +68,18 @@ class Shutter {
return $json;
}
+ // tokenize a given file, and extract the class name
+ public static function extract_classname($file) {
@hcooper
hcooper / [koken] disable_Content-Length.diff
Last active August 29, 2015 14:03
Koken calculates and returns a Content-Length header, regardless of the server is going to compress/chunk the response.
commit 74ae5fa6e841bbe1092cf6262fb6031b44fa9b4c
Author: Hereward Cooper <[email protected]>
Date: Mon Jul 14 14:46:17 2014 -0700
disabling content-length header
diff --git a/i.php b/i.php
index a6c704e..52446b2 100755
--- a/i.php
+++ b/i.php
commit e4b016d2cc93a3231eb55a9d3a8f16c8302c5488
Author: Hereward Cooper <[email protected]>
Date: Mon Jul 14 16:33:37 2014 -0700
switch from imagemagick to gd
diff --git a/storage/configuration/user_setup.php b/storage/configuration/user_setup.php
index 92e54db..ced961b 100755
--- a/storage/configuration/user_setup.php
+++ b/storage/configuration/user_setup.php

Running Koken on HHVM

There's only three steps required to make Koken 0.15.0 work on HHVM:

  1. Koken's plugin support depends on the output of get_declared_classes() matching the order the that classes were defined - which can't be guaranteed. The best solution for this would be to ensure plugins were named the same as their classes, but until they do, this patch parses the plugin for the class name: https://gist.github.com/hcooper/a978a1328da787deb390

  2. In i.php Koken hard-codes a Content-Length header, which causes requests to hang when responses are gzip'ed, (as declared length != actual length). In this diff we just removed the header and let the webserver decided what to do instead (i.e. in most cases return chunked-content rather than set length): https://gist.github.com/hcooper/a1c7a882914679a0ccc9

  3. BONUS - switch Koken from using ImageMagick to GD instead (GD support is built into HHVM): https://gist.github.com/hcooper/081bc779d374eefa7293

@hcooper
hcooper / fix-vidstab-kdenlive
Created December 19, 2014 16:22
fix video stabilization in kdenlive
--- /tmp/kdenlive-0.9.10/src/project/projectlist.cpp 2014-10-05 10:55:35.000000000 +0100
+++ src/project/projectlist.cpp 2014-12-19 16:05:33.906585717 +0000
@@ -3648,9 +3648,10 @@
// producer params
preParams << jobParams.takeFirst();
// filter name
- preParams << jobParams.takeFirst();
+ QString filterName = jobParams.takeFirst();
+ preParams << filterName;
// filter params
@hcooper
hcooper / whereizip
Created November 3, 2015 07:43
icanhazip.com style geolocation
curl -s http://ip-api.com/csv | cut -d , -f 3