This file contains hidden or 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
# AWS Version 4 signing example | |
# EC2 API (DescribeRegions) | |
# See: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html | |
# This version makes a GET request and passes the signature | |
# in the Authorization header. | |
import base64, httpclient, hmac, nimSHA2, os, times, strutils, httpcore | |
# ************* REQUEST VALUES ************* |
This file contains hidden or 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
from x as y import nil | |
from a import b |
This file contains hidden or 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 is an example how an abstract syntax tree could be modelled in Nim | |
type | |
NodeKind = enum # the different node types | |
nkInt, # a leaf with an integer value | |
nkFloat, # a leaf with a float value | |
nkString, # a leaf with a string value | |
nkAdd, # an addition | |
nkSub, # a subtraction | |
nkIf # an if statement | |
This file contains hidden or 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
const libtorrentDllName = "libtorrent-rasterbar.9.dylib" | |
type | |
Tags* {.size: sizeof(cint).} = enum | |
TAG_END = 0, | |
SES_FINGERPRINT, | |
SES_LISTENPORT, | |
SES_LISTENPORT_END, | |
SES_VERSION_MAJOR, | |
SES_VERSION_MINOR, |
This file contains hidden or 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 tables, marshal, json, strutils, macros, sequtils | |
type | |
ConstraintViolation* = object of Exception | |
proc newConstraintViolation(msg: string): | |
raise newException(ConstraintViolation, msg) | |
This file contains hidden or 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
proc `*`*[M,N,T,T2,K](a: Matrix[M,N,T]; k:K): Matrix[M,N,T2]= | |
for i in result.low .. result.high: | |
for j in result[0].low .. result[0].high: | |
result[i][j] = k * a[i][j] |
This file contains hidden or 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
macro loadValue(dest, source: untyped, key: static[string], required=true): untyped = | |
## Loads a value from a JSON node to a member of the same name | |
let keyIdent = ident(key) | |
result = quote do: | |
when `required`: | |
var node = `source`[`key`] | |
else: | |
var node = `source`.getOrDefault(`key`) | |
if node != nil: |
This file contains hidden or 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 strutils | |
import math | |
#[ | |
Module name: Implementation of MergeSort recursion. | |
Author: Benny E. | |
Mail: elgazarbenny at gmail.com | |
]# | |
This file contains hidden or 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
type UncheckedCharArray {.unchecked.} = array[0, char] | |
var s = "hello world" | |
echo repr(cast[ptr UncheckedCharArray](addr s[0])) | |
# ref 0x7f037ebf3060 --> ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o'] |
This file contains hidden or 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
proc someCProcedure[L](arr: ptr array[L, int]) {.header: "...", importc: "...".} | |
proc wrapper(arr: openarray[int]) = | |
someCProcedure(cast[array[1, int]](unsafeAddr arr[0])) |