Skip to content

Instantly share code, notes, and snippets.

View realvictorprm's full-sized avatar
😼
Fighting the bugs!

Victor Peter Rouven Müller realvictorprm

😼
Fighting the bugs!
  • Hivemind Technologies AG
  • Switzerland
  • 02:25 (UTC +02:00)
  • X @realvictorprm
View GitHub Profile
@realvictorprm
realvictorprm / Fable.Import.Pixi.fs
Last active November 6, 2017 04:37
F# Bindings for Pixi.js v4.x
namespace Fable.Import
open System
open System.Text.RegularExpressions
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import.JS
open Fable.Import.Browser
module rec Cherry =
// Wrong function
[SuppressUnmanagedCodeSecurity]
[DllImport("glfw3", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "glfwCreateWindowSurface")]
public static extern VkResult CreateWindowSurface(IntPtr instance, GLFWwindow window, IntPtr allocator, out long surface);
// Working function
[<SuppressUnmanagedCodeSecurity>]
[<DllImport("glfw3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "glfwCreateWindowSurface")>]
extern VkResult CreateWindowSurface(uint64 instance, nativeint window, nativeint allocator, unativeint& surface);
@realvictorprm
realvictorprm / SurfaceExtraction.fs
Last active July 20, 2017 20:08
Surface extraction algorithms in F#, currently contains only Surface Nets
/// <summary>
/// Precalculated values which are power of two. Exponent begins with zero!
/// </summary>
let PowerOfTwo = [| for i in 0..20 -> int (System.Math.Pow(2., float i)) |]
let toBoolean<'T> (v:'T) = System.Convert.ToBoolean(v)
// size = 12
// This maps a edge index to a vertex pair
// 12 edges = 12 vertex pairs
let cubeEdgesSurfacenets =
@realvictorprm
realvictorprm / FsharpGeneratorUsingglTFSpecificationFiles.fs
Last active September 13, 2017 16:41
Creates a abstract generator class which provides all methods for visiting the specified glTF specification
open System.IO
// Weitere Informationen zu F# unter "http://fsharp.org".
// Weitere Hilfe finden Sie im Projekt "F#-Tutorial".
module Generator =
open System.IO
open System
open System.Text.RegularExpressions
open System.CodeDom.Compiler
@realvictorprm
realvictorprm / FsharpAllocationTraps.fsx
Created September 28, 2017 15:32
Those cases here show when allocations happen without being want.
type WhoDesignedThisAnyway =
{ Field: string }
/// allocates two functions, and a tuple each time this is called.
static member Lens = (fun x -> x.Field), (fun v x -> {x with Field = v })
module WhoDesignedThisAnyway =
/// doesn't allocate
@realvictorprm
realvictorprm / API_Reference_Opener.fsx
Last active March 3, 2018 20:09
Provides the class ReferenceHelper with which one can simply open the documentation to a bash command through calling `helper.[commandyousearch]`
open System
open System.Net
open System.Text.RegularExpressions
open System.Collections.Generic
// Learn more about F# at http://fsharp.org. See the 'F# Tutorial' "project"
// for more guidance on F# programming.
module Option =
let inline defaultMap value f option = match option with | None -> value | Some value -> f value
@realvictorprm
realvictorprm / PaketDependencyManagementMadeEasy.fsx
Last active June 12, 2018 19:41
A must have for your script file to ease spreading a small proof of concept with dependencies!
open System
open System.IO
open System.Diagnostics
let downloadDependencies deps =
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
async {
let url = "http://fsprojects.github.io/Paket/stable"
enum HeadMovement{
case Left, Right, Keep
}
type TuringMachineTransitionTable[BandElement, AlphabetElement, State] =
Map[(State, BandElement), (State, AlphabetElement, HeadMovement)]
class InfiniteBand[BandElement, Alphabet](band:Map[Int, BandElement | Alphabet],
neutralElement: (BandElement | Alphabet)) {
var pos = 0
@realvictorprm
realvictorprm / Snake.fsx
Last active November 22, 2020 18:00
Snake implementation in F#
module Elmish.Snake
(**
Timer as a source of events with an SVG clock, by Zaid Ajaj.
You can find more info about Emish architecture and samples at https://elmish.github.io/
*)
open System
open Fable.Import
open Fable.Helpers.React
@realvictorprm
realvictorprm / Feck.scala
Last active August 22, 2020 09:21
Attempt to create an sync IO for bukkit
object Bukkit {
import scala.concurrent.ExecutionContext
implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
def scheduler: BukkitScheduler = JBukkit.getScheduler
def runTask(task: IO[Unit])(implicit plugin: JavaPlugin): BukkitTask = scheduler.runTask(plugin, Utils.mkRunnable(task.unsafeRunSync()))