Skip to content

Instantly share code, notes, and snippets.

View beyondthewall's full-sized avatar
😆

david beyondthewall

😆
View GitHub Profile

Keybase proof

I hereby claim:

  • I am beyondthewall on github.
  • I am beyond (https://keybase.io/beyond) on keybase.
  • I have a public key ASBJopj94UXr8Xlg1Jfpg_Mr9byHFmv4cWdRLIwXMklfDAo

To claim this, I am signing this object:

@beyondthewall
beyondthewall / openwrt_commands.sh
Last active August 29, 2015 13:56
some practical openwrt config hits and commands
#conditional dns forwarding
uci add_list dhcp.@dnsmasq[0].servers=/example.com/10.85.0.10
uci commit dhcp
/etc/init.d/dnsmasq restart
#wpa2
uci set wireless.@wifi-iface[0].encryption=psk2
uci set wireless.@wifi-iface[0].key="your_password"
uci commit wireless
wifi
@beyondthewall
beyondthewall / remove_old_kernels.sh
Created February 18, 2014 21:45
remove old linux kernels in ubuntu (and maybe debian)
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
@beyondthewall
beyondthewall / install_deps.sh
Created February 18, 2014 21:28
install missing dependencies within your shell script
installdeps()
{
#checking for system
systems="ubuntu arch"
issue="$(cat /etc/issue)"
for item in $systems; do
echo $issue | grep -i $item
if [ $? -eq 0 ]; then
system=$item
fi
@beyondthewall
beyondthewall / mount_qcow2.sh
Created February 18, 2014 21:26
mount a qcow2 image into your filesystem
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 image.qcow2
partprobe /dev/nbd0
mount /dev/nbd0p1 /mnt/image
@beyondthewall
beyondthewall / shell_or_cron.sh
Created February 18, 2014 21:24
find out if your script is run by a interactive shell or a cron job
tty -s
echo $?
@beyondthewall
beyondthewall / connect_to_wlan.sh
Created February 18, 2014 21:22
connect to a secured wireless lan using wpa_supplicant
wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant_socialnerds.conf
sleep 5
dhcpcd wlan0
@beyondthewall
beyondthewall / handy_iptables.sh
Created February 18, 2014 21:19
handy iptables script (this is more a reference than anything else)
#enable IPv4 Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
#Drop IMCP from broadcast multicast
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#Enable TCP SYN Cookie Protection from SYN Floods
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#Don't accept ICMP redirect messages
@beyondthewall
beyondthewall / restart_apache_at_threshold.sh
Created February 18, 2014 21:16
automatically restart apache if you're dealing with a memory leak (which is not fixable atm)
i=1
j=1
threshold=850
while [ 2 -gt 1 ]; do
echo "run count: $i"
sleep 30
mem=$(free -m | grep + | awk '{print $3}')
echo " used memory: $mem"
echo " threshold: $threshold"
if [ $mem -gt $threshold ]; then
@beyondthewall
beyondthewall / gcd.py
Created December 14, 2013 14:44
a function to determine the greatest common divisor.
def gcd(a, b):
a=int(a)
b=int(b)
if a <= 0 or b <= 0:
print "given values may not be less than 1"
exit()
elif a > b:
c = b
else: