This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Minimum example nim-glfw code to draw a triangle using OpenGL. | |
# | |
# There are more examples on nim-glfw repo: | |
# https://github.com/johnnovak/nim-glfw/tree/master/examples | |
# Get glad/gl.nim from | |
# https://glad.dav1d.de/#profile=core&language=nim&specification=gl&loader=on&api=gl%3D4.2 | |
import glad/gl | |
# Install nim-glfw from |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[cmdline, times, monotimes, random, sugar, os, typetraits] | |
const | |
EnableTests = false | |
EnableCount = not EnableTests and false | |
EnableBench = not EnableTests | |
template bench(repeat: int; init, body: untyped): untyped = | |
var minTime = initDuration(days = 2) | |
for i in 1 .. repeat: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[cmdline, times, monotimes, random, hashes] | |
template bench(body: untyped): untyped = | |
let start = getMonoTime() | |
body | |
let finish = getMonoTime() | |
echo "Time: ", (finish - start).inMicroseconds, "μ sec" | |
proc main = | |
# Use paramCount() to initialize rand so that compiler cannot run this code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://nim-lang.org/docs/inotify.html | |
import std/[macros, os] | |
import posix, posix/inotify | |
macro testMasks(v: uint32; m: untyped; mstr: untyped; masks: varargs[untyped]): untyped = | |
masks.expectMinLen 2 | |
result = newStmtList() | |
let userCode = masks[^1] | |
for i in 0 ..< (masks.len - 1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[math, options] | |
import bigints | |
func sqrt(a: BigInt): Option[BigInt] = | |
if a < 0'bi: | |
none(BigInt) | |
else: | |
# Approximate BigInt as z = x * 2^(2y) | |
# (0 ≦ x < 2^62, y ∈ N) | |
# Then sqrt(z) = sqrt(x) * 2^y. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This program calculate an automorphic number. | |
# 何乗しても下N桁が同じになる数(自己同形数 Automorphic number)を計算して出力します。 | |
# | |
# How to compile and run | |
# 1. Install Nim (https://nim-lang.org/install.html) | |
# 2. $ nimble refresh | |
# 3. $ nimble install cligen | |
# 4. $ nimble install https://github.com/demotomohiro/bigints@#add-per-bit-op | |
# 5. $ nim c -d:danger --passC:-flto --passL:"-flto -s" amn.nim | |
# 6. $ ./amn run --numDigits=10000 > result.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[strformat, strutils, bitops] | |
import pixie, chroma | |
# define `nort` when opengl or windows system is not available. | |
when not defined(nort): | |
import nimgl/[glfw, opengl] | |
proc `{}`(image: var Image, x, y: int): var ColorRGBX = | |
## Accessing any pixels outside the bounds of the image is error | |
when not defined(danger): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Visualize how Pseudo-random number generators created | |
## with jump function and with random seed use PRNG state space. | |
## Install pixie with `nimble install pixie` | |
import std/[strformat, random] | |
import pixie | |
const | |
numRows = 32 | |
numColumns = 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
proc execQuote(args: varargs[string]) = | |
args.quoteShellCommand.exec | |
proc download(url, dist: string) = | |
mkDir dist.parentDir | |
execQuote "wget", url, "-O", dist | |
proc untar(src, dist: string) = |
NewerOlder