Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""
Translate a CSV document with a header to a YAML document that is a list of maps.
Uses constant memory and keeps field names in the original order.
"""
import sys
import csv
import yaml # requires PyYAML
@SteelPangolin
SteelPangolin / php-pecl-parsekit-1.3-php56-variadic-fix.patch
Created May 20, 2015 20:26
patch by @Hubbitus for Parsekit on PHP 5.6; see PHP bug #67854
diff -Naur php-pecl-parsekit-1.3.0.orig/parsekit-1.3.0/parsekit.c php-pecl-parsekit-1.3.0/parsekit-1.3.0/parsekit.c
--- php-pecl-parsekit-1.3.0.orig/parsekit-1.3.0/parsekit.c 2014-08-16 21:55:32.000000000 +0400
+++ php-pecl-parsekit-1.3.0/parsekit-1.3.0/parsekit.c 2014-08-18 12:50:05.377165855 +0400
@@ -300,7 +300,7 @@
}
add_assoc_long(return_value, "num_args", ops->num_args);
add_assoc_long(return_value, "required_num_args", ops->required_num_args);
- add_assoc_bool(return_value, "pass_rest_by_reference", ops->fn_flags & ZEND_ACC_PASS_REST_BY_REFERENCE);
+ add_assoc_bool(return_value, "pass_rest_by_reference", ops->fn_flags & ZEND_ACC_VARIADIC);
@SteelPangolin
SteelPangolin / adblock-related-content.txt
Created July 20, 2015 20:48
Adblock filter list for "related content" garbage
@SteelPangolin
SteelPangolin / mkdtemp.php
Created November 29, 2011 23:57
fake mkdtemp() for PHP
<?php
/**
* Create a directory in the system temp directory with a hard-to-predict name.
* Does not have the guarantees of the actual BSD libc function or Python tempfile function.
* @param string $suffix Append to the new directory's name
* @param string $prefix Prepend to the new directory's name
* @return string The path of the new directory.
*/
function mkdtemp($suffix = '', $prefix = 'tmp')
@SteelPangolin
SteelPangolin / etc_init.d_foo
Last active January 20, 2016 19:51
Run socat as a SysV service to write TCP stream contents to a file
#!/bin/bash
### BEGIN INIT INFO
# Provides: foo
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Writes TCP on port 8725 to a file
### END INIT INFO
source /etc/rc.d/init.d/functions
@SteelPangolin
SteelPangolin / Main.hs
Created January 20, 2015 00:51
Install Mac version of UT2004 from PC discs and Mac demo
module Main where
{-
Utility to automatically install and patch the Mac OS X version
of Unreal Tournament 2004 from the Mac demo and patcher
and PC installation disc images and CD key.
Can automatically download the demo and patcher.
see: http://lowetechlabs.com/UT2004-WIN2OSX/
see: http://forums.macnn.com/showthread.php?t=292620
@SteelPangolin
SteelPangolin / EC2-Describe-IAM-policy.json
Created January 30, 2015 21:23
Get an Amazon Elastic Beanstalk environment's name from inside one of its instances
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
@SteelPangolin
SteelPangolin / lsflags.c
Created October 2, 2012 23:48
lsflags: complementary utility to chflags. List flags for Mac OS X files and folders.
// compile with gcc -std=c99 -Wall lsflags.c -o lsflags
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
@SteelPangolin
SteelPangolin / rmtree.php
Created November 30, 2011 00:19
shutil.rmtree for PHP
<?php
/**
* Delete a file or directory recursively.
* @param string $path
*/
function rmtree($path)
{
if (is_dir($path))
{
@SteelPangolin
SteelPangolin / robbyrussell-hostname.zsh-theme
Created October 20, 2015 21:58
Tweak robbyrussell ZSH theme to prepend hostname
local hostname="%{$fg_bold[black]%}%m"
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
PROMPT='${hostname} ${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"