Skip to content

Instantly share code, notes, and snippets.

Daniel Beardsley danielbeardsley

Block or report user

Report or block danielbeardsley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danielbeardsley
danielbeardsley / organize.bash
Created May 21, 2014
Script to group and condense my mobile phone pictures after they are synced with Bittorrent Sync
View organize.bash
#!/bin/bash -e
organize_dir() {
date=`date +"(%Y-%m-01) Mobile Photos"`
base_dir="/cygdrive/c/Users/Danny/Documents/Mobile Photos"
dest_dir="$base_dir/$date"
source_dir="$base_dir/$1"
mkdir -p "$dest_dir"
cd "$source_dir"
@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 / csrf.js
Last active Jul 12, 2017
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 Jul 6, 2017
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 / .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');
@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 / compose_connect_middlware.js
Created Jun 22, 2011
Allows easy composition of a chain of connect.js-style middlewares
View compose_connect_middlware.js
// Allows easy composition of a chain of connect.js-style middlewares in node.js
// given:
// function A(req,res,next){}
// function B(req,res,next){}
// composeMiddleware(A,B) will return a function(req,res,next) that passes the request
// through both handlers, just like Connect. If a next() is called with an error
// the call chain is stopped and the error is passed to the topmost next()
// If next() is called with the second parameter set to 'break' "next(null, 'break')"
// The chain is halted and route control is passed back to the original next()
function composeMiddleware(){
@danielbeardsley
danielbeardsley / html_template.js
Created Jun 22, 2011
A template renderer for express.js that processes plain vanilla HTML and has the option to strip newlines.
View html_template.js
// Usage:
// express_app.register('html', htmlRenderer({stripNewlines: true}));
// ...
// express_app.get('/plain', function(req, res){
// res.render('./path_to_html_file');
// })
function htmlRenderer(opt){
var stripNewlines = opt && opt.stripNewlines;
You can’t perform that action at this time.