Skip to content

Instantly share code, notes, and snippets.

View treeform's full-sized avatar

Andre von Houck treeform

View GitHub Profile
spawn:
var socket = newSocket()
print "1"
socket.connectFi("localhost", Port(12321))
print "2"
socket.sendFi("spawn #1\c\L")
print "4"
echo socket.recvFi()
socket.close()
print "5"
@treeform
treeform / html.nim
Last active January 11, 2020 05:47
let a = html:
html:
lang "en"
head:
meta:
charset "utf-8"
title "myTitle"
meta:
name "description"
content "myDescription"
## Bare-bones SDL2 example
import sdl2
import typography, vmath, flippy, chroma, tables, times
discard sdl2.init(INIT_EVERYTHING)
var
window: WindowPtr
render: RendererPtr
## Bare-bones SDL2 example
import sdl2
discard sdl2.init(INIT_EVERYTHING)
var
window: WindowPtr
render: RendererPtr
window = createWindow("SDL Skeleton", 100, 100, 640,480, SDL_WINDOW_SHOWN)
const
cbWebSafe64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
proc encodeWebSafeNoPadding*(s: string): string =
## encodes `s` into web safe base64 representation.
proc encodeSize(size: int): int =
return (size * 4 div 3) + 6
result.setLen(encodeSize(s.len))
# Get the log itself
var
logStr = cast[ptr GLchar](alloc(logSize))
logLen: GLsizei
glGetShaderInfoLog(vertShader, logSize.GLsizei, logLen.addr, logStr)
# Print the log
echo $logStr
import ws, asyncdispatch, asynchttpserver
proc cb(req: Request) {.async.} =
var ws = await newWebSocket(req)
echo "Got ws connecting with protocol ", ws.protocol
if ws.protocol == "alpha":
await ws.send("Welcome Protocol Alpha")
ws.close()
var server = newAsyncHttpServer()
import ws, asyncdispatch, asynchttpserver
proc cb(req: Request) {.async.} =
var ws = await newWebSocket(req)
await ws.send("Welcome")
ws.close()
var server = newAsyncHttpServer()
waitFor server.serve(Port(9001), cb)
import strutils
proc initDecodeTable*(): array[256, char] =
# computes a decode table at compile time
for i in 0 ..< 256:
let ch = char(i)
var code = 255
if ch >= 'A' and ch <= 'Z': code = i - 0x00000041
if ch >= 'a' and ch <= 'z': code = i - 0x00000047
{.compile: "openwl/source/osx-cocoa/MainThreadExecutor.mm".}
{.compile: "openwl/source/osx-cocoa/WLAppDelegate.mm".}
{.compile: "openwl/source/osx-cocoa/WLContentView.mm".}
{.compile: "openwl/source/osx-cocoa/WLWindowObject.mm".}
{.compile: "openwl/source/osx-cocoa/globals.mm".}
{.compile: "openwl/source/osx-cocoa/keystuff.mm".}
{.compile: "openwl/source/osx-cocoa/miscutil.mm".}
{.compile: "openwl/source/osx-cocoa/openwl.mm".}
{.compile: "openwl/source/osx-cocoa/private_defs.mm".}
{.passL: "-framework Foundation" .}