Skip to content

Instantly share code, notes, and snippets.

View pietroppeter's full-sized avatar
🐳
chasing the whale

Pietro Peterlongo pietroppeter

🐳
chasing the whale
View GitHub Profile
import markdown
import std / strutils
echo markdown("""
```nim
echo "hello"
```*
""".replace('*', ' '), config=initGfmConfig())
#[
<pre><code class="language-nim">echo &quot;hello&quot;
# minib (a mini nimib)
import strformat, macros
import tempfile
proc dup*(oldfd: FileHandle): FileHandle {.importc, header: "unistd.h".}
proc dup2*(oldfd: FileHandle, newfd: FileHandle): cint {.importc, header: "unistd.h".}
macro toStr*(body: untyped): string =
(body.toStrLit)
@pietroppeter
pietroppeter / languages-and-vms.md
Created November 11, 2022 13:13 — forked from haxscramper/languages-and-vms.md
languages-and-vms
@pietroppeter
pietroppeter / add.nim
Created September 8, 2022 12:45
dll analysis in nim
# compile with: nim c --app:lib -d:release add.nim
# examine with: peni info -a add.dll
# see https://forum.nim-lang.org/t/9446
proc add*(num1, num2: int): int {.stdcall, exportc, dynlib.} =
num1 + num2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
sudo apt-get update
sudo apt-get install libpangocairo-1.0-0
sudo apt-get install libblas-dev liblapack-dev
@pietroppeter
pietroppeter / cairo_deps.md
Last active February 15, 2021 15:46
Cairo dependencies for Windows (to use ggplotnim on Windows)

A common issue while trying to use https://github.com/Vindaar/ggplotnim on Windows is the fact that it is not easy to satisfy the full list of dll for Cairo.

In an issue (Vindaar/ggplotnim#57) and related gist (https://gist.github.com/Vindaar/6cb4e93baff3e1ab88a7ab7ed1ae5686) one of the best options seems to be to install emacs and add its bin folder to the path.

Using a dll dependency analyzer (https://github.com/lucasg/Dependencies, found through SO: https://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency), I was able to list all the dlls required, which are the following 17 files (including libcairo-2.dll, total around 9MB).

So another solution instead of installing emacs is to download the dlls (see link to libcairo-deps.rar in comment) and copy them in ~\.nimble\bin.

List of all recursive dependencies for libcairo-2.dll:

  • libbz2-1.dll
@pietroppeter
pietroppeter / hello_world.html
Created October 22, 2020 19:51
nimib preview
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>world.nim</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel='stylesheet' href='https://unpkg.com/normalize.css/' type='text/css'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css">
</head>
<body>
@pietroppeter
pietroppeter / week.nim
Created September 10, 2020 12:36
isoweek number in nim
## iso week number
## see https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
import times
type
WeekRange = range[1 .. 53]
proc lastWeek(year: int): WeekRange =
## The long years, with 53 weeks in them, can be described as any year starting on Thursday and any leap year starting on Wednesday
let firstWeekDay = initDateTime(1.MonthDayRange, mJan, year, 0, 0, 0).weekday
@pietroppeter
pietroppeter / package_count.nim
Last active April 7, 2021 16:10
Nim file to count Nimble packages
# git clone https://github.com/nim-lang/packages.git
# then compile and run this file in the git repo
import os, parsecsv, json, strutils
proc runCommand(command: string) =
let errorCode = os.execShellCmd(command)
if errorCode != 0:
echo "error running command: " & command
quit(1)
else: