Skip to content

Instantly share code, notes, and snippets.

View adituv's full-sized avatar

Iris Ward adituv

View GitHub Profile
@adituv
adituv / Khinchin.py
Last active December 20, 2015 03:49
A demonstration of Khinchin's constant for the continued fraction expansion of the number pi. Obviously as python has finite precision floating point, this is only an approximation, and is likely to approach an incorrect result as a grows larger.
#!/usr/bin/python3
from math import floor
from math import pi
def getExpansion(y):
x = y
while True:
z = floor(x)
yield z
@adituv
adituv / dotprod.c
Last active December 20, 2015 04:58
OpenCL pseudocode to demonstrate the usual pattern of calling OpenCL
//The code that runs on the graphics card is included in the program here as a plaintext string
//It's also possible to include it as a binary, but I don't know how to do that.
const char* source=
"__kernel \n"
"void sum(__global float* source, __global float* dest, uint n) \n"
" int idx = get_global_id(0); \n"
" int iter = 2; \n"
" \n"
" while(iter < n && idx % iter == 0) { \n"
" dest[min(iter*idx,n)] = source[min(iter*idx,n)] + source[(iter-1)*idx]; \n"
@adituv
adituv / point_of_no_return.sound
Last active December 26, 2015 15:38
Very simple converter from list of frequencies and durations to output sound wave on stdout. Pipe it through e.g. /dev/audio or aplay to actually create sound.
@adituv
adituv / approx.dat
Created November 14, 2013 01:50
Pendulum results with and without sin(x) ~ x. Initial conditions: timestep = 0.1s pendulum length = 1m pendulum mass = 0.25kg gravitational acceleration = 9.81 damping = 0.5 initial angle = 1 initial angular velocity: -0.8
# Assumed that sin(x) ~ x
0.837900
0.626022
0.395107
0.171615
-0.024014
-0.178162
-0.284002
-0.340814
-0.352829
@adituv
adituv / conditions.txt
Last active December 28, 2015 06:49
More comparison data for pendulum.
Please enter the following parameters:
Timestep /s: 0.1
Simulation length /timesteps: 100
Pendulum length /m: 1
Pendulum mass /kg: 0.25
Gravitational acceleration /m s^-2: 9.81
Damping constant /?: 0
Initial pendulum angle /rad: 1
Initial pendulum angular velocity /rad s^-1: -0.8
@adituv
adituv / input.cc
Last active August 29, 2015 13:56
C++ space-delimited inputs
#include <iostream>
#include <fstream>
#include <limits>
using namespace std;
int main() {
float val1, val2;
int line = 0;
ifstream file("temp.txt", ifstream::in);
@adituv
adituv / .vimrc
Created November 5, 2014 01:01
I had to recreate my vimrc. Based heavily on http://statico.github.io/vim.html
"BEGIN Vundle stuff
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'kien/ctrlp.vim'
@adituv
adituv / Main.hs
Last active August 29, 2015 14:15
Qualified Record Pun
{-# LANGUAGE NamedFieldPuns #-}
module Main where
import qualified MyRecord as M
someFunction :: M.MyRecordType -> Int
someFunction (MyRecordType { M.someVal }) = M.someVal * M.someVal
main :: IO ()
main = print . someFunction . MyRecordType $ 3
@adituv
adituv / CList.hs
Created June 22, 2015 04:48
Constrained heterogeneous list
{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes #-}
module CList where
infixr 5 :>
data CList c where
Nil :: CList c
(:>) :: forall c t. (c t) => t -> CList c -> CList c
-- "Monomorphic map instance" (ish) for CList. Converts to normal list.
@adituv
adituv / AutoVersion.md
Last active August 29, 2015 14:27
Visual Studio 2012 - Automatically incrementing version for C#

This requires Microsoft Visual Studio 2012 SDK and Microsoft Visual Studio 2012 Visualization & Modeling SDK, which come separately from Visual Studio 2012. Other version combinations are probably possible, and maybe compatible, but untested. The core of the method is this:

  • Add AssemblyInfo.tt to MyProject\Properties, filling out the "Your xxxxxx" sections.
  • Open up the project file (e.g. MyProject.csproj) in a text editor (e.g. Notepad++), and locate the line that defines the build targets for the language ("import project... microsoft.csharp.targets")
  • Insert the contents of MyProject.csproj there
  • Finally, if you build the AssemblyInfo.tt template within Visual Studio, make sure to set AssemblyInfo1.cs to Build Action: None in the File Properties window. This will fix any errors about duplicate definitions.