Skip to content

Instantly share code, notes, and snippets.

View andrewjbennett's full-sized avatar

Andrew Bennett andrewjbennett

View GitHub Profile
@andrewjbennett
andrewjbennett / fake_pokedex_stuff.c
Created April 28, 2019 12:43
A hack to print arbitrary text before any printf'd text.
#include <stdio.h>
////////////////////////////////////////////////////////////////////////
// Fake version of pokedex.c //
////////////////////////////////////////////////////////////////////////
// Pretend this takes in a pokedex...
void detail_pokemon(void) {
printf("Id: #001\n");
printf("Name: Bulbasaur\n");
@andrewjbennett
andrewjbennett / setup_xfce_defaults.sh
Created August 14, 2018 07:28
Set up some sensible default applications for an XFCE4 desktop. Intended for new programmers working on the CSE lab systems.
#!/bin/sh
# Set up some sensible defaults:
# firefox - web browser
# Thunar - file manager
# xfce-terminal - terminal
# gedit - C source files
# eog - bitmaps
# Relevant files where config settings are stored
@andrewjbennett
andrewjbennett / mandel_calc.py
Last active July 4, 2017 12:13
mandelbrot calculator (note: doesn't actually calculate mandelbrots)
MANDEL_MIN = -2
MANDEL_MAX = 2
MANDEL_WIDTH = 4.0 # abs(MANDEL_MIN) + abs(MANDEL_MAX)
"""
Tile coords look like: for n=4
(0,0) (1,0) (2,0) (3,0)
(0,1) (1,1) (2,1) (3,1)
(0,2) (1,2) (2,2) (3,2)
(0,3) (1,3) (2,3) (3,3)
@andrewjbennett
andrewjbennett / structs.c
Created May 9, 2017 06:20
example struct code
#include <stdio.h>
#include <stdlib.h>
struct student {
char name[100];
int age;
};
struct student make_student() {
struct student cur_student;
@andrewjbennett
andrewjbennett / timetables.py
Created April 24, 2017 16:48
Hacky script to generate my possible timetables for next semester, eliminate any that don't meet my requirements, then rank them in order of "goodness".
# Andrew Bennett <andrew.bennett@unsw.edu.au>
# April 2017
# Hacky script to generate my possible timetables for next semester,
# eliminate any that don't meet my requirements, then rank them in
# order of "goodness".
import json
import random
import operator
import itertools
@andrewjbennett
andrewjbennett / vlab-resolution.py
Created February 26, 2017 05:41
Determine the resolution for a series of VNC ports.
"""
Determine the resolution for a series of VNC ports.
Andrew Bennett <andrew.bennett@unsw.edu.au>
Feb 2017
Implementing the protocol from the RFC6143 spec:
https://tools.ietf.org/html/rfc6143
Width and Height:
// Delete an item from a hash table that uses linear probing to deal with collisions.
void delete(HashTable ht, Key k) {
int numSlots = ht->nslots;
Item *data = ht->items; // the actual hash table
int i; // i is a better counter variable name than j
int hashPos = hash(k, numSlots); // the position in the hash table
// probe through the possible slots it could be,
// starting from the value it actually hashed to,
@andrewjbennett
andrewjbennett / output.txt
Created November 9, 2016 11:04
pointer stuff: differences between char* and char[] when used as a stack variable
Looking at variable: str1[]
&str1[]: -> 0xfff42d72 (address)
str1[]: -> 0xfff42d72 (value)
*str1[]: -> 0x41 (dereference)
Looking at variable: str2[]
&str2[]: -> 0xfff42d77 (address)
str2[]: -> 0xfff42d77 (value)
*str2[]: -> 0x41 (dereference)
Looking at variable: strp1
@andrewjbennett
andrewjbennett / snip.sh
Created November 5, 2016 02:28
Takes a screenshot of a selected area, saves to file *and* copies to clipboard.
#!/bin/bash
# A script to take a screenshot, save to a file *and* copy to clipboard.
# Because gnome-screenshot can't do both.
# Assumes you have `gnome-screenshot` and `xclip` installed
# Andrew Bennett <andrew.bennett@unsw.edu.au> 2016-11-05
USERNAME=$(whoami)
#define SONG_BPM 145
/*
// Track 3:
uint16_t notes[] = {
82, 165, 82, 165, 82, 165, 82, 165, 110, 220, 110, 220, 110, 220, 110, 220, 104, 208, 104, 208, 82, 165, 82, 165, 110, 220, 110, 220, 110, 220, 123, 131, 147, 73, 73, 73, 110, 87, 65, 131, 131, 65, 98, 98, 123, 247, 247, 165, 208, 110, 165, 110, 165, 110, 165, 82, 165, 82, 165, 82, 165, 82, 165, 110, 220, 110, 220, 110, 220, 110, 220, 104, 208, 104, 208, 82, 165, 82, 165, 110, 220, 110, 220, 110, 220, 123, 131, 147, 73, 73, 73, 110, 87, 65, 131, 131, 65, 98, 98, 123, 247, 247, 165, 208, 110, 165, 110, 165, 110, 165, 220, 330, 220, 330, 220, 330, 220, 330, 208, 330, 208, 330, 208, 330, 208, 330, 220, 330, 220, 330, 220, 330, 220, 330, 208, 330, 208, 330, 208, 330, 208, 330, 220, 330, 220, 330, 220, 330, 220, 330, 208, 330, 208, 330, 208, 330, 208, 330, 220, 330, 220, 330, 220, 330, 220, 330, 208, 330, 208, 330, 208, 330, 208, 330, 82, 165, 82, 165, 82, 165, 82, 165, 110, 220, 110, 220, 110, 220, 110, 220, 104, 208, 104, 208, 82, 165, 82, 165, 110, 220,