Skip to content

Instantly share code, notes, and snippets.

View User4574's full-sized avatar

Nat Lasseter User4574

View GitHub Profile
@User4574
User4574 / alleq.hs
Created April 12, 2012 00:55
Haskell function to check all elements of a list are equal
alleq :: Eq a => [a] -> Maybe a -> Bool
alleq [] _ = True
alleq (h:t) Nothing = alleq t (Just h)
alleq (h:t) (Just e)
| h == e = alleq t (Just e)
| True = False
@User4574
User4574 / stltogl
Created June 29, 2012 19:11
Vim Script to convert an STL file to openGL glVertex3f()s for inclusion in a c program
"Get rid of most of the bumpf in the file
:g/solid/d
:g/loop/d
:g/endfacet/d
"Get rid of leading and trailing spaces
:%s/^ *//g
:%s/ *$//g
"Unify spaces
:%s/ \+/ /g
"Rewrite each facet normal into a glNormal3f
@User4574
User4574 / NDFA2DFAexample
Created March 26, 2013 19:54
NDFA to DFA example for VFSM
This example from http://en.wikipedia.org/wiki/Powerset_construction
Comment: In the NDFA Extension to the VFSM syntax (VFSMv2N), lambda: and epsilon: are equivalent
Comment: In VFSMv2N, lambda: and epsilon: are special transitions indicating transition on no input
Start: 1
Accept: 3 4
Edges:
1 0 2
1 lambda: 3
2 1 2
-module(ring).
-export([bench/2, ring/2]).
bench(N, M) ->
timer:tc(?MODULE, ring, [N, M]).
ring(N, M) ->
SPID = spawn(fun() -> createstartnode() end),
LPID = create_ring(N-1, SPID),
SPID ! LPID,
package main
import (
"fmt"
"sync"
"time"
)
var wg sync.WaitGroup
@User4574
User4574 / box.mzn
Last active April 12, 2016 12:59
Intended to find the dimensions of a rectangle with an area at least n units and a ratio e.
include "globals.mzn";
% Given an integer n and a real e
par int: n = 566*708;
par float: e = 16/9;
% Find two integers r <= c
var int: r; var int: c;
constraint c >= r;
output [
@User4574
User4574 / make.rb
Created August 21, 2016 21:56
Ruby script to make playing The Factory efficient
#!/usr/bin/env ruby
require 'json'
Products = JSON.parse(DATA.read)
Productindex = Products.keys
ingredientsstack = []
buildstack = {}
build = ARGV.shift
@User4574
User4574 / deep-extend.js
Created August 22, 2016 13:15 — forked from amatiasq/deep-extend.js
Deep extend for simple JSON objects
function deepExtend(target, source) {
Object.keys(source).forEach(function(key) {
var value = source[key];
var dest = target[key];
var sourceType = typeof value;
var destType = typeof target[key];
if (Array.isArray(value) && Array.isArray(dest))
target[key] = dest.concat(value);
else if (sourceType === destType && sourceType === 'object')
> isCorner(3);
undefined
> rows
5
> cols
5
> isCorner
function isCorner(i) {
return
i == 0 ||
s is need "stdio".
f is nonary {
add is binary {
PRE + POST
},
s:println 4 add 5,
s:println add
}.