Skip to content

Instantly share code, notes, and snippets.

import times
proc fib(n: int32): int32 =
if n <= 1: n
else: fib(n-1) + fib(n-2)
proc main =
let timeStart = epochTime()
var result: int32 = 0
import os, times, future, math, sequtils, strutils
proc get_primes7(n: int32): seq[int32] =
if n < 2:
return @[]
result = @[2'i32]
if n == 2:
return
@def-
def- / foo.nim
Created February 24, 2017 21:19
import base64, strutils, sha256, os
import libsodium.sodium
import libsodium.sodium_sizes
const
usage = """
DDCATool - Tool to establish and manage a DDNet CA
usage:
ddcatool <command>
Commands:
template inReverse(x, y) =
y
x
inReverse do:
echo "Hello World"
do:
echo "Goodbye World"
@def-
def- / at.nim
Last active June 19, 2016 18:02 — forked from Varriount/at.nim
import asyncdispatch
template doAsync(name: expr; body: untyped): untyped {.immediate.} =
proc name() {.async.} =
body
asyncCheck(name())
doAsync(namething):
echo "hello"
#
# Search wikipedia dump for a string
#
# XML parse code credit: Rob Speer (https://github.com/rspeer/wiki2text)
#
import re, options, strutils, os, streams, parsexml
let mySearchRe = re"archive[.]org/w?e?b?/?[0-9]{1,14}/|[{][{][ ]?[Ww]ayback"
# Naive
proc containsAll(letters, text: string): bool =
for c in letters:
if c notin text:
return false
return true
# Only check each letter once
proc containsAll2(letters, text: string): bool =
var chars: set[char]
proc a(x: int): int = x + 1
proc b(x: int): int = x + 2
proc c(x: int): int = x + 3
proc d(x: int): int = x + 4
echo 5.d.c.b.a
var xs: seq[tuple[nr: int, name: string]] = @[(1, "foo"), (2, "bar"), (3, "foobar"), (0, "baz")]
# Imperatively:
var max = xs[0]
for i in 1 .. xs.high:
if xs[i].nr > max.nr:
max = xs[i]
echo max
# Functionally:
var a: ref int = new(int) # or just: var a = new int
a[] = 10
var p = a
p[] = 20