Skip to content

Instantly share code, notes, and snippets.

View onionhammer's full-sized avatar

Erik O'Leary onionhammer

  • CRF USA
  • Minneapolis, MN
View GitHub Profile
## Imports
import marshal
## Types
type TLog* = ref object
path: string
file: TFile
@onionhammer
onionhammer / httpserver.nim
Created November 15, 2013 16:43
HTTP Server crashes with invalid header
import parseutils
proc currentNext(header: string): tuple[key, value: string] =
var i = 0
var key = ""
var value = ""
i = header.parseUntil(key, ':')
inc(i) # skip :
@onionhammer
onionhammer / time.nim
Created November 17, 2013 20:19
Times issue
import times
var time = getTime()
var local = time.getLocalTime() - TTimeInterval(hours: 2)
echo local.format("h:mm:ss tt")
assert local != getTime().getLocalTime()
@onionhammer
onionhammer / rng.nim
Last active December 28, 2015 14:59
Range issue
type TSomeRange = object
hour: range[0..23]
var value: string
#Works
var val6 = TSomeRange(hour: 6)
value = $(if val6.hour > 12: val6.hour - 12 else: val6.hour)
echo value
#! strip | stdtmpl
#from irc import TIRCMType
#from times import getTime
#import utilities, models
#
#proc logview(channel: TIRCChannel): string =
#result = ""
#
<ul class=logview>
#for message in channel.log:
@onionhammer
onionhammer / ideas.txt
Created December 8, 2013 21:22
Nimrod-Sublime ideas
v complete syntax highlighting
v Syntax highlighting of sourcecode filters
* goto definition
- TODO: Use nimrod's CaaS once it's not borken
- Documentation lookup (be able to ctrl/shift/P and look up nimrod docs)
- Some way of specifying the 'project.nim' file
- SublimeREPL "i" interactive nimrod mode
@onionhammer
onionhammer / times.nim
Last active December 31, 2015 07:09
Times leak?
import os, times
var i = 0
while true:
var t = getTime()
var l = t.getLocalTime()
var g = t.getGMTime()
if i mod 100 == 0:
import macros
# Generate tags
macro make(names: openarray[expr]): stmt {.immediate.} =
result = newStmtList()
for i in 0..names.len - 1:
result.add newProc(
name = ident($names[i]).postfix("*"),
params = [
import templates
let NO_PROC = proc(n:var string) = discard
proc master(result: var string, head = NO_PROC, body = NO_PROC, footer = NO_PROC) = tmpl html"""
<head>
${ head(result) }
</head>
<body>
${ body(result) }
import templates, macros
template master(content: stmt): stmt {.immediate.} =
template body = content
tmpli html"""
<html>
<body>
${ body() }
</body>