Skip to content

Instantly share code, notes, and snippets.

Avatar

Dustin Knopoff dustinknopoff

View GitHub Profile
View query_system.rs
use core::hash::Hash;
use std::sync::Arc;
use core::any::Any;
use core::any::TypeId;
use std::collections::HashMap;
use async_trait::async_trait; // 0.1.36
use tokio; // 0.2.21
use tokio::sync::RwLock;
// Our trait. The async part is not necessary, I just wanted to see how it behaves :)
View Hanoi.rs
fn main() {
let n = 8;
let mut blank = Vec::with_capacity(8);
hanoi(n, &mut (0..8).collect(), &mut blank.clone(), &mut blank);
}
//if n > 0
// Hanoi(n − 1, src, tmp, dst) 〈〈Recurse!〉〉
// move disk n from src to dst
// Hanoi(n − 1, tmp, dst, src) 〈〈Recurse!〉〉
@dustinknopoff
dustinknopoff / markdown_highlight.rs
Created May 3, 2020
A bare minimum pulldown_cmark highlighting using syntect based off of conversation in: https://github.com/raphlinus/pulldown-cmark/issues/167
View markdown_highlight.rs
use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;
use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, Options, Parser, Tag};
fn main() {
// Setup for pulldown_cmark to read (only) from stdin
let opts = Options::all();
let input = String::from(
View http_parse_fold.rs
use std::convert::TryFrom;
#[derive(Debug, Copy, Clone)]
enum HttpMethod {
GET,
POST,
PUT
}
impl TryFrom<String> for HttpMethod {
@dustinknopoff
dustinknopoff / def.yml
Created Jun 26, 2019
tmuxinator setup
View def.yml
# /Users/dknopoff/.config/tmuxinator/portal.yml
name: def
root: ~/Documents
# Optional tmux socket
# socket_name: foo
# Note that the pre and post options have been deprecated and will be replaced by
# project hooks.
@dustinknopoff
dustinknopoff / list-color.go
Created Jun 26, 2019
Ideal go-jira template for use in tmux setup
View list-color.go
{{$w := sub termWidth 200 -}}
{{ range .issues }}{{color "green+bh"}}{{.fields.issuetype.name | printf "%-12s" }}{{color "reset"}} {{color "yellow+bh"}}{{ .key | append ":" | printf "%-12s"}}{{color "reset"}} {{ .fields.summary | abbrev (sub $w 2) | printf (printf "%%-%ds" (sub $w 18)) }} {{color "blue+bh"}}{{if .fields.assignee }}{{.fields.assignee.name | printf "%12s" }}{{else}}<unassigned>{{end}}{{color "reset"}}
{{ end }}
@dustinknopoff
dustinknopoff / fibo.rs
Last active Jun 25, 2019
some fibonacci sequence fns using fold
View fibo.rs
fn main() {
fn fibo_fancy(val: i32) -> i32 {
if val == 0 {
return 0
}
(1..=val)
.fold((None, None), |acc, curr| {
let (m1, m2) = acc;
if curr <= 2 {
match (m1, m2) {
@dustinknopoff
dustinknopoff / fp_sort.rs
Last active Jun 18, 2019
Is the string sorted?
View fp_sort.rs
fn is_sorted(input: &str) -> bool {
let input_iter: Vec<_> = input.chars().collect();
let initial = input_iter[0];
input
.chars()
.fold(Some(initial), |acc, current| {
if acc != None {
if Some(current) >= acc {
return Some(current)
} else {
@dustinknopoff
dustinknopoff / is_reflexive.rs
Last active Jun 16, 2019
Is a Tree reflexive?
View is_reflexive.rs
type OptionBranch = Option<Box<Tree>>;
#[derive(Debug)]
struct Tree {
data: i32,
branches: (OptionBranch, OptionBranch)
}
impl Tree {
fn new(data: i32) -> Self {
View Brewfile
tap "filosottile/musl-cross"
tap "heroku/brew"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/core"
tap "neovim/neovim"
tap "redox-os/gcc_cross_compilers"
tap "sbdchd/skim"
tap "sergiobenitez/osxct"
You can’t perform that action at this time.