Skip to content

Instantly share code, notes, and snippets.

View TyOverby's full-sized avatar
😸

Ty Overby TyOverby

😸
View GitHub Profile

Problem

Given a directed graph with weighted nodes, find the a set of cycles that don't share any nodes, maximizing the total sum of the node weights. Ties can be broken arbitrarily.

Example 1

All nodes have weight 1

@TyOverby
TyOverby / dyn.md
Last active September 11, 2017 19:56
(define with-dynamic-var (sym val f)
    (define rec (f) 
        (match (reset (cons 'dyn sym) f)
            ({#finished, value} value)
            ({#shifted, {#lookup, cont}} (rec (thunk (continue cont val))))
            ({#shifted, {#mut, value, cont}} (with-dynamic-var sym value (thunk (continue cont))))
    (rec f))

(define lookup (sym)
extern crate serde;
use serde::{Serialize, Deserialize};
struct PathInfo;
struct QueryInfo;
trait ApiFunction<I: Deserialize<'static>, R: Serialize> {
fn build(self) -> Box<Fn(PathInfo, QueryInfo, I) -> R>;
}
open System.Collections.Generic;
let memoize f =
let table = new Dictionary<_, _>()
fun k ->
if lock table (fun () -> table.ContainsKey(k))
then
lock table (fun () -> table.[k])
else
let res = f k
@TyOverby
TyOverby / colors.md
Created December 3, 2016 08:57
color problem

Context

There exists a Color space.

weight(Color) = real number between 0 and 1 

difference(Color, Color) = real number between 0 and 100
find . | grep "Cargo.toml$" | # Find all cargo.toml files \
sed 's#/[^/]*$##' | # Remove the filename leaving us with the directories containing cargo.toml files \
xargs -L1 printf "cd \"%s\"; cargo clean; cd -\n" | # Print "cd path/to/crate; cargo clean; cd -" \
bash # Execute

Abstract

Create a "as-a-library" implementation of Bash, offering live-inspection capabilities.

Capabilities

  • Run any batch script as normal
  • Ask for a semantic bound-tree of an arbitrary expression
  • Ask for a lint in a specific environment (detect undefined env-vars)
  • Debug shell script
@TyOverby
TyOverby / .bashrc
Last active February 28, 2016 04:56
export PATH="$PATH:$HOME/.cargo/bin"
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"
set_fg()
{
printf "\001\e[38;5;${1}m\002"
}
set_bg()
{
@TyOverby
TyOverby / gist:ebee310a07149131d712
Created May 19, 2015 22:03
raw C pre-processor
cpp -undef -o foo.txt -nostdinc -E -P
# Make it use C-a, similar to screen..
unbind C-b
unbind l
set -g prefix C-a
bind-key C-a last-window
# Reload key
bind r source-file ~/.tmux.conf
set -g default-terminal "screen-256color"