Skip to content

Instantly share code, notes, and snippets.

View fowlmouth's full-sized avatar
🦃

Tim E fowlmouth

🦃
  • United States of America
View GitHub Profile
import zlib
proc compress(source: string): string =
var
sourcelen = source.len
destlen = sourcelen + (sourcelen.float * 0.1).int + 16
result = ""
result.setLen destLen
#
# STFL - The Structured Terminal Forms Language/Library
# Copyright (C) 2006, 2007 Clifford Wolf <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
import endians
proc swapEndian16*(outp, inp: pointer) =
## copies `inp` to `outp` swapping bytes. Both buffers are supposed to
## contain at least 2 bytes.
var i = cast[cstring](inp)
var o = cast[cstring](outp)
o[0] = i[1]
o[1] = i[0]
when cpuEndian == bigEndian:
@fowlmouth
fowlmouth / ansicolors.nim
Created September 12, 2012 23:58
ansi colors
from strutils import format
type TColor = enum
black = 0, red, green, yellow, blue, magenta, cyan, white, default
proc color(s: string; fg: TColor; bg = black): string =
result = "\x1B[$1;$2m$3\x1B[0m".format(fg.int + 30, bg.int + 40, s)
echo color("error!", red)
echo color("sup", green, yellow)
template foo(): stmt =
var x = "hello"
echo x
foo()
echo(definedInScope(x))
template dirtyfoo(): stmt {.dirty.}=
var x = "hello"
echo x
@fowlmouth
fowlmouth / colorize.nim
Created September 30, 2012 07:00
irc colorizer
import math, os, strutils
randomize()
proc color(c: string; res: var string; fg = random(30), bg = random(30)) =
res.add '\3'
res.add($fg)
res.add ','
res.add($bg)
res.add c
import strutils
when defined(parserPeg):
import pegs
elif defined(parserRegex):
import re
else:
{.error: "define either parserPeg or parserRegex".}
proc last*[A](some: seq[A]): A = return some[len(some)-1]
@fowlmouth
fowlmouth / luathinger.nim
Created October 8, 2012 23:55
lua repl thinger
import lua, lualib, lauxlib, sfml, sfml_colors, strutils, sf_gui, json
const
ScreenW = 800
ScreenH = 600
var
window = new_render_window(video_mode(ScreenW, ScreenH, 32), "Lame Lua", sfDefaultStyle)
event: TEvent
text = newText("herro", guifont, 18)
gui = newContainer("luathinger_settings.json")
@fowlmouth
fowlmouth / window.nim
Created October 11, 2012 15:19
opengl wrapper wrapper, maybe
import opengl
when defined(Linux):
import x, xlib, xutil
type
PWindow = ref TWindow
TWindow = object
when defined(Linux):
type
Bool32* {.size: sizeof(cint).} = enum
False32 = 0, True32 = 1
converter toBool*(a: Bool32): bool = bool(a)
when isMainModule:
var x = False32
if x: echo "hi"
else: echo "not x"