Skip to content

Instantly share code, notes, and snippets.

View apinstein's full-sized avatar

Alan Pinstein apinstein

  • Atlanta, GA
View GitHub Profile
@apinstein
apinstein / pcntl_fork.php
Last active December 14, 2015 03:39
php concurrency with pcntl_fork
$concurrency = 5;
if ($concurrency > 1)
{
print("Starting {$concurrency} workers via pcntl_fork\n");
$childPids = array();
$isMain = true;
foreach (range(1, $concurrency) as $i) {
$pid = pcntl_fork();
if ($pid === -1) throw new Exception("Forking failed.");
if ($pid === 0)
@apinstein
apinstein / heroku_ssl_only.md
Last active December 16, 2020 10:20
Enforce SSL-only (ie disable non-ssl) on Heroku via apache.

The safest way to prevent any non-SSL traffic is to not have your web server listen on http/port 80. This way, people cannot even accidentally transmit sensitive data in an insecure fashion.

Unfortunately Heroku doesn't seem to have a switch to DISABLE non-SSL traffic, but at least we can make the non-SSL traffic die an early death and hopefully minimize the amount of non-SSL traffic ever sent.

With apache, this can be done quickly like so:

    # you might need this
    RewriteEngine On
 
@apinstein
apinstein / gist:4998046
Created February 20, 2013 18:53
thoughts for cron jobs and unix script utilities
# useful for ignoring certain codes (ie rsync 24) when running under set -e
#
# runIgnoringExitCodes 1,2,3 cmd foo bar
#
# be sure to escape the command as needed
#
# runIgnoringExitCodes 1,2,3 "cmd foo bar | grep baz"
#
function runIgnoringExitCodes {
local ignore_codes=(${1//,/ })
@apinstein
apinstein / shell_scripting_best_practices.md
Last active December 14, 2015 00:08
Shell Scripting best practices

Ensure a consistent execution environment

  1. Always start the script with a shebang line

    #!/bin/bash
    
  2. Always run the script directly

@apinstein
apinstein / gist:4480477
Created January 8, 2013 02:13
How to compile custom binary executables for heroku cedar stack. This is example is for ImageMagick.
# Custom ImageMagick build for Heroku via Vulcan
vulcan create vulcan-builder
curl -O http://www.imagemagick.org/download/legacy/ImageMagick-6.7.4-10.tar.gz
tar zxvf ImageMagick-6.7.4-10.tar.gz
vulcan build -v -s ./ImageMagick-6.7.4-10 -c "./configure --prefix /app/vendor/ImageMagick-6.7.4-10 '--disable-shared' '--with-quantum-depth=8' '--with-lcms' '--with-gslib' --'with-fontconfig' && make install" -p /app/vendor/ImageMagick-6.7.4-10
# ==> downloads output to /tmp/ImageMagick-6.7.tgz
cd /path/to/project
@apinstein
apinstein / gist:1601324
Created January 12, 2012 16:05
mp-helper.php; calculate all migration re-sequencing
<?php
$fromBranch = 'master';
$toBranch = 'videoClips-integration';
// find common ancestor
$commonAncestor = commonAncestor($fromBranch, $toBranch);
print "Common ancestor of {$fromBranch}..{$toBranch} is {$commonAncestor}\n";
<?php
manifest(array(
"pear", "apinstein.pearfarm.org/mp", "1.0.2",
));
@apinstein
apinstein / gist:1281741
Created October 12, 2011 16:34
Redirecting STDOUT and STDERR for complex shell commands
#!/bin/sh
echo ">> STDOUT and STDERR"
(echo 'this is stdout' && this_is_stderr)
echo ">> STDERR only"
(echo 'this is stdout' && this_is_stderr) 1> /dev/null
echo ">> STDOUT only"
(echo 'this is stdout' && this_is_stderr) 2> /dev/null
echo ">> NOTHING"
(echo 'this is stdout' && this_is_stderr) > /dev/null 2>&1
@apinstein
apinstein / gist:1281740
Created October 12, 2011 16:34
Redirecting STDOUT and STDERR for complex shell commands
(echo 'this is stdout' && this_is_stderr)
(echo 'this is stdout' && this_is_stderr) 1> /dev/null
(echo 'this is stdout' && this_is_stderr) 2> /dev/null
(echo 'this is stdout' && this_is_stderr) > /dev/null 2>&1
@apinstein
apinstein / gist:1266375
Created October 6, 2011 02:55
librets valgrind output
$ export USE_ZEND_ALLOC=0; valgrind --tool=memcheck --num-callers=30 --leak-check=full --show-reachable=yes [rets php script]