Skip to content

Instantly share code, notes, and snippets.

@joshkunz
joshkunz / upload.sh
Last active December 11, 2015 00:28
This is what I have of a shell based moodle upload system. The username should be passed as the first argument. This (with the exception of logging in) does *not* work.
#!/bin/bash
# Where the cookies are stored
COOKIES='cookies.tmp'
# Where the pages are temporarily stored
PAGE='page.tmp'
# value matching regex constant
VALUE_MATCHER='^ value="([^"]*)"'
@joshkunz
joshkunz / gist:4998910
Created February 20, 2013 19:59
The locking section of some caching code I wrote.
@classmethod
def resolve(cls, request, caching_client):
"""If this request isn't yet cached, cache it, otherwise return
a file containing the cached contents"""
hash = cls.hash(request)
is_caching = False
active_thread = None
# If there is no cached file
if not cls.hit(hash):
# obtain a lock for the active caches
@joshkunz
joshkunz / gist:5015438
Created February 22, 2013 18:14
Get all possible 3 tuple combinations of a-z2-9.
from itertools import product
import string
id_combos = product("".join((string.ascii_lowercase, string.digits[2:])), repeat=3)
ids = map("".join, id_combos)
print len(ids), "ids found."
@joshkunz
joshkunz / tmp.c
Last active December 14, 2015 02:39
#include <stdio.h>
char * space = "abcdefghijklmnopqrstuvwxyz23456789";
int main(){
unsigned int total = 0;
char * end = space+34;
char *loop1, *loop2, *loop3;
loop1 = space;
for (; loop1 < end; loop1++) {
@joshkunz
joshkunz / gist:5252787
Created March 27, 2013 08:55
This is the important part.
// Allocate video frame
pFrame=avcodec_alloc_frame();
// Allocate an AVFrame structure
pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL)
return -1;
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
@joshkunz
joshkunz / linenet.py
Last active December 16, 2015 10:09
Simple telnet-like socket interface.
import socket
import threading
import argparse
LINE_TERM = "\n"
parser = argparse.ArgumentParser()
parser.add_argument("host", help="The host name of the server.")
parser.add_argument("port", type=int, help="Port of the server.")
args = parser.parse_args()
@joshkunz
joshkunz / gist:5457074
Created April 25, 2013 02:27
Very simple line-based protocol
LINE_SPLITTER = "\r\n\r\n"
def handle_client((csock, address)):
buffer = ""
while True:
tmp_buffer = csock.recv(RECV_SIZE)
if tmp_buffer == "": break
buffer += tmp_buffer
line = buffer.split(LINE_SPLITTER, 1)
if len(line) < 2: continue
else:
class Person(object):
def __init__(self, name, *attrs):
self.name = name
self.attrs = set()
self.can(*attrs)
def does(self, what):
if what in self.attrs: return True
return False
@joshkunz
joshkunz / output.txt
Last active December 19, 2015 11:09
newLISP issue.
$ newlisp test.lsp
Reading first line...
Started!
Reading second line...
/* Simple quoted translation program. It reads characters from
* stdin and writes them to standard out replacing all
* instances of the character 'WHAT' with the character 'WITH'.
* If a 'WHAT' character appears between 'QSTART' and 'QEND'
* (the starting and ending quote characters) it is not
* replaced. */
#include <stdio.h>
#include <stdbool.h>