Skip to content

Instantly share code, notes, and snippets.

View phred's full-sized avatar
🌴
On vacation

Fred Alger phred

🌴
On vacation
View GitHub Profile
@phred
phred / unserialize.php
Created September 7, 2011 19:04
Simple reliable and non-regex method to unserialize PHP session data
//
// This is the result of about an hour's delving into PHP's hairy-ass serialization internals.
// PHP provides a session_decode function, however, it's only useful for setting the contents of
// $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its
// session files -- session_decode gets you nowhere.
//
// There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular
// expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse
// through the string extracting all of the serialized bits along the way.
//
@phred
phred / caveatPatchor.js
Created October 6, 2011 17:31 — forked from protocool/caveatPatchor.js
caveatPatchor.js with barebones oohembed (now embedly?!) support for Propane 1.1.2 and above
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
@phred
phred / Life.lua
Last active September 27, 2015 23:08
Conway's Game of life for Codea
-- Size of the board, 40 is nice and fast 
-- 100 is doable but only runs at 3 fps with current board algorithm
-- 10 is fun and good for making sure everything works
-- 40 is ideal
Size=40
Generation=0
World = { cols=Size, rows=HEIGHT/(WIDTH/Size), last=0.0 }
Cell = { size = WIDTH/World.cols, color=color(0, 62, 255, 255) }
Directions = {
@phred
phred / trees.lua
Created November 13, 2011 00:56 — forked from npryce/trees.lua
Random Trees for Codea
-- Use this function to perform your initial setup
function setup()
   seed = 1
    iparameter("depth", 1, 15)
    depth = 10
    parameter("length", 0, 300)
    length = 120
    parameter("angle", 1, 90)
@phred
phred / pedantically_commented_playbook.yml
Last active November 3, 2023 01:55
Very complete Ansible playbook, showing off all the options
---
####
#### THIS IS OLD AND OUTDATED
#### LIKE, ANSIBLE 1.0 OLD.
####
#### PROBABLY HIT UP https://docs.ansible.com MY DUDES
####
#### IF IT BREAKS I'M JUST SOME GUY WITH
#### A DOG, OK, SORRY
####
@phred
phred / discounts.factor
Last active October 11, 2015 08:08
EBNF for FoxyCart discount strings
USE: peg.ebnf
#! throw this in the listener to see the example parse tree
"discount_quantity_amount=Discount_Name{repeat|1-5.42|2-5|6-0}"
[EBNF
number = [0-9]+ => [[ string>number ]]
amount = number ("." number)?
type = "allunits" | "incremental" | "repeat" | "single"
@phred
phred / tiny.markdown
Created October 14, 2012 12:30
Solving Embarrasingly Simple Problems in Factor

Solving Embarrasingly Simple Problems in Factor

This Article has struck a chord with me. I'm not an Erlang-er, but the style he describes of "writing many tiny functions" strongly reminds me of why I've come to love Factor.

Drink Beer when Delicious

@phred
phred / config.fish
Created October 23, 2012 18:06
phred's config.fish
if status --is-login
# Use universal variables to replace globals, this lets set -Ux change PATH and LANG forever
set -ge PATH
set -gx PATH $PATH
set -ge LANG
set -gx LANG $LANG
function e
emacsclient -n $argv
@phred
phred / extract_vulns.py
Created November 1, 2012 18:10
Extract Ubuntu Vulnerabilities into a easy to copy/paste text form
#!/usr/bin/env python
# Usage: python extract_vulns.py <url>
# Bog-simple screen scraping, will fail unless URL is something like this:
# http://www.ubuntu.com/usn/lucid/
# http://www.ubuntu.com/usn/lucid/?page=3
#
from BeautifulSoup import BeautifulSoup
import requests, time, sys
@phred
phred / ConfigParser.php
Created November 16, 2012 20:45
Simple PHP class wrapper for reading configuration from ini files
<?php
class ConfigParser {
function __construct($ini_file) {
$this->data = parse_ini_file($ini_file, true);
if ($this->data === FALSE) {
throw new Exception("Error reading file {$ini_file}");
}
}
function sections() {