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
iterator testIter: int {.closure.} = | |
for i in 0..5: | |
yield i | |
for r in testIter(): | |
echo r | |
#outputs: 0 |
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 math | |
import unsigned | |
import strutils | |
import os, osproc | |
import times | |
import json | |
type | |
TVector = tuple[x, y, z: float] |
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
template toSeq(iter: expr): expr {.immediate.} = | |
var result = newSeq[type(iter)]() | |
for x in iter: result.add(x) | |
result | |
iterator something: string = | |
yield "Hello" | |
yield "World" | |
var info = something().toSeq() |
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
#Here's my program | |
proc x: | |
echo "this is a test" | |
when isMainModule: | |
#run X | |
x() |
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
template `??`*(value, default: expr): expr = | |
if value == nil: default | |
else: value | |
template `??`*[T](value : ref T, default : ref T) : ref T = | |
if value == nil: default | |
else: value | |
template `??`*[T](value : ref T, default : T) : T = | |
if value == nil: default |
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 | |
TSettingKind* = enum | |
SettingInt, SettingString, SettingChannel, SettingBool | |
TSettings = seq[TSetting] | |
TSetting* = object | |
name*: string | |
var settings: TTable[string, TSettings] | |
var newSetting = TSetting(kind: kind) |
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 sockets, asyncio, jester | |
import strtabs, htmlgen | |
let dispatch = newDispatcher() | |
##Import Web Handlers | |
get "/": | |
resp "Hello world" | |
##Procedures |
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
TEMPLATE: | |
#! stdtmpl | standard | |
# | |
#template view*(body: expr): stmt {.immediate.} = | |
# | |
<link href=style.css rel=stylesheet> | |
<title>$title</title> | |
<header>$title</header> | |
# body | |
<footer>the end</footer> |
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 read(ws: TWebSocketServer, client: TWebSocket): string = | |
var buffer = cstring(ws.buffer) | |
var read = client.socket.recv(buffer, 2) | |
var length = int(uint8(buffer[1]) and 127) | |
template readLength(size: int) = | |
## Read next `size` bytes to determine length | |
read = client.socket.recv(buffer, size, 0) | |
length = 0 #Reset the length to 0 |
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
<script> | |
var ws; | |
function connect() { | |
ws = new WebSocket("ws://localhost:8080"); | |
setTimeout(function() { | |
ws.close(); | |
connect(); | |
}, 20); |
OlderNewer