Skip to content

Instantly share code, notes, and snippets.

View haxscramper's full-sized avatar

haxscramper haxscramper

View GitHub Profile
@haxscramper
haxscramper / nimble-rebuild.fish
Created August 28, 2020 08:33
Automatically rebuild nimble tests when file changes
#!/usr/bin/env fish
function find-match-in-parent-dir -a "find_match"
set -l path "$PWD"
while [ '/' != "$path" ]
find "$path" -maxdepth 1 -mindepth 1 -name "$find_match"
set path (readlink -f "$path/..")
end
end
@haxscramper
haxscramper / register.nim
Last active October 18, 2020 18:22
Nim custom compiler pass
import std/[os, strformat]
import Nim / compiler /
[ idents, options, modulegraphs, passes, lineinfos, sem, pathutils, ast,
astalgo, modules, condsyms, passaux
]
let file = "/tmp/ee.nim"
file.writeFile("""
proc test*(arg: int) = echo arg
@haxscramper
haxscramper / languages-and-vms.md
Last active March 16, 2024 19:45
languages-and-vms
@haxscramper
haxscramper / nim-features-you-didn-t-know-and-don-t-need-to.org
Last active December 4, 2020 22:09
Nim features you didn't know and don't need to

Nim features you didn’t know and don’t need to

Can put basically anything as identifier

Technically this is just function call using method call syntax - × is treated as regular identifier (like someFunction) and it is perfectly legal to call obj .someFunction arg. So a .× b is not really different in that regard.

proc ×(a, b: set[char]): seq[(char, char)] =
  for aIt in a:
    for bIt in b:
@haxscramper
haxscramper / htppserve.nim
Last active May 12, 2021 12:04
Nim emscripten hello world
import asynchttpserver, asyncdispatch, os
proc handler(req: Request) {.async.} =
echo "request for path ", req.url.path
let cwd = getCurrentDir()
let file = cwd / req.url.path
if fileExists(file):
await req.respond(Http200, file.readFile())
else:
@haxscramper
haxscramper / matching.org
Last active February 24, 2021 06:06
Getting started with pattern matching article

Pattern matching in nim

Introduction

New pattern matcing library introduces support for two very useful concepts: pattern matching and object destructuring.

Base C++ class cppbase.cpp

#pragma once

#include <stdio.h>

struct CppBase {
  virtual void baseMethod(int arg) {
    printf("arg from nim - %d -\n", arg);
@haxscramper
haxscramper / nim-fusion.md
Last active February 19, 2021 15:07
nim-fusion.md

Nim fusion

Starting from this version you can run nim fusion to install or update the fusion package - an extension to the nim stdlib with some additional modules.

Currently, the following modules are present:

Cleaning up existing tests

There are many ideas of what we could change or where to go next, but those are often poorly thought out. The sheer volume of what we don't know about the existing system, good or bad, is so large we're working in the dark. This is a blindspot induced by the current state of the code base.

What we do know, with great certainty, is that we need tests that not only test things but also:

  • teach the reader
  • are a useful reasoning tools
  • remember decisions of the past
  • help uncover lost ideas
  • shine a light on dark corners and issues