Skip to content

Instantly share code, notes, and snippets.

@lborg019
lborg019 / mergesort.fsx
Created August 18, 2022 02:40
fsharp merge sort
let rec split = function
| [] -> ([], [])
| [a] -> ([a], [])
| a::b::cs -> let (M,N) = split cs in (a::M, b::N)
let rec merge = function
| ([], ys) -> ys
| (xs, []) -> xs
| (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys)
else y :: merge (x::xs, ys)
@lborg019
lborg019 / math-parser.fsx
Created August 18, 2022 02:17
fsharp monadic parser
type Exp =
| Num of int //number of integers
| Neg of Exp //negation
| Sum of Exp * Exp //sum
| Diff of Exp * Exp //difference
| Prod of Exp * Exp //product
| Quot of Exp * Exp;; //quotient
let rec evaluate = function
| Num n -> Some n
@lborg019
lborg019 / dot-product.fsx
Created August 18, 2022 02:04
F# Dot Product
let rec inner xs ys =
match xs, ys with
| [], [] -> 0
| [], ys -> 0
| xs, [] -> 0
| x::xs, y::ys -> x * y + inner xs ys;;
(*
The head of the first list (xs) gets multiplied
by the head of the second list (ys).
We add the next call to this value and recursion
@lborg019
lborg019 / wav-deinterlacer.py
Last active February 15, 2018 23:26
Deinterlace .wav files: $ python2 wav-deinterlacer.py <filename.wav> <samplesize (in bytes)>
import os
import sys
import binascii
from itertools import chain, izip, repeat, islice
# this program is compatible with python 2.7.8
# interspace function
def intersperse(delimiter, seq):
return islice(chain.from_iterable(izip(repeat(delimiter), seq)), 1, None)
@lborg019
lborg019 / codevr.Build.cs
Last active November 13, 2020 08:50
Boost library in Unreal
// Fill out your copyright notice in the Description page of Project Settings.
using System;
using System.IO;
using UnrealBuildTool;
public class codevr : ModuleRules
{
public codevr(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
@lborg019
lborg019 / .hyper.js
Created June 29, 2017 20:17
hyper.js for my windows with git-for-windows-sdk
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
@lborg019
lborg019 / bit_vs_str_permutations.rs
Created June 23, 2017 15:35
Permuting bits using bitshifts can be at least 20 times faster than using String operations (in nanos)
use std::time::{Instant};
fn permute_eight_bits(ten_bit: u16) -> u8
{
// P8[6 3 7 4 8 5 10 9]
// P8[5 2 6 3 7 4 9 8] (-1)
let mut permuted_byte = 0b0000_0000_0000_0000;
let p_eight: [(u16,u16);8] = [(5, 0b0000_0000_0010_0000),
(2, 0b0000_0000_0000_0100),
@lborg019
lborg019 / bytesplit.rs
Created June 21, 2017 17:14
Rust byte splitting
fn main() {
let byte: u8 = 0b1001_0110;
let mut high: u8 = 0b0000_0000;
let mut low: u8 = 0b0000_0000;
/*
(1 << 0) -> 0000 0001
(1 << 1) -> 0000 0010
(1 << 2) -> 0000 0100
@lborg019
lborg019 / switchboxes.rs
Last active June 21, 2017 17:11
Rust switchboxes.
fn main()
{
//switch boxes
let sbox_zero = [[1,0,3,2],
[3,2,1,0],
[0,2,1,3],
[3,1,3,2]];
let sbox_one = [[0,1,2,3],
[2,0,1,3],
@lborg019
lborg019 / .bash_profile
Created April 16, 2017 02:56
bash files
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced