Skip to content

Instantly share code, notes, and snippets.

Gerke Max Preussner gmpreussner

Block or report user

Report or block gmpreussner

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
@gmpreussner
gmpreussner / archlinux-install-nvme-luks-lvm-btrfs-usb
Last active Jul 15, 2019
Minimal instructions for installing a fully encrypted ArchLinux with USB boot on Lenovo Yoga 920.
View archlinux-install-nvme-luks-lvm-btrfs-usb
# 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 ############################################################
View generic_concepts.nim
type
Foo[T] = concept x
x.foo(T)
proc foobar[T](f: Foo[T]) =
f.foo(42)
type
FooImpl[T, U] = object
View generic_param_concept.nim
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
View static[T] constructor problem.nim
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]
View tstatic_ones_generic.nim
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)]
View generic_templates.nim
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 Oct 18, 2015
Bug with generics/concepts
View gist:42316c11c9c6d4479d21
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 Oct 6, 2015
MIDL interface glue code generator
View midlinterface.nim
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
View gist:df7705a7c2c3c57f0e62
framework
packageA
bin
docs
src
module1.nim
module2.nim
module3.nim
tests
tmodule1.nim
View gist:af6cceaa2c54403b6c87
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
You can’t perform that action at this time.