Skip to content

Instantly share code, notes, and snippets.

using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for(int i=1;i<=100;i++) {
switch (new { mod3 = i % 3, mod5 = i % 5 }) {
@neildanson
neildanson / FizzBuzzLLVM.fs
Created December 2, 2017 09:11
Example of a fizzbuzz specific AST that emits LLVM bytecode that can be run through clang
module AST =
type Name = string
type TypeName = string
type Literal = Int of int | Bool of bool | String of string | Void
type Expr =
| Literal of Literal
| Rem of Expr * Expr
@neildanson
neildanson / raytracer.glsl
Created December 2, 2017 22:10
Simple Raytracer running in GLSL
#define NUM_SPHERE 6
#define NUM_LIGHT 3
struct Camera {
vec3 position;
vec3 forward;
vec3 up;
vec3 right;
};
.class public auto ansi abstract sealed Program
extends [mscorlib]System.Object
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = (
01 00 07 00 00 00 00 00
)
.class nested public auto auto sealed serializable beforefieldinit DU
extends [mscorlib]System.ValueType
implements class [mscorlib]System.IEquatable`1<valuetype Program/DU>,
[mscorlib]System.Collections.IStructuralEquatable,
@neildanson
neildanson / Effects.fx
Created August 31, 2013 20:11
Example fx file that compiles and runs fine on Windows, iOS & Android.
float fTimer;
float fPixellateFactor = 1.0f;
sampler ColorMapSampler : register(s0);
float4 NormalShader(float2 Tex:TEXCOORD0) : COLOR
{
float4 color = tex2D(ColorMapSampler, Tex);
return color;
}
type ColorF(r : float, g : float, b : float) =
new(r : byte, g : byte, b : byte) = ColorF(float r / 255.0, float g / 255.0, float b / 255.0)
member __.R = r
member __.G = g
member __.B = b
member color.RGBA =
let r = int (r * 255.0)
let g = int (g * 255.0)
let b = int (b * 255.0)
//add rand and bmp as dependencies in toml file
extern crate rand;
extern crate bmp;
use bmp::Image;
use rand::Rng;
#[derive(Clone)]
enum Expr {
VariableX,
VariableY,
@neildanson
neildanson / ray.cs
Created November 6, 2012 22:12
Declaring types
class Ray
{
private readonly Vector3D position;
private readonly Vector3D direction;
public Ray(Vector3D position, Vector3D direction)
{
this.position = position;
this.direction = direction;
}
@neildanson
neildanson / structures.fs
Created November 6, 2012 22:06
Type declarations
type Ray(position : Vector3D, direction:Vector3D) =
member ray.Position = position
member ray.Direction = direction
@neildanson
neildanson / XdesProcKiller.fsx
Last active August 29, 2015 14:26
F# Script for periodically killing the pesky XDesProc.exe that often hangs Visual Studio for no good reason
open System
open System.Diagnostics
printfn "XDesProc killer"
printfn "Press Return to Close"
printfn "======================"
let rec killer() = async {
let xdesproc = Process.GetProcessesByName "xdesproc"