Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / main.go
Created July 10, 2021 18:41
Split audio files into constant-length chunks
package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"github.com/unixpickle/essentials"
@unixpickle
unixpickle / go.mod
Last active February 28, 2021 18:41
Minimize the maximum of a mesh's SDF
module github.com/unixpickle/heart3d
go 1.15
require (
github.com/unixpickle/essentials v1.3.0
github.com/unixpickle/ffmpego v0.1.3
github.com/unixpickle/model3d v0.2.12
)
@unixpickle
unixpickle / decimate.go
Created July 23, 2020 01:39
2D decimation
func DecimateMesh(m *model2d.Mesh, maxVertices int) *model2d.Mesh {
m = model2d.NewMeshSegments(m.SegmentsSlice())
areas := map[model2d.Coord]float64{}
for _, v := range m.VertexSlice() {
areas[v] = VertexArea(m, v)
}
for len(areas) > maxVertices {
var next model2d.Coord
nextArea := math.Inf(1)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
func CreateMesh() *model3d.Mesh {
box := model3d.NewMesh()
stepSize := 0.05
addQuad := func(p model3d.Coord3D, normalAxis int) {
ax1 := model3d.Coord3D{X: stepSize}
ax2 := model3d.Coord3D{Y: stepSize}
if normalAxis == 0 {
ax1 = model3d.Coord3D{Z: stepSize}
} else if normalAxis == 1 {
@unixpickle
unixpickle / go.mod
Last active May 8, 2020 23:33
Deformation into sphere
module gists/deformation
go 1.14
require (
github.com/unixpickle/essentials v1.1.0
github.com/unixpickle/model3d v0.2.1
github.com/unixpickle/polish v0.0.0-20200508163631-1844661b331d
)
@unixpickle
unixpickle / hi.js
Created February 12, 2020 01:38
Bilinear interp
const canvas = document.createElement('canvas');
canvas.width = 400;
canvas.height = 400;
const ctx = canvas.getContext('2d');
ctx.font = '350px serif';
ctx.textBaseline = 'middle';
ctx.textAlign = 'center';
ctx.fillText('Hi', 200, 200);
const data = ctx.getImageData(0, 0, 400, 400);
@unixpickle
unixpickle / involutes.py
Created January 7, 2020 22:50
Circle involutes
import math
def involute_point(a, t):
c = math.cos(t)
s = math.sin(t)
d = t - a
return c + d * s, s - d * c
@unixpickle
unixpickle / extract_tar.go
Created December 22, 2019 22:31
Extract ImageNet tar in-place
// Command extract_tar can be used to extract a large
// ImageNet tarbal on a system that doesn't have enough
// storage for both the tarbal and the untarred data.
//
// As it extracts the tarbal, it truncates the original
// tar file so that it takes up less and less space.
//
// Based on this earlier gist for processing ImageNet tars:
// https://gist.github.com/unixpickle/7304c78032c9f433e28a87409f4d5aca
package main
@unixpickle
unixpickle / data.py
Created November 18, 2019 21:57
3D model generator model
"""
Reading data produced by an external program.
"""
import math
import random
import numpy as np
import torch