Skip to content

Instantly share code, notes, and snippets.

@nsf
nsf / guidemo.fs
Last active August 29, 2015 14:27
module NG.FS.GUIDemo
open System
open System.Collections.Generic
open NG
open NG.FS.GUI
open NG.FS.GUI.Common
open NG.FS.GUI.Windows
open NG.FS.GUI.Widgets
open NG.FS.Coroutines
type DefaultWindowStyle () as this =
member val Color = ShadowedTextColor(RGBA8.White, RGBA8(0, 0, 0, 127)) with get, set
member val Alignment = TextAlignment.Left with get, set
member val Ellipsis = Char.ConvertToUtf32("…", 0) with get, set
member val Font = getFont guiResourceGroup "fonts/dejavu.font" with get, set
member val DecorNine : LazyNineAtlasTextures = getNineAtlasTextures guiResourceGroup "atlases/gui.atlas#decor" with get, set
member val HandleSizes = lazy (this.DecorNine.Sizes |> Array.map (Vec2i.Max (Vec2i 5)))
interface IWindowStyle with
override s.AdditionalSize w = nineAdditionalSize s.DecorNine.Sizes
@nsf
nsf / omg.fs
Last active August 29, 2015 14:26
module NG.FS.ResourceCache
open NG
open NG.FS.Coroutines
open System
open System.Collections.Generic
type private SharedResource<'T> (r : 'T) =
member val Mutex = Mutex()
member val Loaded = false with get, set
module NG.SExp
open FParsec
type Node =
| Scalar of string
| List of Node list
let grammar =
// special char is the one that cannot be part of a naked scalar value
module NG.FS.Coroutines
open System
open System.Threading
open System.Collections.Generic
open System.Collections.Concurrent
type Type =
| CPU = 0
| IO = 1
@nsf
nsf / lines.lua
Last active August 29, 2015 14:05
Lua line iterator
-- Iterate over all lines in `text`, use it like this (handles only
-- plain "\n", not "\r\n"):
-- for line_num, line in Lines(text) do
-- -- line_num - number of the line, starting from 1
-- -- line - contents of the line without "\n"
-- end
local function Lines(text)
local function next_line(state)
local text, begin, line_n = state[1], state[2], state[3]
if begin < 0 then
@nsf
nsf / gist:10246593
Last active August 29, 2015 13:58
Marching Cube Triangles
// Marching Cubes configurations, packed to 64 bit each.
//
// Offset 0 bits - a 4 bit integer, the number of indices.
// Offset 4 bits and further - 4 bit numbers, edge indices.
//
// Edges configuration:
//
// 3
// +-----------------------+
// / | / |
# Maintainer: Rodrigo Bezerra <rodrigobezerra21 at gmail dot com>
# Contributor: delor <bartekpiech@gmail com>
# Contributor: Lukas Jirkovsky <l.jirkovsky@gmail.com>
# Contributor: Dan Vratil <progdan@progdansoft.com>
# Contributor: thotypous <matiasΘarchlinux-br·org>
# Contributor: Imanol Celaya <ornitorrincos@archlinux-es.org>
# Contributor: heinz from #qt-creator
pkgname=qtcreator-git
pkgver=3.0.1.840.gaa2a063
@nsf
nsf / weird.cc
Created December 6, 2013 06:28
Very interesting chunk of code and very interesting performance results.
#include <cstdio>
const int Size = 256;
static int opti_killer = 2;
int test1() {
int *buf = new int[Size*Size*2];
int out = 0;
#define bufget(buf, x, y, z) buf[y*Size+x+((z)%2)]
for (int z = 0; z < Size; z++) {
@nsf
nsf / bootstrap.lua
Created October 11, 2013 12:40
3rd party libs bootstrap script
#!/usr/bin/env lua
local function sh(fmt, ...)
local cmd = string.format(fmt, ...)
return os.execute(cmd)
end
local function sh_or_err(fmt, ...)
local cmd = string.format(fmt, ...)
if not os.execute(cmd) then