Skip to content

Instantly share code, notes, and snippets.

@joshkunz
joshkunz / example.go
Last active August 27, 2015 02:50
Newlines in go.
type thing struct {
a, b int
c string
d uint
}
// this is valid go (in a function context)
v := thing{ a: 0,
b: 0,
@joshkunz
joshkunz / _readme.md
Last active August 29, 2015 13:55
Canvas subscription script.

Here's the script I wrote that automatically subscribes you to all forum threads. It's built to be run as a cron job.

You'll need to generate an API token for it which can be done at the bottom of the [profile settings page][profile]. It uses canvas's REST API to do the actual subscribing, the documentation for the api [is here][capi].

I also hate Canvas's WYSIWYG editor, so I wrote some scripts to render markdown, and then inline the styles. Typically I'll write my posts in a text file, and then run:

$ fpost name_of_file.md | pbcopy    # pbcopy is an OSX thing, xclip -in works for xwindows.

and then just post the raw HTML into the WYSIWYG's 'html entry' portion.

@joshkunz
joshkunz / mpd-fileaccess_v0.19.9.patch
Last active August 29, 2015 14:01
Patch for mpd tag v0.19.9 that allows unauthenticated users to enque files using the `file://' url scheme as long as the MPD daemon is able to read the files.
diff --git a/src/client/ClientFile.cxx b/src/client/ClientFile.cxx
index 3ea8034..0f75907 100644
--- a/src/client/ClientFile.cxx
+++ b/src/client/ClientFile.cxx
@@ -33,32 +33,23 @@ Client::AllowFile(Path path_fs, Error &error) const
#ifdef WIN32
(void)path_fs;
- error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
+ error.Set(ack_domain, ACK_ERROR_PERMISSION, "Not Implemented.");
@joshkunz
joshkunz / Makefile
Created August 8, 2014 22:43
A simple `qmv` implementation. Given a list of files as arguments, this program will open up a file in $EDITOR with one line per argument. You edit the file names, and then when you quit, the files are re-named according to their corresponding lines in the edited file.
.PHONY: clean
CFLAGS = -Wall -Wextra -Wpedantic -Werror
bin = qmv
$(bin):
clean:
rm $(bin)
@joshkunz
joshkunz / sat_ops.c
Created September 22, 2014 07:42
Arbitrary bit-width saturing addition and subtraction operations. Created for regher's Advanced Embedded Systems class.
#include "sat_ops.h"
#include <stdio.h>
/* Note: This code assumes that sizeof(myuint) == sizeof(myint). This assumption
* is made because the comment at the top of 'sat_ops.h' says that each pair
* will be in effect at the same time. I am sacrificing robustness to acheive
* a smaller footprint. */
#define UMIN ((myuint) 0)
#define UMAX ((myuint) (~UMIN))

The file decide.py contains the code necessary to call your C DECIDE function from python code. I wrote this to try and facilitate easier fuzzing of my team's DECIDE implementation. If you have any questions about the setup or usage feel free to ask on the forums. Also, I've tried to add at least a little documentation to decide.py so you can always try checking in there as well.

Setup

Before I explain the interface in detail, I need to explain how to generate a

@joshkunz
joshkunz / t.py
Last active August 29, 2015 14:14
Code to generate a map between pairs of pre-2011 SSNs.
import random
import sys
L_AREA = 649
H_AREA_LOW = 700
H_AREA = 29
A_SIZE = L_AREA + H_AREA
G_SIZE = 99
S_SIZE = 9999
@joshkunz
joshkunz / ssn2.py
Created February 5, 2015 04:57
A new ssn generator
# SSNPad.py - creates a SSN scratch pad. This is used to map one SSN value to
# a random replacement value. Useful to protect a SSN number while preserving
# the format of the data. Reasonably secure if the scratch pad is kept secure.
# This script creates a text file with the following structure:
# XXXXXXXXX|YYYYYYYYY
# where XXXXXXXXX is the source SSN and
# YYYYYYYYY is a psuedo(semi)-random alternate SSN
# Sample:
@joshkunz
joshkunz / ex.py
Created March 30, 2015 15:58
Python name mangling fun
class foo:
__local = 10
def local(self): return self.__local
def test(self, bar): return self.__local, bar.__local
class empty:
pass
ei= empty()
ei.__local = "hello from empty"
f = foo()
@joshkunz
joshkunz / fsck-all.sh
Last active August 29, 2015 14:19
One-Liner to check the integrity of all git repos in the current directory
find . -name '.git' -type d -prune \
| rev | cut -d '/' -f2- | rev | tr '\n' '\0' \
| xargs -0 -n1 -I% bash -c 'echo -n "%..."; cd "%"; git fsck 2>/dev/null 1>&2; if [ $? -eq "0" ]; then printf "\e[32mPASS\e[39m\n"; else printf "\e[31mFAIL\e[39m\n"; fi'