Skip to content

Instantly share code, notes, and snippets.

@deech
deech / recordupdate.hs
Last active January 30, 2021 00:35
Record Update with RecordWildCards
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns#-}
data C = C { c::[Int] } deriving Show
data B = B { b::Bool, c::C } deriving Show
data A = A { a::String, b::B } deriving Show
mkA = A "hello world" (B True (C [1,2,3]))
@deech
deech / compiletimefizzbuzz.nim
Created June 7, 2019 23:10
Compile Time FizzBuzz In Nim
import math
proc fizzbuzz(n: int) {.compileTime.} =
for i in 1 .. n:
let
by3 = (i mod 3) == 0
by5 = (i mod 5) == 0
if (by3 and by5): echo "FizzBuzz"
elif by3: echo "Fizz"
elif by5: echo "Buzz"
else: echo $i
@deech
deech / binarytrees.nim
Created March 13, 2019 20:58
Binary tree benchmark [Nim]
import threadpool, strformat, os, strutils, math
type
Tree = ref object
left: Tree
right: Tree
proc deepCopy[T](x: var T, y: T) =
x = y
proc check(t: Tree): int32 =
pthread_setschedparam failed: Operation not permitted
This VM uses a separate heartbeat thread to update its internal clock
and handle events. For best operation, this thread should run at a
higher priority, however the VM was unable to change the priority. The
effect is that heavily loaded systems may experience some latency
issues. If this occurs, please create the appropriate configuration
file in /etc/security/limits.d/ as shown below:
cat <<END | sudo tee /etc/security/limits.d/pharo.conf
* hard rtprio 2
3/home/deech/Pharo/vms/70-x64/lib/pharo/5.0-201806281256/pharo
Pharo VM version: 5.0-201806281256 Thu Jun 28 13:04:44 UTC 2018 gcc 4.8 [Production Spur 64-bit VM]
Built from: CoInterpreter VMMaker.oscog-eem.2401 uuid: 29232e0e-c9e3-41d8-ae75-519db862e02c Jun 28 2018
With: StackToRegisterMappingCogit VMMaker.oscog-eem.2401 uuid: 29232e0e-c9e3-41d8-ae75-519db862e02c Jun 28 2018
Revision: VM: 201806281256 https://github.com/OpenSmalltalk/opensmalltalk-vm.git Date: Thu Jun 28 14:56:30 2018 CommitHash: a8a1dc1 Plugins: 201806281256 https://github.com/OpenSmalltalk/opensmalltalk-vm.git
Build host: Linux travis-job-46342785-b1c1-4811-8c3c-9b2a88ae7ecc 4.4.0-101-generic #124~14.04.1-Ubuntu SMP Fri Nov 10 19:05:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
plugin path: [default: /home/deech/Pharo/vms/70-x64/lib/pharo/5.0-201806281256/]
C stack backtrace & registers:
@deech
deech / D Compile time TCO
Created July 7, 2017 20:53
D Compile Time TCO
import std.stdio;
double factorial (double i)
{
if (i == 1) {
return 1;
}
else {
return (i * factorial(i - 1));
}
curl -X PUT -H "Content-Type: application/x-tar" -H "Content-Encoding: gzip" --data-binary @"packagename-packageversion-docs.tar.gz" "https://usernae:[email protected]/package/packagename-packageversion/docs"
diff --git a/c-src/Fl_C.h b/c-src/Fl_C.h
index 963bc04..9485c6c 100644
--- a/c-src/Fl_C.h
+++ b/c-src/Fl_C.h
@@ -257,6 +257,7 @@ EXPORT {
FL_EXPORT_C(void ,Fl_release_widget_pointer)(fl_Widget w);
FL_EXPORT_C(void ,Fl_clear_widget_pointer)(fl_Widget w);
FL_EXPORT_C(void ,Fl_clear_widget_pointer)(fl_Widget w);
+#if FL_API_VERSION == 10304
FL_EXPORT_C(void ,Fl_set_box_color)(Fl_Color c);
(datatype is-prime
if (is-prime? N)
N : number;
==============
N : prime;)
(define is-prime?
X -> (prime* X (/ X 2) 2) where (number? X)
_ -> false)
@deech
deech / typeclass-repl.hs
Created February 12, 2017 15:17
Typeclasses in the REPL.
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /tmp/ghci7261/ghci-script
Prelude> class Foo a where { foo :: a -> Int }
Prelude> instance Foo () where { foo _ = 1 }
Prelude> f = foo ()
Prelude> class Foo a where { foo :: a -> IO () }
Prelude> f
1