Skip to content

Instantly share code, notes, and snippets.

@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;
};
@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
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 }) {
.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,
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 / 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"
import Foundation
class Vector {
let x,y,z: Double;
init(x:Double, y:Double, z:Double) {
self.x = x;
self.y = y;
self.z = z;
}
use std::num;
pub struct Vector {
pub x: f64,
pub y: f64,
pub z: f64
}
impl Vector {
pub fn dot(&self, v:Vector) -> f64 {
package types
import "math"
type Vector struct {
X, Y, Z float64
}
func (v Vector) Dot(v1 Vector) float64 {
return (v.X * v1.X) + (v.Y * v1.Y) + (v.Z * v1.Z)