Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
# Compile with --gc:arc
import ngxcmod, strutils
proc init(ctx: ContextCycle) {.exportc: "ngx_link_func_init_cycle", dynlib, cdecl.} =
setupForeignThreadGc()
ctx.cyc_log(INFO, "hello from Nim")
proc exit(ctx: ContextCycle) {.exportc: "ngx_link_func_exit_cycle", dynlib, cdecl.} =
setupForeignThreadGc()
ctx.cyc_log(WARN, "goodbye, from Nim w/ <3")
@Varriount
Varriount / PropertyLogger.java
Last active June 18, 2020 17:04 — forked from sandor-nemeth/PropertyLogger.java
Spring Boot - Log all configuration properties on application startup
package org.flowable.rest.app;
import java.util.Arrays;
import java.util.stream.StreamSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.AbstractEnvironment;
proc this: void {.cdecl, exportc, dynlib.} =
var i = 1
var a = 2
var z = 3
proc foo(): int =
echo "here"
return i + a + z + 65
proc processClient(client: AsyncSocket): owned(Future[void]) =
var retFuture_17906029 = newFuture("processClient")
iterator processClientIter_17906030(): owned(FutureBase) {.closure.} =
while true:
var future_17906031 = recvLine(client, {SafeDisconn}, 1000000)
yield future_17906031
let line = read(future_17906031)
if len(line) == 0:
break
for c in items(clients):
import module_b
from module_c import nil
echo HelloFromModuleB
echo module_c.HelloFromModuleC
@Varriount
Varriount / forbench.nim
Created April 13, 2020 19:53
Note: Requires the `criterion` Nimble package.
import criterion
var cfg = newDefaultConfig()
cfg.brief = true
const
sepSet = {'/', '\\'}
sepArray = ['/', '\\']
proc dummy(a: string): bool =
from strutils import nil
template copy(target: string, tRegion: Slice|HSlice, source: string, sRegion: Slice|HSlice): untyped =
template resolve(c, i): untyped =
when i is BackwardsIndex:
len(c) - int(i)
else:
i
# Figure out the length of each slice
# A lazybuf is a lazily constructed path buffer.
# It supports append, reading previously appended chars,
# and retrieving the final string. It does not allocate a buffer
# to hold the output until that output diverges from s.
type lazybuf = object
path: string
buf: string
w: int
volAndPath: string
volLen: int
type
WindowsPath* = distinct string
PosixPath* = distinct string
when OS_IS_WINDOWS:
type
Path* = distinct WindowsPath
IPath* = distinct Path
else:
type
async proc foo(i: int) int =
await bar(i) // gives i+1
await bar(i+1) // gives i+2
await bar(i+2) // gives i+3
# To
proc foo(state: var State) =
if state.state == 1:
state.waiting_on = bar(state.bar_state, state.i)