Skip to content

Instantly share code, notes, and snippets.


Juan Carlos juancarlospaco

View GitHub Profile
View wikipediadns.nim
import httpclient, json, xmltree, q
proc wikipediaDns*(name: string): string {.inline.} =
const w = ""
let hc = newHttpClient()
for x in hc.getContent(w & name).parseJson{"query", "pages"}.pairs:
for u in q(hc.getContent(x.val{"fullurl"}.getStr)).select"table.infobox tbody tr a[href*=http]":
return u.attr"href"
echo wikipediaDns("Nim-lang")
juancarlospaco / printf.nim
Last active Mar 24, 2020
C print for Nim
View printf.nim
proc printf*(format: cstring): cint {.importc, header: "<stdio.h>".}
proc fprintf*(stream: File, format: cstring): cint {.importc, header: "<stdio.h>".}
proc sprintf*(str: var cstring, format: cstring): cint {.importc, header: "<stdio.h>".}
proc vsprintf*(str: var cstring, format: cstring, arg: varargs[typed, `$`]): cint {.importc, header: "<stdio.h>".}
proc vfprintf*(stream: File, format: cstring, arg: varargs[typed, `$`]): cint {.importc, header: "<stdio.h>".}
juancarlospaco / build_generic_nim_module.yml
Last active Dec 1, 2019
.github/workflows/build.yml GitHub Action for Nim (Generic Base Template)
View build_generic_nim_module.yml
name: Build Nim 👑
on: [push]
runs-on: ubuntu-latest
View nicy.nim
import strformat, times, os, osproc, nicypkg/functions
export functions
when isMainModule:
prompt = returnCondition(ok = "👍", ng = "👎") & " "
nl = "\n"
gitBranch = color(gitBranch(), "yellow")
cwd = color(tilde(getCwd()), "cyan")
dirty = color("×", "red")
juancarlospaco / function_example.nim
Last active Jul 23, 2019
Python Vs Nim: Functions
View function_example.nim
# args are immutable by default.
# Variables immutables by default (std lib).
# func ensures exampleFunction dont have Side Effects (is a Functional function).
func exampleFunction(arg: Natural): range[0..100] = # Static Types no type Bugs possible (wont compile otherwise). range[0..100] only allows integers from 0 to 100. Natural only allows integers not Negative (>=0).
# result variable is automatically created for you (you always need to return a result anyways)
preconditions arg > 0, arg < 101 # Preconditions (like a Unittest BEFORE a block of code, asserts on args and variables)
postconditions result > 0, result < 101 # Postconditions (like a Unittest AFTER a block of code, asserts on result)
result = arg + 1 # Mimic some logic here, it does not really matter for this example
# result is automatically returned, no need for "return result" (can still use return if wanted tho)
juancarlospaco /
Last active Mar 9, 2020
Arch Linux Thermal Printer USB 58mm / 80mm Drivers & Config
juancarlospaco / example.txt
Created Feb 28, 2019
NimWC with Firejail: typical terminal standard output debug messages when not build for release.
View example.txt
2019-02-28T16:00:52-03:00: Nim Website Creator: starting.
*** Starting xvfb server: "Xvfb" ":529" "-screen" "0" "800x600x24" ***
*** Stating xvfb client: "firejail" ***
*** Attaching to Xvfb display 529 ***
Basic read-only filesystem:
Mounting read-only /bin
Mounting read-only /lib
Mounting read-only /usr
juancarlospaco /
Last active Nov 4, 2019
Arch Linux Tips & Tricks

Required Packages

sudo pacman -S xdelta3 ccache axel


juancarlospaco /
Last active Nov 14, 2019
Python Versus Nim: Async

Python Versus Nim: Async

  • No performance benchmark.
  • Python ⟿ PEP-8
  • Nim ⟿ NEP1
  • Python ⟿ 3.7
  • Nim ⟿ 0.19
  • No Ofuscation, no Code-Golf.

This is to compare elegant, simple, expressive code.

juancarlospaco /
Last active May 11, 2018 with post-install compilation of Cython and Go.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# To generate DEB package from Python Package:
# sudo pip3 install stdeb
# python3 --verbose --command-packages=stdeb.command bdist_deb
# To generate RPM package from Python Package:
You can’t perform that action at this time.