Skip to content

Instantly share code, notes, and snippets.

-- 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 / OUTPUT
Last active November 24, 2023 08:27
C++ TRACE and LOG macros.
TRACE: /dev/shm/test.cpp(27): int main(int, char**)
TRACE: /dev/shm/test.cpp(20): void where_am_I(int)
LOG: /dev/shm/test.cpp(22): void where_am_I(int)
x(3) is odd.
LOG: /dev/shm/test.h(10): void where_are_you()
Here I am!
@johntyree
johntyree / splitpatch.rb
Created February 5, 2013 21:27
Ruby script for splitting a patch by file or into hunks.
#!/usr/bin/env ruby
# GistID: 4717831
#
# splitpatch is a simple script to split a patch up into multiple patch files.
# if the --hunks option is provided on the command line, each hunk gets its
# own patchfile.
#
# Copyright (C) 2007, Peter Hutterer <peter@cs.unisa.edu.au>
#
# This program is free software; you can redistribute it and/or modify
@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 / history_vol.py
Last active February 26, 2020 04:24
Calculate annualized volatility from historical data.
#/usr/bin/env python
from pandas import np
from pandas.io.data import DataReader
def historical_volatility(sym, days):
"Return the annualized stddev of daily log returns of `sym`."
try:
quotes = DataReader(sym, 'yahoo')['Close'][-days:]
@johntyree
johntyree / a.pyx
Last active May 17, 2018 12:26
C vs. C++ in Cython.
# coding: utf8
# distutils: language = c++
# distutils: sources = b.cpp
# Using C calling convention works with "cdef extern ..." directly; no
# hpp header.
# Without it we need to use the cdef extern from "b.hpp": ... declaration.
# Implicitly forces C calling convenction?
cdef extern void c()
@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