Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
proc `&`[N1,N2, T1](arg1: array[N1,T1], arg2: array[N2,T1]): auto =
const length = (high(arg1) - low(arg1)) + (high(arg2) - low(arg2)) + 2
var res: array[length, T1]
var i = 0
for x in arg1:
res[i] = x
i += 1
for x in arg2:
res[i] = x
import jsmn, streams, tables, hashes, strutils, macros, sequtils
type
ConstraintViolation* = object of Exception
proc checkConstraint(value: bool, message: string) =
if value:
raise newException(ConstraintViolation, message)
import jsmn, streams, tables, hashes, strutils, macros, sequtils
# StringRef support
type
StringRef = ref string
StringCache = TableRef[Hash, StringRef]
converter stringToStringRef(s: string): StringRef =
new(result)
result[] = s
# Stringify an integer
stringified_int = Schema(All(
int,
Coerce(str) # Same as `lambda x: str(x)
))
def AcceptSingleOrListOf(sub_schema):
"""
Returns a wrapped schema that either accepts the original schema, or a list
# Copyright 2017 Mamy André-Ratsimbazafy
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
let hex = 0xDEADBEEF'u32
proc initNumber(i: int): int = i+1
proc main() =
var resources: seq[int] = @[]
template initResource(initExpression: untyped): untyped =
var res = initExpression
resources.add(res)
res
var a, b: int
import linalg
{.experimental.}
# Global templates
template foreach(expression, iter: untyped): untyped =
for element in mitems(iter):
expression(element)
main.nim(17, 17) template/generic instantiation from here
dadren/dadren/bsp.nim(63, 13) template/generic instantiation from here
dadren/dadren/bsp.nim(30, 20) Error: inheritance only works with non-final objects
The below code is not valid C code - a preprocessor must be used:
```
CHAKRA_API
JsParseModuleSource(
_In_ JsModuleRecord requestModule,
_In_ JsSourceContext sourceContext,
_In_ BYTE* script,
_In_ unsigned int scriptLength,
_In_ JsParseModuleSourceFlags sourceFlag,