Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
#!/bin/bash
echo '#!/bin/bash'
echo ''
echo 'failed_items=""'
echo 'function install_package() {'
echo 'echo EXECUTING: brew install $1 $2'
echo 'brew install $1 $2'
echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.'
echo '}'
@amosshapira
amosshapira / restore-vagrant-key
Created July 9, 2015 07:15
Restore Vagrant authorized_keys on a Vagrant box
#!/bin/bash
MACHINE=$1
# Assume executing in the directory of the Vagrant file
# This command will prompt for the Vagrant user's password, it's usually "vagrant"
ssh-keygen -y -f .vagrant/machines/$MACHINE/virtualbox/private_key | \
vagrant ssh $MACHIME -c "mkdir .ssh; tee -a .ssh/authorized_keys; chmod 0600 .ssh/authorized_keys"
@amosshapira
amosshapira / find-next-power-of-2.c
Last active August 29, 2015 14:27
return next power of 2 larger than i
// If "i" is already power of 2 then return it. Skip this step if want
// the next power of 2 for this case
if (! (i & i-1)))
return i; /* i is already a power of 2 */
// this "do" assumes that the previous "if" exists, otherwise replace the
// "do..while" with a simple "while"
do
i &= i-1;
while (i & (i-1));
#!/usr/bin/ruby
require 'rubygems'
require 'packetfu'
dev = ARGV[0]
mac=`ip link show #{dev} | awk '/ether/ {print $2}'`
ARGV.shift
dests = ARGV
cap = PacketFu::Capture.new(
@amosshapira
amosshapira / ec2_multicast.sh
Last active September 3, 2015 01:18 — forked from kntyskw/ec2_multicast.sh
Script to enable IP multicast without using Ethernet broadcast. It uses tc mirred and pedit actions to copy and edit an IP multicast packet to send over multiple Ethernet unicast frames. It requires two network interfaces to work. One is the interface to grab original multicast packets from and the other is to send out modified packets. This is …
#!/bin/sh
[[ -n "$1" && -n "$2" ]] || { echo "Usage: $0 <interface to grab multicast packets from> <interface to send modified packets to> [target MAC address 1] [target MAC address 2] ..."; exit 0 ; }
IIF=$1
OIF=$2
shift
shift
SRC_MACADDR=`ip link show $OIF | awk '/ether/ {print $2}' | tr -d :`
@amosshapira
amosshapira / trust-all-gpg-keys
Created September 28, 2015 02:21
Set maximum owner trust on all public gpg keys in the keyring
#!/bin/bash
gpg --list-keys --fingerprint | \
gsed -r -n -e 's/Key fingerprint = (.*)/\1/p' | \
tr -d ' ' | \
sed -e 's/$/:6:/' | \
gpg --import-ownertrust
@amosshapira
amosshapira / gist:48a74717c9f9600df332
Created November 7, 2015 00:06
How to disable 408 Request Timeout in CherryPy
cherrypy.server.socket_timeout = 0
@amosshapira
amosshapira / sendRawEth.c
Created November 7, 2015 04:07 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@amosshapira
amosshapira / 0_reuse_code.js
Created November 11, 2015 01:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@amosshapira
amosshapira / clear-sensu-puppet-apt-lists
Created November 18, 2015 00:28
Fetch all Sensu clients with Puppet alerts then delete puppetlabs apt repo indexes
#!/bin/bash
TTY=$(tty)
curl -s http://status.int.covata.com:4567/results |
jq -r '.[] | select(.check.output | startswith("PuppetLastRun WARNING:")) | .client' |
while read HOST
do
echo ====== "$HOST" ======
IP=$(curl -s http://status.int.covata.com:4567/clients/"$HOST" | jq -r '.address')