Skip to content

Instantly share code, notes, and snippets.

@gmpreussner
gmpreussner / archlinux-install-nvme-luks-lvm-btrfs-usb
Last active March 23, 2023 09:31
Minimal instructions for installing a fully encrypted ArchLinux with USB boot on Lenovo Yoga 920.
# Install a fully encrypted ArchLinux on NVMe with detached LUKS
# headers and LUKS encrypted UEFI boot partition on a USB dongle.
#
# Full tutorial can be found here:
# https://headcrash.industries/reference/fully-encrypted-archlinux-with-secure-boot-on-yoga-920/
#
# Written by Gerke Max Preussner <info@headcrash.industries>
# Overview ############################################################
type
Foo[T] = concept x
x.foo(T)
proc foobar[T](f: Foo[T]) =
f.foo(42)
type
FooImpl[T, U] = object
type
Foo[T] = concept x
var t = T()
x.foo(t)
x.bar(t) is T
FooImpl[T] = object
proc foo[T](f: FooImpl[T], t: T) = discard
proc bar[T](f: FooImpl[T], t: T): T = t
type
Foo[T] = ref object
x: T
Bar[N: static[int], T] = ref object
a: array[N, T]
x: T
Foobar[N: static[int], T] = object
b: Bar[N, T]
type IntArray[T; N: static[int]] = array[N, T]
proc ones[T](N: static[int]): IntArray[T, N] =
for i in 0 .. < N:
result[i] = 1
echo @[ones[int](5)]
import macros
const nmax = 500
type
Complex*[T] = object
re*: T
im*: T
converter toComplex*[T](x: tuple[re, im: T]): Complex[T] =
@gmpreussner
gmpreussner / gist:42316c11c9c6d4479d21
Created October 18, 2015 06:42
Bug with generics/concepts
type
Foo[T] = concept x, y
foo(x, y) is bool
Bar[T] = object
b: T
when true: # the following works
proc foo(x, y: Bar): bool = true
@gmpreussner
gmpreussner / midlinterface.nim
Last active October 6, 2015 01:43
MIDL interface glue code generator
import macros
macro midlInterface*(head: expr; body: stmt): stmt {.immediate.} =
## Generates the glue code required for MIDL interface types.
##
## For example, the following declaration...
##
## midlInterface IUnknown:
## proc queryInterface*(riid: Iid; outObj: ptr pointer): HResult
framework
packageA
bin
docs
src
module1.nim
module2.nim
module3.nim
tests
tmodule1.nim
@gmpreussner
gmpreussner / gist:af6cceaa2c54403b6c87
Created February 14, 2015 20:15
static[T] hangs compiler
type
RectArray*[R, C: static[int], T] = distinct array[R * C, T]
StaticMatrix*[R, C: static[int], T] = object
elements*: RectArray[R, C, T]
StaticVector*[N: static[int], T] = StaticMatrix[N, 1, T]
proc foo*[N, T](a: StaticVector[N, T]): T = 0.T