Skip to content

Instantly share code, notes, and snippets.

@shivshank
shivshank / fd_btree.rs
Created November 14, 2017 01:34
Fixed Depth Binary Tree
use std::fmt::Debug;
trait BtreeTrait: Debug {}
#[derive(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
shivshank / playground.rs
Created September 3, 2017 00:04 — forked from anonymous/playground.rs
Rust code shared from the playground
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 July 20, 2017 03:38
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
shivshank / RunPython.bat
Created July 30, 2016 19:23
A script for running python
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 July 19, 2016 02:25
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
shivshank / vox_to_obj_exporter.py
Last active June 14, 2024 21:59
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
shivshank / renderer.java
Created November 8, 2015 18:33
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
shivshank / physics.java
Last active November 1, 2015 18:48
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
shivshank / PollingDemo.py
Created October 10, 2015 17:25
Monitor new files in a directory for changes.
####
# 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 = "."