Skip to content

Instantly share code, notes, and snippets.

View jlgerber's full-sized avatar

jlgerber

View GitHub Profile
@jlgerber
jlgerber / configuretasks.md
Last active November 30, 2020 01:39
how to configure tasks in vscode

You can configure vscode like so

  1. create a .vscode directory at the root of your project
  2. create a tasks.json file
  3. populate it like so:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
@jlgerber
jlgerber / Makefile
Created May 31, 2019 12:00
simple makefile for rust projects
prog :=xnixperms
debug ?=
$(info debug is $(debug))
ifdef debug
release :=
target :=debug
extension :=debug
@jlgerber
jlgerber / function_composition.rs
Last active April 10, 2019 13:45
compose functions in rust
// from
// https://stackoverflow.com/questions/45786955/how-to-compose-functions-in-rust
// answered by Jan Nils Ferner
//
// composes functions. In the orig namespace
mod orig {
fn compose<A, B, C, G, F>(f: F, g: G) -> impl Fn(A) -> C
where
F: Fn(A) -> B,
@jlgerber
jlgerber / array_of_str.rs
Created July 31, 2018 13:13
static array of string literals - rust
const BROWSERS: &'static [&'static str] = &["firefox", "chrome"];
@jlgerber
jlgerber / rust_generictrait_eg.rs
Created July 14, 2018 14:23
multiple implementations of same generic trait and how to apply
pub enum Entity {
Foo,
Bar,
}
pub trait ExtractEntity<T> {
fn extract_entity(&self, out: Entity) -> Option<T>;
}
@jlgerber
jlgerber / partialeq_trait_take2.rs
Created May 6, 2018 14:41
implementing PartialEq for a trait object. Another approach
trait Schema {
fn eq(&self, other: &Schema) -> bool;
}
impl<'a> PartialEq<&'a Schema> for &'a Schema {
fn eq(&self, other: &&Schema) -> bool {
Schema::eq(*self, *other)
}
}
@jlgerber
jlgerber / rust_any_traitobj.rs
Created May 6, 2018 14:28
getting around inability to use PartialEq and PartialOrd with trait objects. from https://users.rust-lang.org/t/testing-equality-with-a-trait-object/5034/6
use std::any::Any;
trait Schema {
fn eq(&self, other: &Schema) -> bool;
fn as_any(&self) -> &Any;
}
impl<'a, 'b> PartialEq<Schema+'b> for Schema+'a {
fn eq(&self, other: &(Schema+'b)) -> bool {
Schema::eq(self, other)
@jlgerber
jlgerber / stack_and_recursion.rs
Created May 5, 2018 17:11
rust stack vs recursion
static STUFF: &'static [&'static str] = &[
"foo",
"bar",
"bla",
"crar",
"mala",
"court",
"dupla",
"fooobas",
"lalalala",
# from http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@jlgerber
jlgerber / FindMaya.cmake
Last active January 5, 2017 15:49
cmake - custom FindMaya.cmake plugin
# adapted from Chad Vernon's wonderful video series
# only tested on OSX so far
# to use, set the CMAKE_MODULE_PATH to point at this file.
# CACHE keyword allows us to pass in from the command line
if(NOT DEFINED MAYA_VERSION)
set(MAYA_VERSION 2017 CACHE STRING "Maya version")
endif()
set(MAYA_COMPILE_DEFINITIONS "REQUIRE_IOSTREAM;_BOOL")