Skip to content

Instantly share code, notes, and snippets.

@BlakeGardner
BlakeGardner / routes.php
Last active March 1, 2019 19:31
Security vulnerability in Laravel’s URL validator
<?php
/**
* Imagine if this came from the request or a database entry editable by the user.
* The Laravel URL validator relies on PHP's filter_var() method which considers
* file:// and php:// valid URLs. The vast majority of Laravel users probably
* expect this validator to only validate http:// & https://
* @link http://www.php.net/manual/en/wrappers.php
*/
@BlakeGardner
BlakeGardner / supervisord.conf
Created February 20, 2014 19:09
My Supervisor configuration
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001 ; (ip_address:port specifier, *:port for all iface)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
@BlakeGardner
BlakeGardner / Laravel 4.0.x.php
Last active August 29, 2015 13:56
Laravel log file changes
<?php
# /app/start/global.php
/*
This results in several dated log files
/app/storage/logs/log-apache2handler-2014-02-02.txt
/app/storage/logs/log-apache2handler-2014-02-03.txt
@BlakeGardner
BlakeGardner / compact.js
Last active October 10, 2024 11:19
Compact all collections inside of a MongoDB database
// This script loops though the list of collection names in a MongoDB and runs the compact operation on them
// Simply paste this into the Mongo shell
use testDbName;
db.getCollectionNames().forEach(function (collectionName) {
print('Compacting: ' + collectionName);
db.runCommand({ compact: collectionName });
});
@BlakeGardner
BlakeGardner / install.sh
Last active December 21, 2015 01:08
Install gearman on CentOS with cpanel
wget http://dl.fedoraproject.org/pub/epel/6/SRPMS/gearmand-1.1.8-2.el6.src.rpm
yum install rpm-build libuuid-devel boost-devel boost-thread sqlite-devel tokyocabinet-devel libevent-devel libmemcached-devel memcached gperf postgresql-devel gperftools-devel
rpmbuild --rebuild ~/gearmand-1.1.8-2.el6.src.rpm
rpm -Uhv ~/rpmbuild/RPMS/x86_64/*.rpm
service gearmand start
@BlakeGardner
BlakeGardner / something.php
Created July 15, 2013 16:46
PHP SOMETHING challenge
Saw this interesting PHP Challenge.
Replace SOMETHING so that the output is Hello World.
if (SOMETHING) {
echo "Hello";
} else {
echo "World";
}
@BlakeGardner
BlakeGardner / install gearman.sh
Last active April 25, 2017 07:03
How to compile and install the Gearman PECL extension on CentOS release 5.9
# Install IUS and EPEL yum repos
wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/epel-release-5-4.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/ius-release-1.0-11.ius.centos5.noarch.rpm
rpm -i ius-release-1.0-11.ius.centos5.noarch.rpm epel-release-5-4.noarch.rpm
# make sure your system is up to date for good measure
yum update
# Install the required packages
yum install libgearman-devel php53u-devel gcc
@BlakeGardner
BlakeGardner / benchmark.php
Last active February 13, 2018 17:47
Benchmark of all the hashing algorithms provided by PHP
<?php
foreach (hash_algos() as $algo) {
$start_time = microtime(TRUE);
for ($index = 0; $index <= 500000; $index++) {
$hash = hash($algo, $index);
}
@BlakeGardner
BlakeGardner / sample output
Last active December 18, 2015 14:49
Generate a change log automatically with git
#!/bin/bash
# Generate a changelog between the v1 and v2 tags
# See the "pretty formats" section of the git manual if you want to customize the output: https://www.kernel.org/pub/software/scm/git/docs/git-log.html
git log --no-merges --format="%an: %s" v1..v2
@BlakeGardner
BlakeGardner / range.php
Created June 4, 2013 01:17
Simple implementation of range as a generator
<?php
$data = range(0, 1000000);
echo sprintf('%02.2f', (memory_get_usage() / 1048576))." MB of memory used\n";
// output: 137.92 MB of memory used
foreach ($data as $key => $val) {
//echo "key: ".$key." value: ".$val."\n";