Skip to content

Instantly share code, notes, and snippets.

@brycethomas
brycethomas / enter-caps
Created Oct 15, 2017
Run a command with ambient capabilities
View enter-caps
#!/bin/bash
# Run from terminal like enter-caps ./wireshark
export PS1="#$PS1"
export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1
caps=cap_net_admin,cap_net_raw
sudo -E capsh --keep=1 --caps="cap_setuid,cap_setgid,cap_setpcap+ep $caps+eip" --user=[my_hardcoded_username] --addamb="$caps" -- -c "$@"
echo "...Exiting enter-caps"
View monty_hall.py
import random
cars, donkeys = 0, 0
trials = 10000
doors = ['a', 'b', 'c']
for i in range(trials):
# place the car behind a random door
car_door = random.choice(doors)
# choose first door at random
first_choice = random.choice(doors)
@brycethomas
brycethomas / function_pointer_delegates.py
Created Jun 16, 2012
Function pointers up to delegates
View function_pointer_delegates.py
# some button class somewhere that you didn't write.
class Button():
def __init__(self,functionToExecuteOnClick):
self.clickFunction = functionToExecuteOnClick
# does a bunch of other cool stuff to display button - you were too slack to write this code, that's why you're using their button in the first place.
# pretend this is private. other classes shouldn't be calling this method
@brycethomas
brycethomas / gist:1154251
Created Aug 18, 2011
Apples simulator - amended main method and toString() method
View gist:1154251
// prints out something like "Apple 27 (GRANNY_SMITH, 3)"
public String toString() {
return String.format("Apple %d (%s, %s)",size,type,batchNumber);
}
public static void main(String[] args) {
Random random = new Random(); // this is the line missing from the workshop pdf
final int SIZE = random.nextInt(5) + 1;
Apple[] apples = new Apple[SIZE]; // a randomly sized apples array
for (int i = 0; i < SIZE; ++i) {
@brycethomas
brycethomas / gist:1153193
Created Aug 18, 2011
Creating a 2-dimensional array of JButtons and setting the text on them
View gist:1153193
// an array of JButtons
JButton[][] buttons = new JButton[4][4];
/* actually creates each of the sixteen JButton objects and sets
each button's text to look something like "Button [1][2]" (depending on row and column) */
for (int i=0; i < buttons.length; i++) {
for (int j=0; j < buttons[i].length; j++) {
buttons[i][j] = new JButton("Button [" + i + "][" + j + "]");
}
}
@brycethomas
brycethomas / gist:1153191
Created Aug 18, 2011
A 2-dimensional array of JButtons and setting text on them
View gist:1153191
// an array of JButtons
JButton[][] buttons = new JButton[4][4];
/* actually creates each of the sixteen JButton objects and sets
each button's text to look something like "Button [1][2]" (depending on row and column) */
for (int i=0; i < buttons.length; i++) {
for (int j=0; j < buttons[i].length; j++) {
buttons[i][j] = new JButton("Button [" + i + "][" + j + "]");
}
}
View tile_stuff
import httplib2
import StringIO
from PIL import Image
def get_tiles():
h = httplib2.Http('.cache')
base = 'http://www.jcu.edu.au/maps/townsville/interactive/mapimages/'
# get lvl 16 zoom tiles
for x in range(59482, 59486):
for y in range(36353,36357):
View gist:292494
http://blog.sadphaeton.com/2009/01/20/python-development-windows-part-2-installing-easyinstallcould-be-easier.html