Skip to content

Instantly share code, notes, and snippets.

View onesandzeroes's full-sized avatar

Marius Mather onesandzeroes

View GitHub Profile
@onesandzeroes
onesandzeroes / snake_main.py
Created November 21, 2014 23:41
Snake implemented in Pygame
import random
import pygame
from pygame.locals import *
class GameGrid:
def __init__(self, grid_size=(100, 100), window_size=(400, 400)):
self.grid_size = grid_size
self.square_x_size = window_size[0] / grid_size[0]
self.square_y_size = window_size[1] / grid_size[1]
@onesandzeroes
onesandzeroes / pandoc_style.tplx
Created October 10, 2014 08:19
Ipython Nbconvert simple article template
((* extends 'article.tplx' *))
((* block docclass *))
\documentclass[a4paper,11pt]{article}
((* endblock docclass *))
((* block commands *))
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
@onesandzeroes
onesandzeroes / blocks.py
Created August 5, 2014 05:21
Randomized block assignment in Python
from __future__ import division
import random
import pprint
def assign_blocks(total_n, block_sizes):
block_size_list = []
current_n = 0
while current_n < total_n:
max_size = total_n - current_n
possible_sizes = [s for s in block_sizes if s <= max_size]
@onesandzeroes
onesandzeroes / assign_blocks.ado
Created August 4, 2014 23:23
Blocked random assignment
program assign_blocks
version 13.1
syntax [varlist], totaln(integer) blocksize(integer)
drop _all
set obs `totaln'
generate treatment_assigned = 1
generate dice_roll = runiform()
generate block = 1
local half_block = `blocksize' / 2
local n_blocks = `totaln' / `blocksize'
import string
ambiguous_letters = ['I', 'O']
letter_targets = [letter for letter in string.ascii_uppercase
if letter not in ambiguous_letters]
ambiguous_numbers = ['0', '1']
number_targets = [digit for digit in string.digits
if digit not in ambiguous_numbers]
print(number_targets)
@onesandzeroes
onesandzeroes / ggplot_widgets.ipynb
Created June 27, 2014 01:26
Interactive widgets with ggplot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@onesandzeroes
onesandzeroes / make_notes.py
Created August 12, 2013 10:59
Quick python script to convert all the markdown files in a folder to pdf
#! /usr/bin/env python3
# Convert all markdown files in the current folder to PDF using pandoc
import os
import subprocess
import time
MARKDOWN_EXTS = ('.markdown', '.md')
# Using abspath means I don't have to manually specify the folder name
ROOT_FOLDER = os.path.split(os.path.abspath(__file__))[0]
require(lattice)
hrt <- function(x, y) {
x^2 + (y-(x^2)^(1/3))^2
}
hrt_mat <- matrix(10000, nrow=100, ncol=100)
x_vals <- seq(-1, 1, length.out=100)
y_vals <- seq(-1, 1.5, length.out=100)
for (x in seq(1:nrow(hrt_mat))) {
@onesandzeroes
onesandzeroes / pygame_pong.py
Created July 13, 2012 12:47
Pong in Pygame
import pygame
from pygame.locals import *
import random
KEYS_1 = {K_w:'up', K_s: 'down'}
KEYS_2 = {'up arrow': 'up', 'down arrow': 'down'}
KEY_DICT = {1: KEYS_1, 2: KEYS_2}
WHITE = (255, 255, 255)
class Player: