Skip to content

Instantly share code, notes, and snippets.


JR shivshank

  • Buffalo, NY
View GitHub Profile
shivshank /
Created Nov 14, 2017
Fixed Depth Binary Tree
use std::fmt::Debug;
trait BtreeTrait: Debug {}
struct Btree<T: Debug, Tail: BtreeTrait> {
val: T,
left: Option<Tail>,
right: Option<Tail>,
/// 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 /
Created Sep 3, 2017 — forked from anonymous/
Rust code shared from the playground
fn main() {
use shape_args::Dot;
// 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 /
Last active Jul 20, 2017
Parses (a very specific subset) of syn::ConstExpr for use with procedural macros
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 / 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 /
Created Jul 19, 2016
Count the lines of various files, ignoring lines that start with //

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 /
Last active Dec 19, 2020
Exports from MagicaVoxel VOX to OBJ. Can preserve all edges for easy editing in a program like Blender.
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 /
Created Nov 8, 2015
A simple 2D Java Renderer (incomplete example implemenation)
/* 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 /
Last active Nov 1, 2015
A (very) simple 2d Java Phyics Simulator
/* 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 /
Created Oct 10, 2015
Monitor new files in a directory for changes.
# Monitor new files in a directory for changes.
import os, time
# basic ideas from here:
dir = "."