Skip to content

Instantly share code, notes, and snippets.

View juancarlospaco's full-sized avatar
👑
https://t.me/NimArgentina

Juan Carlos juancarlospaco

👑
https://t.me/NimArgentina
View GitHub Profile
@juancarlospaco
juancarlospaco / ue5cleaner.nim
Last active October 13, 2023 14:54
Unreal Engine 5 project folder Minify/Anonymizer/Cleaner in Nim
import std/[os, strutils, json, sequtils]
proc main(cwd: string) =
if dirExists(cwd / "Content"):
# Minify uproject to valid minimal.
for f in walkPattern(cwd / "*.uproject"):
let uproject = parseFile(f)
if uproject.contains"Category": uproject.delete"Category"
if uproject.contains"Description": uproject.delete"Description"
## Debug utilities, to keep it simple and stdlib-only.
import functools
__all__ = ("debugs", )
def debugs(func):
@juancarlospaco
juancarlospaco / README.md
Last active October 20, 2022 21:05
Rust vs C++ vs C vs Cython vs Nim. (year 2022)

Build

$ ./compileall.sh 

# Cleanout #############################################################
# Go ###################################################################

real    0m0,283s
user    0m0,227s

💰➡️🍕

Tether USDT

TRC20 Tron Network

TPfjb2mbSQQwUe9AScZmu5bRax3dHdBBiL

BEP20 Binance Smart Chain Network BSC

@juancarlospaco
juancarlospaco / wikipediadns.nim
Created April 9, 2020 05:52
Wikipedia as DNS Server
import httpclient, json, xmltree, q
proc wikipediaDns*(name: string): string {.inline.} =
const w = "http://en.wikipedia.org/w/api.php?action=query&prop=info&inprop=url&format=json&limit=1&titles="
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
juancarlospaco / printf.nim
Last active May 27, 2024 18:06
C print for 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
juancarlospaco / build_generic_nim_module.yml
Last active May 22, 2021 23:53
.github/workflows/build.yml GitHub Action for Nim (Generic Base Template)
name: Build Nim 👑
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
@juancarlospaco
juancarlospaco / nicy.nim
Last active April 7, 2021 16:10
ZSH Terminal "DIY prompt", uses https://github.com/icyphox/nicy
import strformat, times, os, osproc, nicypkg/functions
export functions
when isMainModule:
let
prompt = returnCondition(ok = "👍", ng = "👎") & " "
nl = "\n"
gitBranch = color(gitBranch(), "yellow")
cwd = color(tilde(getCwd()), "cyan")
dirty = color("×", "red")
@juancarlospaco
juancarlospaco / function_example.nim
Last active July 23, 2019 03:03
Python Vs Nim: Functions
# 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
juancarlospaco / thermal_printer.md
Last active June 21, 2024 17:47
Arch Linux Thermal Printer USB 58mm / 80mm Drivers & Config