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 / 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 / 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 / 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)
# just a png
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
96.99 35.865105 18768 1911 256 futex
0.55 0.203601 461 442 poll
0.53 0.197358 49 3990 gettimeofday
0.46 0.171303 10706 16 select
0.24 0.088853 100 890 semop
0.24 0.087636 198 443 writev
0.20 0.072347 164 441 times
@apinstein
apinstein / gist:5264406
Created March 28, 2013 16:02
Emergency devops
# manually ban IP's (to a named iptables chain)
iptables -nL
iptables -A fail2ban-apache-badbots -p all -s 74.117.180.16 -j DROP
@apinstein
apinstein / shef tips
Last active December 16, 2015 08:09
Using shef (with chef-solo) to debug chef runs
# from inside a "chef-managed" instance (in this case, vagrant)
sudo shef -s -j /tmp/vagrant-chef-1/dna.json -c /tmp/vagrant-chef-1/solo.rb
=> will have nothing in the run list, but all cookbooks loaded.
=> http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/
# add recipe from source
load_recipe "apache2::mod_fastcgi"
# run chef...
run_chef
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial timeout="15">404-461-9639</Dial>
<Say>Hello, you have reached Tourbuzz. Please leave us a message and we will get back to you as soon as possible.</Say>
<Record transcribe="true" transcribeCallback="http://twimlets.com/[email protected]"/>
</Response>
in file.scss:
@import "tourbuzz-layout-images/*.png";
@include all-tourbuzz-layout-images-sprites;
...
@media screen and (max-width: 1023px) {
...
.main-nav-toggle { @include tourbuzz-layout-images-sprite(main-nav-toggle); }
}
generates err:
@apinstein
apinstein / gist:5528179
Created May 6, 2013 21:03
how to configure a raspberry pi for wpa2 personal wifi
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
# disable the manual setup
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
; Enable xdebug extension module
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable = true
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
; To generate TRACES of script execution; see http://www.xdebug.org/docs/execution_trace
; this will happen ALWAYS (or set to 0 and use xdebug_start_trace; sadly no XDEBUG_XXX method to enable this via URL)
;xdebug.auto_trace=1