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
proc mimeType*(filePath: string): string = | |
case filePath.splitFile.ext: | |
of ".html": "text/html" | |
of ".js": "text/javascript" | |
of ".css": "text/css" | |
of ".ttf": "font/ttf" | |
of ".png": "image/png" | |
of ".jpg", ".jpeg": "image/jpeg" | |
of ".svg": "image/svg+xml" | |
else: "text/plain" |
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
proc genWeekEtag*(filepath: string): string = | |
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag | |
let | |
info = getFileInfo(filepath) | |
ns = info.lastWriteTime.toUnix().uint64 * 1e9.uint64 + info.lastWriteTime.nanosecond.uint64 | |
time = toHex(ns, sizeof(uint64)).toLowerAscii() | |
size = toHex(info.size, sizeof(uint64)).toLowerAscii() | |
result = "W/" & '"' & size & '-' & time & '"' | |
proc serveFile*(req: Request, path: string) {.async.} = |
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
#define GLFW_INCLUDE_NONE | |
#import <GLFW/glfw3.h> | |
#define GLFW_EXPOSE_NATIVE_COCOA | |
#import <GLFW/glfw3native.h> | |
#import <Metal/Metal.h> | |
#import <QuartzCore/QuartzCore.h> | |
#import <simd/simd.h> | |
#include <assert.h> | |
#include <stdlib.h> |
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
## Based on the work of https://github.com/edin/raytracer | |
## MIT License | |
## Copyright (c) 2021 Edin Omeragic | |
import benchy, chroma, math, times, glm | |
from pixie import Image, newImage, writeFile, setRgbaUnsafe | |
type Vec3 = glm.Vec3[float32] | |
{.push inline, noinit, checks: off.} |
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
proc fetchStr(req: Request): (string, seq[string]) = | |
## Fetches a URL and returns header and chunks. | |
var socket = newSocket() | |
if req.url.scheme == "https": | |
var ctx = | |
try: | |
let caCertPath = getAppDir() / "cacert.pem" |
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 math | |
# See https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/ | |
# for details of this function | |
func binomialCoeff(n, k: int): int = | |
var res = 1 | |
var k = k | |
if (k > n - k): | |
k = n - k | |
for i in 0 ..< k: |
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 fidget, vmath | |
proc drawMain() = | |
... exported code here .... | |
windowFrame = vec2(620, 140) | |
startFidget(drawMain) |
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
name: Run tests | |
on: [push, pull_request] | |
jobs: | |
build: | |
runs-on: windows-2019 | |
steps: | |
- name: "install choosenim" | |
id: cache-choosenim | |
run: curl -OL https://github.com/dom96/choosenim/releases/download/v0.6.0/choosenim-0.6.0_windows_amd64_debug.exe |
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
# nim c -r --threads:on --gc:orc | |
import cpuinfo, os, random, locks, deques | |
type | |
WorkReq = ref object | |
id: int | |
WorkRes = ref object | |
id: 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 math | |
func genCache(): array[100, int] = | |
for i in 0 .. 99: | |
let | |
a = i mod 10 | |
b = (i div 10) mod 10 | |
result[i] = int(a ^ a) + int(b ^ b) | |
const |
NewerOlder