Skip to content

Instantly share code, notes, and snippets.

module BF
// Natural number
type N = abstract member Value : int
[<StructuredFormatDisplay("{IntValue}")>]
type Z = Z with
member z.IntValue = 0
interface N with member z.Value = 0
" https://github.com/jeetsukumaran/vim-indentwise
" Vim indent-level based motion
Plugin 'jeetsukumaran/vim-indentwise'
augroup fsharp_commands
autocmd!
" Prev/next let/type/exception/module/namespace
autocmd FileType fsharp nnoremap [[ :call search('\(^\s*\)\@<=\(let\\|and\\|type\\|exception\\|module\\|namespace\)\>', "bW")<CR>
autocmd FileType fsharp nnoremap ]] :call search('\(^\s*\)\@<=\(let\\|and\\|type\\|exception\\|module\\|namespace\)\>', "W")<CR>
@Ming-Tang
Ming-Tang / ObjectPool.cs
Created February 16, 2015 08:21
Generic object pooling script with custom allocator
using System;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using Random = UnityEngine.Random;
using Object = UnityEngine.Object;
// Class Diagram
//
// MonoBehaviour vertical arrow = is-a
@Ming-Tang
Ming-Tang / circular_queue.cpp
Created September 26, 2014 06:34
Circular array queue demonstration
#include <iostream>
#include <iomanip>
using namespace std;
/*-
*
* 0 1 2 3 4 5
* a b c d
* ^ ^
@Ming-Tang
Ming-Tang / hottercolder.cpp
Created September 24, 2014 17:25
ACM Programming Competition practice program: Hotter Colder
// Hotter Colder: http://acm.student.cs.uwaterloo.ca/~acm00/010127/E.html
#include <iostream>
#include <list>
#include <cmath>
using namespace std;
///////////////////////////////////////////////////////////
// POINT
@Ming-Tang
Ming-Tang / blackhole.opencl
Last active August 29, 2015 14:04
OpenCL image distortion
// See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE;
constant int n = 2; // field exponent
constant float e = 1e-3; // smoothing factor
constant float c = 5e-4; // field multiplier
constant float br = 4e-5; // brightness factor
float z(float r, float k) {
return k / (e + pow(r, n - 1));
@Ming-Tang
Ming-Tang / ripple.opencl
Last active August 29, 2015 14:04
OpenCL image distortion
/**
QueryFormat example : query image format dynamically inside the kernel
Written by Olivier Chafik, no right reserved :-) */
// See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE;
int2 ripple(float x, float y, float a, float w) {
float m = sqrt(x*x + y*y);
@Ming-Tang
Ming-Tang / session-quine.py
Created August 6, 2011 01:18
Quine program that saves state by outputting its own source code and session data
from time import gmtime, strftime;data = { }
while True:
inp = raw_input().split(" ")
if inp[0] == '*':
data = { }
elif len(inp) < 2:
break
else:
if inp[0] == '!':
del data[inp[1]]
@Ming-Tang
Ming-Tang / Factorial12.java
Created May 12, 2011 06:19
Factorial quine program (outputs its own source code with variables changed, compiles new source, repeat)
import java.io.*;
import javax.tools.*;
class Factorial12 {
static final char Q=34;
static final int N=12;
static final int M=1;
public static void main(String[]a)throws Exception{
if (N == 0) {
System.out.println(M);
System.exit(0);
@Ming-Tang
Ming-Tang / Attractor.pde
Last active September 25, 2015 11:08
Lorenz attractor
final int[][] D1 = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
final boolean[][] D2 = { { false, false, false }, { false, false, false }, { true, false, false }, { true, true, false },
{ false, false, true }, { false, false, true }, { true, false, true }, { true, true, true },
{ false, false, false }, { false, true, false }, { true, false, false }, { true, true, false } };
final boolean[][] D3 = { { true, false, false }, { false, true, false }, { true, true, false }, { false, true, false },
{ true, false, true }, { false, true, true }, { true, true, true }, { false, true, true },
{ false, false, true }, { false, true, true }, { true, false, true }, { true, true, true } };
float o = 10, b = 8 / 3, p = 28;
float ra = 0.1, rb = 0.1, rc = 18;