Skip to content

Instantly share code, notes, and snippets.

thedeemon

Block or report user

Report or block thedeemon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dn.d
import std.stdio;
// secret sauce: https://dlang.org/spec/class.html#alias-this
struct DayNum {
int dn;
alias dn this; // this line makes DayNum look like an int with dn as the value
}
DayNum next(DayNum d) {
View points.hs
{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Unboxed as V
import System.CPUTime
import Text.Printf
time :: IO t -> IO t
time a = do
start <- getCPUTime
v <- a
end <- getCPUTime
View vecs.idr
module Main
import Data.Vect
toVec : List a -> (n : Nat ** Vect n a)
toVec [] = (_ ** [])
toVec (x::xs) with (toVec xs)
| (k ** v) = (S k ** x :: v)
myFun : Vect n1 Int -> Vect n2 Int -> LTE n1 n2 -> Int
myFun xs ys p = foldr (+) 0 xs
@thedeemon
thedeemon / path_int.d
Last active Sep 26, 2019
Toy quantum mechanics with path integrals
View path_int.d
import std.complex, std.stdio, std.random, std.parallelism, std.math : hypot;
import std.getopt, std.datetime.stopwatch, std.array, std.algorithm : max, min, reduce;
import std.format, std.range : iota;
struct Wall { double y, x1, x2; } // x1 < x2
struct Point { double x, y; }
bool intersects(Point p1, Point p2, ref Wall wall) {
if (min(p1.y, p2.y) > wall.y) return false;
if (max(p1.y, p2.y) < wall.y) return false;
View logger.d
ILogger {
void log(string msg);
}
class BoringLogger : ILogger {
overrride void log(string msg) {...}
}
class ColorfulLogger : ILogger {
overrride void log(string msg) {...}
View tox.ml
open Batteries
type point = { x : int; y : int }
let f from_y to_y from_x to_x =
let a = (from_y --^ to_y/2) |> Enum.map (fun y -> {x=from_x; y=y}) in
let b = (to_y/2 --^ to_y) |> Enum.map (fun y -> {x=to_x; y=y}) in
Enum.append a b |> Array.of_enum;;
let g from_y to_y from_x to_x =
let t = to_y/2 in
Array.init (to_y - from_y) (fun i -> let y = i + from_y in if y < t then {x=from_x; y=y} else {x=to_x;y=y});;
View tox.d
import std.stdio, std.algorithm, std.range, std.array, std.datetime.stopwatch;
struct Point { int x, y; }
auto f(int from_y, int to_y, int from_x, int to_x) {
return chain( iota(from_y, to_y/2).map!(y => Point(from_x, y)),
iota(to_y/2, to_y) .map!(y => Point(to_x, y)) ).array;
}
auto g(int from_y, int to_y, int from_x, int to_x) {
View cothinkers3.hs
import qualified Data.ByteString.Lazy.Char8 as L8
import Network.HTTP.Client (defaultManagerSettings, newManager)
import Network.HTTP.Simple
import Network.HTTP.Client.TLS
import System.Directory
import qualified Data.Map as M
import Data.List (sortBy)
import Control.Monad
import Control.Applicative
import System.Environment
View veb.txt
cap=134217728
arrSize=16385
next uni=8192
cap=8192
arrSize=129
next uni=64
cap=64
arrSize=9
next uni=8
n for 64 = 0
View jitcases.inc
case ADD|RRR:
case ADD_RRR:
if (code[ip+1]==code[ip+2]) {
a.mov(eax, dword_ptr(edi, code[ip+3]*4));
a.add(dword_ptr(edi, code[ip+1]*4), eax);
} else {
a.mov(eax, dword_ptr(edi, code[ip+2]*4));
a.add(eax, dword_ptr(edi, code[ip+3]*4));
a.mov(dword_ptr(edi, code[ip+1]*4), eax);
}
You can’t perform that action at this time.