Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Enders joshenders

View GitHub Profile
@joshenders
joshenders / function.sh
Last active Aug 29, 2015
rvm/extras/bash_zsh_support/chpwd/function.sh
View function.sh
__zsh_like_cd()
{
# Called as:
# cd() { __zsh_like_cd cd "$@" ; }
# popd() { __zsh_like_cd popd "$@" ; }
# pushd() { __zsh_like_cd pushd "$@" ; }
# So, "$@" in __zsh_like_cd contains the __zsh_like_cd "personality" as well as passed arguments
\typeset __zsh_like_cd_hook # define local variable in __zsh_like_cd scope, may be POSIXly correct but lol- #! is /bin/bash, use "local __zsh_like_cd_hook". Also, hilarious that they prepend \ to typeset because who knows if you can trust that it's not hooked!
if
builtin "$@" # builtin returns true if command is a built-in
View gist:3bbd2e4d86d0f9553ca0
jenders@jenders-mba tmp :) $ cat ./foo.sh
#!/bin/bash
echo "\$@: $@"
flags=()
for flag in "$@"; do
if [[ "${flag}" =~ ^- ]]; then
flags=("${flags[@]}" "${flag}")
fi
View stats-by-country.py
#!/usr/bin/python3.4
import math
import statistics as stats
import signal
import sys
from os.path import basename
# Hide stack trace from KeyboardInterrupt
View gist:9f197896b1c05676ab6f
[root@dev-aje:~]# apt-cache --help | grep -- depends
depends - Show raw dependency information for a package
rdepends - Show reverse dependency information for a package
[root@dev-aje:~]# apt-cache depends libpng12-0
libpng12-0
Depends: libc6
Depends: zlib1g
PreDepends: multiarch-support
Conflicts: libpng12-dev
Conflicts: <mzscheme>
View gist:2a7a7b00dc644a72b7a1
#!/bin/bash
# for each list of nodes in ISP metadata list
for country in metadata/by-isp/*; do
ccode="$(basename ${country})"
echo "${ccode}"
mkdir "by-isp/${ccode}"
# from node list for each country, create file with only tests from said country
pattern=$(awk '{ print $2 }' "${country}" \
View gist:421526ae868c0f4bea78
>>> a = "1.0"
>>> int(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.0'
>>> int(float(a))
1
>>> foo = "1.0"
>>> int(foo)
Traceback (most recent call last):
@joshenders
joshenders / sshrc
Created Mar 13, 2015
/etc/ssh/sshrc to fix X11 Forwarding on Debian
View sshrc
if read proto cookie && [ -n "$DISPLAY" ]; then
if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then
# X11UseLocalhost=yes
echo add unix:`echo $DISPLAY |
cut -c11-` $proto $cookie
else
# X11UseLocalhost=no
echo add $DISPLAY $proto $cookie
fi | xauth -q -
fi
View gist:d1538f93b857371c926b
def params_to_dict(param_str):
splits = param_str.split(" ")
data = {}
prev_key = None
prev_val = None
for s in splits:
if "=" in s:
key, val = s.split("=")
if prev_key:
View setxattrs.c
/*
setxattrs - bubbaATbubba.org
Properly sets sparse bundle extended attributes lost when rsyncing
sparse bundle data to a platform that does not support extended
attributes. This is only need when restoring/retrieving the
bundle.
To use, sync/copy all bundle files, then run this tool on the
sparse bundle:
@joshenders
joshenders / libhttpd.c.patch
Created Feb 8, 2015
X-Forwarded-For patch for thttpd-2.26
View libhttpd.c.patch
--- libhttpd.c 2014-12-10 12:53:07.000000000 -0800
+++ libhttpd.c.patched 2015-02-07 22:44:59.183663432 -0800
@@ -2231,6 +2231,12 @@
if ( strcasecmp( cp, "keep-alive" ) == 0 )
hc->keep_alive = 1;
}
+ else if ( strncasecmp( buf, "X-Forwarded-For:", 16 ) == 0 )
+ { // Use real IP if available
+ cp = &buf[16];
+ cp += strspn( cp, " \t" );