Skip to content

Instantly share code, notes, and snippets.

@johntyree
johntyree / hangman.hs
Created May 1, 2013 19:22
Hangman in Haskell
module Main where
import Prelude hiding (catch)
import Control.Applicative
import Control.Exception
import Control.Monad.State
import Data.List
import System.IO
import System.Random
import Options.Applicative
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
-- A nice collection of FizzBuzz implementations
-- GistID: 5313582
module Main where
import Data.List
fb :: (Show a, Integral a) => a -> String
fb i
| i `rem` 15 == 0 = "FizzBuzz"
@johntyree
johntyree / dualscreen.sh
Created March 14, 2013 17:51
Easy xRandr settings.
#!/bin/sh
# GistID: 5163520
usage () {
echo "Usage: $0 OPTION
Change multi-head display settings.
Options:
-a Do something reasonable
-0 Laptop
-1 Laptop + VGA
// GistID: 4770251
#ifndef THRUST_REPEAT_ITERATOR_H
#define THRUST_REPEAT_ITERATOR_H
/* Remove this header */
#include <GNUC_47_compat.h>
#include <thrust/iterator/iterator_adaptor.h>
@johntyree
johntyree / GNUC_47_compat.h
Last active December 11, 2015 21:58
Header to work around CUDA incompatibility with GCC 4.7+.
// Header for compilation with GCC-4.7
#if defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
#undef _GLIBCXX_ATOMIC_BUILTINS
#undef _GLIBCXX_USE_INT128
#endif
@johntyree
johntyree / syntax.css
Created January 29, 2013 00:26
Pandoc CSS (light)
/* Generated by pandoc. */
code { white-space: pre; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0;
padding: 0;
vertical-align: baseline;
border: none;
}
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers {
@johntyree
johntyree / cyhash.pyx
Created December 20, 2012 10:54
Cython with Numpy. From 2.2s to 0.4s.
# cython: infer_types=True
# Use the C math library to avoid Python overhead.
from libc cimport math
# For boundscheck below.
import cython
# We're lazy so we'll let Numpy handle our array memory management.
import numpy as np
# You would normally also import the Numpy pxd to get faster access to the Numpy
# API, but it requires some fancier compilation options so I'll leave it out for
@johntyree
johntyree / arr.c
Created December 19, 2012 13:02
3D array indexing.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
int main(int argc, char* argv[]) {
int idim = 3;
int jdim = 4;
@johntyree
johntyree / pymode.vim
Created December 13, 2012 19:26
Pass by 'reference' in VimL
fun! pymode#Toggle(toggle, msg) "{{{
let {a:toggle} = {a:toggle} ? 0 : 1
if {a:toggle}
echomsg a:msg." enabled"
else
echomsg a:msg." disabled"
endif
endfunction "}}}