This file contains 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
dumpTree: | |
var dis: set[Distribution] = {} | |
if detectOs(Windows): | |
dis.incl Windows | |
## more detect os |
This file contains 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 distros | |
import macros | |
macro whichOs(): untyped = | |
result = newStmtList() | |
for dist in Distribution: | |
result.add newCall("echo", newLit dist , newLit " ", newCall("detectOs", newIdentNode($dist))) | |
whichOs() |
This file contains 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 distros | |
for dist in Distribution: | |
echo dist, detectOs(dist) | |
distrost.nim(53, 22) template/generic instantiation of `detectOs` from here | |
distros.nim(184, 28) Error: undeclared field: 'dist' | |
found 'dist' of kind 'forvar' |
This file contains 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 asyncdispatch, asyncnet | |
type | |
Server = ref object | |
socket: AsyncSocket | |
proc newServer(): Server = | |
Server(socket: newAsyncSocket()) | |
proc loop(server: Server, port = 7920) {.async.} = | |
server.socket.bindAddr(Port(port), "0.0.0.0") |
This file contains 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
# test with: `while true; do curl 127.0.0.1:8080; done` | |
# import threadpool | |
import locks | |
import os | |
import asyncdispatch | |
import asynchttpserver, asyncdispatch | |
var L: Lock | |
type Context = ref object {.pure.} |
This file contains 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 ServiceMain = proc(gSvcStatus: SERVICE_STATUS) | |
proc wrapServiceMain(mainProc: ServiceMain): LPSERVICE_MAIN_FUNCTION {.closure.} = | |
## wraps a nim proc in a LPSERVICE_MAIN_FUNCTION | |
return proc(dwArgc: DWORD, lpszArgv: LPTSTR) {.stdcall.} = | |
gSvcStatusHandle = RegisterServiceCtrlHandler( | |
SERVICE_NAME, | |
svcCtrlHandler | |
) | |
gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS | |
gSvcStatus.dwServiceSpecificExitCode = 0 |
This file contains 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
## Store multiple "bool" values in an integer | |
# http://blog.millermedeiros.com/using-integers-to-store-multiple-boolean-values/ | |
type foos = enum | |
foo = 1.shl 0, # 1 | |
baa = 1.shl 1, # 2 | |
baz = 1.shl 2 # 4 | |
echo foo.int | |
echo baa.int | |
echo baz.int |
This file contains 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 webview | |
import strutils | |
import os | |
const indexHTML = """ | |
<!doctype html> | |
<html> | |
<head> |
This file contains 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 httpclient, asyncdispatch | |
var client = newAsyncHttpClient() | |
proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} = | |
echo("Downloaded ", progress, " of ", total) | |
echo("Current rate: ", speed div 1000, "kb/s") | |
client.onProgressChanged = onProgressChanged | |
echo waitFor client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test") |
This file contains 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 times | |
import options | |
type | |
Entry = object of RootObj | |
emergeDate: Option[DateTime] | |
publishDate: Option[DateTime] | |
proc newEntry(): Entry = | |
# Gives: Error: fields not initialized: emergeDate, publishDate. |
NewerOlder