Skip to content

Instantly share code, notes, and snippets.

@joastbg
joastbg / pingu.cc
Last active November 6, 2015 00:49
SVG symmetry generator
#include <iostream>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <complex>
#include <cmath>
double const pi = 4 * std::atan(1);
@joastbg
joastbg / qm_angles.m
Created October 31, 2015 18:04
Orbital angular momentum
angles = @(j) acos(linspace(-j,j,j*2+1)./(sqrt(j*(j+1))));
@joastbg
joastbg / numerical.py
Last active November 5, 2015 07:10
Numerical Analysis in Python
import numpy as np
# numpy.dot
# For 2-D arrays it is equivalent to matrix multiplication, and for
# 1-D arrays to inner product of vectors (without complex conjugation).
# Ex: np.dot([[1, 0], [0, 1]], [[4, 1], [2, 2]])
# numpy.vdot
# The vdot(a, b) function handles complex numbers differently than dot(a, b).
# If the first argument is complex the complex conjugate of the first argument is
@joastbg
joastbg / snippets.clj
Last active August 29, 2015 14:27
Clojure snippets
user=> (Long/toBinaryString (Double/doubleToLongBits 3.14))
"100000000001001000111101011100001010001111010111000010100011111"
user=> (map #(println (apply str (drop 10 %1))) (map #(Long/toBinaryString (Double/doubleToLongBits %1)) (range 1 2 0.05)))
0000000000000000000000000000000000000000000000000000
0000110011001100110011001100110011001100110011001101
0001100110011001100110011001100110011001100110011010
0010011001100110011001100110011001100110011001100111
0011001100110011001100110011001100110011001100110100
0100000000000000000000000000000000000000000000000001
@joastbg
joastbg / testcont.sml
Created December 2, 2014 13:42
Illustrates the use of continuation-passing style (CPS)
(* testcont.sml
*
* Copyright (c) 2014. Johan Astborg.
*
* This illustrates the use of continuation-passing style (CPS)
* applied to Standard ML and more specific MLton together with
* infix operators to achieve a stackless programming style.
*
* See "http://mlton.org/MLtonCont" for details.
*)
@joastbg
joastbg / gist:e86b863987dc624fdb05
Created November 29, 2014 16:16
Build Moscow ML on FreeBSD 10.1
#!/usr/local/bin/zsh
pkg install subversion
pkg install `pkg search gcc5`
cd /usr/ports/lang
svn co https://svn0.us-east.freebsd.org/ports/head/lang/moscow_ml moscow_ml
make patch
pkg install `pkg search gcc5`
make CC="gcc5"
@joastbg
joastbg / mt_assign1.m
Created November 7, 2014 20:17
Jordan matrices
%% Matrix Theory - Assignment 1
% Johan Astborg, HT14
% joastbg@gmail.com
%% Illustrates the usage
% Feel free to change the test matrix
function draft()
% Test matrices
@joastbg
joastbg / readparse.cc
Last active October 19, 2018 04:41
Read and parse doubles from file
#include <iostream>
#include <iterator>
#include <fstream>
#include <algorithm>
int main () {
std::ifstream infile("example.txt");
std::istream_iterator<double> iit (infile);
@joastbg
joastbg / binfun.cpp
Created August 1, 2014 17:06
Binomial price step using some x86 tricks
// e^(-r*sqrt(t/n)) using some x86 tricks
float _fexpbin(float vol, float t)
{
float ret;
__asm
{
fld t
fsqrt
fldln2
fdiv
@joastbg
joastbg / mpi_ring.cc
Created July 12, 2014 20:55
MPI test program, sending messages in a ring
#include <mpi.h>
int main(int argc, char** argv)
{
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);