Skip to content

Instantly share code, notes, and snippets.

Avatar

JR shivshank

  • Buffalo, NY
View GitHub Profile
@shivshank
shivshank / fd_btree.rs
Created Nov 14, 2017
Fixed Depth Binary Tree
View fd_btree.rs
use std::fmt::Debug;
trait BtreeTrait: Debug {}
#[derive(Debug)]
struct Btree<T: Debug, Tail: BtreeTrait> {
val: T,
left: Option<Tail>,
right: Option<Tail>,
}
View HOPM.md
/// Captures are the macro equivalent of enums and macro 1.1 match arms. The capture either
/// contains one anonymous match arm or any number of named match arms. Captures are reusable,
/// i.e. they can be bound to scoped constants which can then be referred to any number of 
/// times.
[pub] [macro] capture vertex_attribute {
    /// you can use braces, brackets, or parentheses after the colon
    unnamed: ( $kind:ty ),
    named: {
        $name:ident : $kind:ty
@shivshank
shivshank / playground.rs
Created Sep 3, 2017 — forked from anonymous/playground.rs
Rust code shared from the playground
View playground.rs
fn main() {
use shape_args::Dot;
draw(Dot(5.5));
}
// I need a function that works like this:
// pub fn draw<D: Drawable, T: Into<D>>(d: T) {
// but where Rust can always infer what D is
pub fn draw<T: DrawableArg>(d: T) {
@shivshank
shivshank / syn_evaluate_binary_sum.rs
Last active Jul 20, 2017
Parses (a very specific subset) of syn::ConstExpr for use with procedural macros
View syn_evaluate_binary_sum.rs
fn evaluate_bin_sum(expr: &syn::ConstExpr) -> u64 {
match expr {
// TODO: Fix the pattern (first match is left == literal, right == binary op, second match should be both are literals)
&syn::ConstExpr::Binary(syn::BinOp::Add, ref left, ref right) => {
extract_int_value(left) + evaluate_bin_sum(right)
},
&syn::ConstExpr::Binary(syn::BinOp::Add, ref left, ref right) => {
extract_int_value(left) + extract_int_value(right)
},
_ => {
@shivshank
shivshank / RunPython.bat
Created Jul 30, 2016
A script for running python
View RunPython.bat
rem add this command to the shortcuts file in Notepad++
rem run_python.bat &quot;$(FULL_CURRENT_PATH)&quot;
@echo off
Set filename=%1
For %%A in (%filename%) do (
Set Folder=%%~dpA
Set Name=%%~nxA
)
@shivshank
shivshank / README.md
Created Jul 19, 2016
Count the lines of various files, ignoring lines that start with //
View README.md

I've written this like a billion times because it's fun. The above code is pretty gross but it works...

It will kind of ignore commented lines, assuming those lines are commented out with //.

@shivshank
shivshank / vox_to_obj_exporter.py
Last active Dec 19, 2020
Exports from MagicaVoxel VOX to OBJ. Can preserve all edges for easy editing in a program like Blender.
View vox_to_obj_exporter.py
"""
This script is designed to export a mass amount of MagicaVoxel .vox files
to .obj. Unlike Magica's internal exporter, this exporter preserves the
voxel vertices for easy manipulating in a 3d modeling program like Blender.
Various meshing algorithms are included (or to be included). MagicaVoxel
uses monotone triangulation (I think). The algorithms that will (or do)
appear in this script will use methods to potentially reduce rendering
artifacts that could be introduced by triangulation of this nature.
@shivshank
shivshank / renderer.java
Created Nov 8, 2015
A simple 2D Java Renderer (incomplete example implemenation)
View renderer.java
/* An example implemenation of data structures to support a 2D Renderer in (semi) Java... */
class abstract Body {
public Vector2f posNext;
public Vector2f posPrev;
/**
* The actual position of the object at time t = t0 + dt * alpha.
*/
protected Vector2f pos = new Vector2f(0f, 0f);
@shivshank
shivshank / physics.java
Last active Nov 1, 2015
A (very) simple 2d Java Phyics Simulator
View physics.java
/* This is a work in progress, not done yet (doesn't do anything in fact!).*/
// I don't have a website, so it's just my screen name... feel free to refactor
// package name how you like. But credit me plz ;D
package shivshank.engine.physics;
import somepackage.that.doesnt.exist.yet.Vector2f;
import java.util.List;
import java.util.ArrayList;
@shivshank
shivshank / PollingDemo.py
Created Oct 10, 2015
Monitor new files in a directory for changes.
View PollingDemo.py
####
# Monitor new files in a directory for changes.
####
import os, time
# basic ideas from here:
# http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html#poll_with_listdir
dir = "."