Skip to content

Instantly share code, notes, and snippets.

// g++ -o gauss gauss.cpp -DTYPE=Number
#include <cstdio>
#include <cstdlib>
// some helper functions and classes
static int gcd (int a, int b) {
if (b == 0) return a;
else return gcd (b, a%b);
}
function curve(x) {
return Math.sqrt(1 - x * x);
}
function curveInt(x) {
return 0.5*(Math.sqrt(1-x*x)*x+Math.asin(x));
}
function corner(x, y, w, h) {
if ((x+w)*(x+w)+(y+h)*(y+h) <= 1) return 1;
if (x*x+y*y >= 1) return 0;
//if (x > 1 || y > 1) return 0;
protocol Creatable {
init()
}
func create<T: Creatable>(f: (T) -> Void) -> T {
let t = T()
f(t)
return t
}
function fish_prompt
set prompt (prompt_pwd)
if set branch (git rev-parse --abbrev-ref HEAD ^/dev/null)
set prompt $prompt (set_color $fish_color_autosuggestion) ' | ' (set_color normal) $branch (set_color normal)
end
set prompt $prompt (set_color $fish_color_autosuggestion) ' > ' (set_color normal)
echo -n -s $prompt
end
@eyelash
eyelash / printer.cpp
Last active December 6, 2015 14:14
a printf-like printer for arbitrary types
#include <cstdio>
class Printer;
class Printable {
public:
virtual void print (Printer& printer) const = 0;
};
class Printer {
@eyelash
eyelash / array2d.cpp
Created May 2, 2015 13:29
C++ dynamic two-dimensional array
#include <cstdlib>
template <class T> class Array2D {
int size, stride;
T* data;
public:
Array2D (int m, int n): size(m*n), stride(n) {
data = (T*) malloc (size*sizeof(T));
for (int i=0; i<size; i++)
new (data + i) T ();