Skip to content

Instantly share code, notes, and snippets.

View fogleman's full-sized avatar

Michael Fogleman fogleman

View GitHub Profile
@fogleman
fogleman / main.py
Created August 23, 2014 16:16
PDS IMG to 3D Mesh
from PIL import Image
from pyhull.delaunay import DelaunayTri
import numpy as np
import gdal
import operator
import struct
import sys
def load(path):
print 'load'
@fogleman
fogleman / NSBezierPath+Ops.mm
Last active August 29, 2015 14:10
NSBezierPath+Ops.mm
//
// NSBezierPath+Ops.m
// Grids
//
// Created by Michael Fogleman on 12/2/14.
// Copyright (c) 2014 Michael Fogleman. All rights reserved.
//
#import "NSBezierPath+Ops.h"
#import "SkPath.h"
@fogleman
fogleman / mountain.py
Created January 10, 2015 22:20
G-Code Mountain
def load_blocks(path):
height = {}
with open(path, 'r') as fp:
for line in fp:
x, y, z = map(int, line.strip().split('|'))
height[(x, z)] = max(y, height.get((x, z), 0))
return height
def main():
height = load_blocks('blocks.txt')
@fogleman
fogleman / mountain.py
Created January 11, 2015 16:11
Generate Mountain in Craft
from builder import *
from world import *
from time import sleep
def mountain(x, y, z, w, radius, height, noise):
client = get_client()
set_block = client.set_block
set_blocks = client.set_blocks
for dx in range(-radius * 2, radius * 2 + 1):
for dz in range(-radius * 2, radius * 2 + 1):
@fogleman
fogleman / poisson.go
Created February 6, 2015 15:47
poisson.go
package pt
import (
"math"
"math/rand"
)
type poissonGrid struct {
r, size float64
cells map[Vector]Vector
@fogleman
fogleman / merge.py
Created May 1, 2015 15:58
Sum Dictionary Tuples
import operator
def merge(dicts):
result = {}
keys = reduce(operator.or_, [set(d) for d in dicts])
for key in keys:
values = [d[key] for d in dicts if key in d]
result[key] = tuple(reduce(operator.add, x) for x in zip(*values))
return result
@fogleman
fogleman / fabmo.py
Created July 12, 2015 00:14
Fabmo API Wrapper
import json
import requests
import sys
HEADERS = {'content-type': 'application/json'}
class Fabmo(object):
def __init__(self, host, port=9876):
self.url = 'http://%s:%s' % (host, port)
@fogleman
fogleman / main.go
Created August 21, 2015 00:54
Go 1.5 Crash
package main
import (
"fmt"
"log"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/ungerik/go-cairo"
)
@fogleman
fogleman / thing.scad
Created September 14, 2015 12:36
Thing
module pill() {
difference() {
hull() {
sphere(10, $fn=36);
translate([40, 0, 0])
sphere(10, $fn=36);
}
translate([0, 0, 14])
hull() {
sphere(5, $fn=36);
@fogleman
fogleman / fib.py
Created October 20, 2012 15:49
Simpler Fibonacci Iterator
class FibonacciIterator(object):
def __init__(self):
self.data = [0, 1]
def next(self):
self.data.append(sum(self.data))
return self.data.pop(0)
class Fibonacci(object):
def __iter__(self):
return FibonacciIterator()