Skip to content

Instantly share code, notes, and snippets.

@danielbeardsley
danielbeardsley / README.md
Last active Feb 1, 2021
Unlimited size uploads in PHP: a minimal demonstration.
View README.md

Unlimited upload size in PHP

a minimal implementation

A demonstration of accepting unlimited-size uploads in PHP. The included server.php pipes the POST body directly to /dev/null and returns a JSON encoded hash of some useful stats. Using this method (streaming from stdin) we are able to accept uploads of any size with little memory overhead.

Setup

Symlink apache config and reload

@danielbeardsley
danielbeardsley / csrf.js
Last active Feb 21, 2020
Dynamically add CSRF protection <input>s to each form on the page immediately before it's submitted. This code uses MooTools, though it would be trivial to remove that dependency or swap with jQuery.
View csrf.js
var CSRF = (function() {
window.addEvent('domready', function() {
/**
* Setup triggers on the .submit() function and the `submit` event so we
* can add csrf inputs immediately before the form is submitted.
*/
$$('form').each(function(form) {
// Ensure all forms submitted via a traditional 'submit' button have
// an up-to-date CSRF input
form.addEvent('submit', function() {
@danielbeardsley
danielbeardsley / README.md
Last active Sep 17, 2019
memcache key analysis
View README.md

List and analyze keys in memcache

# Writes a big file with one line per key
> bash dump_keys.sh > all-the-keys

# Get stats on the state of the whole key list
> cat all-the-keys | perl ./aggregate_keys.pl
count:2228244 size:86.50%  fetched:53.66%  bytesize:1948.7MB

# Let the script know how big your cache is
@danielbeardsley
danielbeardsley / capistrano_create_git_tags.rb
Created Mar 1, 2011
A simple capistrano setup that Auto-creates git tags on deploy, and supports multiple deployment environments
View capistrano_create_git_tags.rb
task :production do
# :deployment variable should match task name
set :deployment, 'production'
set :deploy_to, "/home/user/www/#{application}"
set :branch, "master"
find_and_execute_task("deploy:tags:schedule_creation")
end
task :staging do
# :deployment variable should match task name
@danielbeardsley
danielbeardsley / grepReplace
Created Sep 26, 2011
Shell Script for grep-based search and replace recursively in files
View grepReplace
#!/bin/sh
SEARCH=$1
REPLACE=$2
function ConfirmOrExit() {
echo -n "Continue? (y / n) :"
read CONFIRM
if [ $CONFIRM != 'y' ]
then
exit
@danielbeardsley
danielbeardsley / merge_util.js
Created Mar 15, 2011
Javascript Merge functions: merge, mergeCopy, and mergeDeep (compatible with browsers and nodejs)
View merge_util.js
var util = exports || {};
util.mergeDeep = function (A, B, depth) {
var forever = depth == null;
for (var p in B) {
if (B[p] != null && B[p].constructor==Object && (forever || depth > 0)) {
A[p] = util.mergeDeep(
A.hasOwnProperty(p) ? A[p] : {},
B[p],
@danielbeardsley
danielbeardsley / README.md
Last active Dec 20, 2015
A bash script to temporarily slow down your intertubes on MacOS.
View README.md

slow-it-down

Simulate a slow network connection with one command.

Turn on:

$> sudo ./slow-it-down
Your tubes are now filled with molasses
@danielbeardsley
danielbeardsley / .gitignore
Created Aug 14, 2012
PHP Bug in recursive unserialization
View .gitignore
*.out
a.ser
@danielbeardsley
danielbeardsley / memcache-stats.sh
Created Aug 2, 2012
Pipe memcache stats into Graphite
View memcache-stats.sh
#!/bin/bash
if [ "$1" != "report" ]; then
echo "Usage:" >&2
script="`basename $0`"
echo " nohup $script report > /var/log/memcache-stats.log &" >&2
exit 1
fi
GRAPHITE_SERVER=localhost
@danielbeardsley
danielbeardsley / strict-object-examples.js
Created Oct 21, 2011
Examples of how to use strict-object
View strict-object-examples.js
// https://github.com/danielbeardsley/strict-object
// Create a new person type
var Person = StrictObject.define('name', 'age', 'country');
// Instatiate a Person
var pete = new Person();
// set properties using functions
pete.name('Peter');