Skip to content

Instantly share code, notes, and snippets.

View flaviut's full-sized avatar

Flaviu Tamas flaviut

View GitHub Profile
@flaviut
flaviut / debugging.md
Last active August 29, 2015 14:13
How to debug Nim code

Nim Debugging

I use GDB to debug my Nim code, but by default Nim doesn't output enough information to be usable. I pass --debuginfo --linedir:on to the nim command to fix that.

There is some name mangling, but in most cases things are still understandable. procs have an integer appended to the name, so when setting a breakpoint is done like this: b foo_431313. It's also possible to just line number for breakpoints, which is exactly as you might expect: b mymodule.nim:321.

Simple git-up

To install, download the script on your path, rename it to git-up and chmod +x git-up.

Usage is git up <remote> [params]. It iterates through all the the branches that exist on both local and the remote, and does git rebase $params $remote/$branch $branch. Really simple.

Dependencies are GNU Coreutils and git. Running linux? You'll have them both installed.

@flaviut
flaviut / tab-enable.diff
Created January 1, 2015 19:24
enables tabs in nim
diff --git i/compiler/lexer.nim w/compiler/lexer.nim
index a6b85d7..183a678 100644
--- i/compiler/lexer.nim
+++ w/compiler/lexer.nim
@@ -724,12 +724,9 @@ proc skip(L: var TLexer, tok: var TToken) =
tok.strongSpaceA = 0
while true:
case buf[pos]
- of ' ':
+ of ' ', '\t':
import macros
proc procToLambda(input: PNimrodNode): PNimrodNode {.compiletime.} =
# Ident !"foo"
# Empty
# Empty
# FormalParams
# Ident retType
# IdentDefs
# ...
type
yaml_char_t* = cuchar
type
yaml_version_directive_t* = object
major*: cint
minor*: cint
type
yaml_tag_directive_t* = object
handle*: ptr yaml_char_t
prefix*: ptr yaml_char_t
#!/usr/bin/env sh
# A wrapper around the Nim compiler to allow for easy scripting of Nim. Puts
# all temporary files in a temporary directory and cleans up after itself.
#
# Usage:
# - add `#!/usr/bin/env nimrun` at the beginning of your script
# - execute the nim file with it, for example, `nimrun file.nim args`
#
# Possible future extentions:
@flaviut
flaviut / dataclass.nim
Last active August 29, 2015 14:10
A Nim macro to automaticlly generate data classes
import macros, strutils
## Example:
##
## dataclass:
## Animal(RootObj)(name: string, age: int)
## Dog(Animal)(bark: Sound, breed: string)
## Cat(Animal)(meow: Sound, declawed: bool)
##
## Syntax is `Name(Base)(field1: field1_type, field2: field2_type)`

High Quality Monospace Fonts & Configuration (2013) [Arch Linux] Now with pretty pictures!

Use either [freetype2-git] from the [AUR] or [heftig’s repository] which includes Infinality’s ClearType subpixel hinter. A far superior TrueType font hinter compared with the default implementation. See this [bug report] for more details.

In the following list I have tried to remain objective by comparing only the visual artifacts as described in [The Raster Tragedy]. These include excessive colour fringing, non-uniform stroke widths and oversampling (blurriness caused

@flaviut
flaviut / buildslave.service
Last active August 29, 2015 14:09
Run buildslave under systemd. Adjust as appropriate.
[Unit]
Description=Buildbot Build Slave
After=default.target
[Service]
Type=forking
User=nim-user
PIDFile=/home/nim-user/nim/twistd.pid
ExecStart=buildslave start /home/nim-user/nim
Restart=always
import osproc, strutils, pegs, os, parseopt2, sequtils
type Application = object
id: int
name: string
volume: float
var verbose = false
proc tryExec(cmd): auto =