Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
def display_hint(value):
return 'string'
def to_string(value):
if value:
l = int(value['Sup']['len'])
return value['data'][0].address.string("utf-8", "ignore", l)
else:
return ""
@Varriount
Varriount / gist:b93c845f0632ca2d6b6099f7443a356d
Last active February 9, 2020 09:58
Compiletime -> Runtime Data Issue
/* Generated by Nim Compiler v1.1.1 */
/* (c) 2019 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: MacOSX, amd64, clang */
/* Command for C compiler:
clang -c -w -I/usr/local/Cellar/nim/HEAD-81a4379/nim/lib -I/Users/csweetser/Personal -o /Users/csweetser/.cache/nim/untitled_d/@muntitled.nim.c.o /Users/csweetser/.cache/nim/untitled_d/@muntitled.nim.c */
#define NIM_INTBITS 64
#include "nimbase.h"
#include <string.h>
proc copy[T](d: T): T =
when T is ref:
# return a new reference that is a copy (though not a deep copy) of T
else:
return d # regular object copy logic
proc processData[T](data: T): T =
result = copy(data)
sort(result)
trim(result)
iterator foo(a, b: int): int
iterator foo(a, b: int): int =
for x in a..b:
yield x
var s = @["here", "there", "everywhere"]
proc foo(s: var seq[string], s2: var string) =
echo "1 ", repr(s)
echo "2 ", s2
s[^1] = "when"
s2.add("this")
s.setLen(2)
s2.add("yes")
echo "3 ", repr(s)
import npeg
let parser = peg "COMMANDS":
COMMANDS <- COMMAND * *( SEPERATOR_SYM * COMMAND )
COMMAND <- +(
SPACES |
REDIRECT_SYM |
COMMAND_SUB |
VARIABLE_SUB |
DQ_STRING_LIT |
type
User = ref object
id: int
cParent: User
template parent(target: typed): untyped =
when type(target) is User:
if isNil(target.cParent):
target.cParent = await loadParent(target)
@Varriount
Varriount / aws.nim
Last active January 9, 2020 23:06
AWS Request Signing for Nim. Requires the `nimcrypto` package.
import strutils
import tables
import algorithm
import httpcore
import unicode
import strformat
import times
import nimcrypto
import httpclient
import utils
@echo off
set the32bitProgram="typedef int is32bit[sizeof(void*) == 32 ? 1 : -1];"
set the64bitProgram="typedef int is32bit[sizeof(void*) == 64 ? 1 : -1];"
rem Use "|| goto :error" after commands that can fail to invoke the error
rem handler.
goto :after_error
:error
import pegs
let p = peg"""
function_call <- \ident '(' parameters ')'
parameters <- (parens / string / [^)] )*
parens <- '(' parameters ')'
string <- dq_string / sq_string
dq_string <- DQUOTE (BSLASH . / [^DQUOTE])* DQUOTE
sq_string <- SQUOTE (BSLASH . / [^SQUOTE])* SQUOTE