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 / Life.lua
Last active June 27, 2024 13:46
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 / 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 / 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 / backup_cloudant_db.sh
Created January 26, 2011 16:48
Quick n' dirty shell script to back up a Cloudant database to a new, uniquely-named Cloudant DB.
#!/bin/sh
CLOUDANT_USER="myusername"
CLOUDANT_PASS="mypassword"
CLOUDANT_DB="mydb"
DATE=`date +"%Y-%m-%d\$%H.%M"`
BACKUP_NAME="${CLOUDANT_DB}_backup_${DATE}"
echo "Creating database named ${BACKUP_NAME}"
#!/bin/sh
# super-simple request per minute statistics from an Apache log file
# watch it live, now with JSON output!
# while [ /bin/true ]; do sh logstats.sh ; sleep 60 ; done
#
LOGFILE=/var/log/apache2/access_log
HOUR=`date +%H`
MIN=`date +%M`
MIN=`expr $MIN - 1`
@phred
phred / permission_hammer.sh
Created December 15, 2009 22:17
Fix Plesk's vhost group permissions nonsense. Stick this in a cron job to make the headaches go away.
#!/bin/sh
#
# A hammer to fix group permissions on Plesk vhosts.
#
# Plesk creates httpdocs directories with correct permissions initially,
# and they work properly over FTP (sort of), however, they require special
# love to let Apache write to them; namely putting Apache in the psacln
# group, making sure that everyone's httpdocs are owned by that group,
# and setting the setgid bit on httpdocs and all of its subdirectories
# so that new directories created by Apache inherit the proper permissions
@phred
phred / default.php
Created December 2, 2009 21:39
Vanilla 2 plugin to maintain Vanilla 1 links after the upgrade.
<?php if (!defined('APPLICATION')) exit();
/*
Copyright 2008, 2009 FoxyCart, LLC
This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this file. If not, see <http://www.gnu.org/licenses/>.
Contact Fred Alger at fred [dot] alger [at] foxycart [dot] com
*/
@phred
phred / transaction.lasso
Created November 20, 2009 07:14
Lasso functions to decode and decrypt a FoxyCart datafeed.
[
Define_Tag('Decode_Raw', -Required='input');
Local('output' = bytes());
Local('ndx' = 1);
While(#ndx < #input->Length);
if(#input->Get(#ndx) == '%');
local: 'byte' = string(#input->Substring(#ndx+1, 2));
@phred
phred / gist:237322
Created November 17, 2009 22:14
init.d script example for controlling a PHP FastCGI pool
#!/bin/bash
# chkconfig: - 85 15
# description: controls the pool of PHP FastCGI daemons used to handle \
# dynamic requests from nginx.
PHP_SCRIPT=/opt/nginx/bin/world_php_fcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
@phred
phred / gist:206267
Created October 9, 2009 19:28
Comment on "advanced Javascript techniques" blog showing a nice way to format HTML-with-JS.
// Comment on http://sixrevisions.com/javascript/6-advanced-javascript-techniques-you-should-know/
pageContainer.innerHTML = array('',
'<h1>' + pageTitle + '</h1>',
'<div id="content">',
' <p>' + pageContent + '</p>',
' <div id="author_bio">',
' <p>' + authorBio + '</p>',
' </div>',
'</div>',