Skip to content

Instantly share code, notes, and snippets.

@ecashin
ecashin / Cargo.toml
Created December 25, 2023 02:58
Lagged Diffs in Polars
[package]
name = "try-polars-diff"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.76"
chrono = { version = "0.4.31", features = ["serde"] }
@ecashin
ecashin / main.rs
Created December 23, 2023 15:47
SVG Plots with Top-K and Lagged Diff
/*
datetime,usage,user
2023-12-12T01:23:45-0500,1000.0,a
2023-12-12T01:23:45-0500,1000.0,b
2023-12-12T01:23:45-0500,2000.0,c
2023-12-13T01:23:45-0500,1000.0,a
2023-12-13T01:23:45-0500,1000.0,b
2023-12-13T01:23:45-0500,2000.0,c
2023-12-14T01:30:30-0500,2000.0,a
2023-12-14T01:30:30-0500,0000.0,b
@ecashin
ecashin / conformal_prediction.py
Last active December 4, 2023 19:30
Conformal Prediction with Adaptive Prediction Sets
import math
from pathlib import Path
from typing import Optional
import click
import numpy as np
import torch
from torch import nn
@ecashin
ecashin / main.rs
Created November 15, 2023 00:43
Use of clap flatten with common args for two subcommands
use clap::{Args, Parser, Subcommand};
/// Doc comment
#[derive(Debug, Parser)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Args)]
@ecashin
ecashin / main.rs
Created November 4, 2023 23:12
tokio spmc
// This implementation allows a single producer to fan out
// messages to multiple consumers, so that only one consumer
// gets each value.
//
// The trick is to send a oneshot channel to the producer,
// and it responds over that.
use tokio::sync::{mpsc, oneshot};
#[tokio::main]
async fn main() {
@ecashin
ecashin / main.rs
Created September 22, 2022 00:34
function component with state that resets when its route is used
// I want component A to have a counter that increases on button click,
// and I want to be able to use routes to go to B and C, but
// I don't want the counter of A to forget its state when I visit B or C
// and then return to A.
//
// The index.html and Cargo.toml are in comments at the top
// of this yew source file.
/*
<!DOCTYPE html>
<html>
@ecashin
ecashin / .emacs
Created November 29, 2014 03:18
.emacs on Ubuntu 14.04
((lambda ()
(show-paren-mode 1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)))
(defun visiting-bro-sources ()
"Is this buffer visiting a bro source file?"
(interactive)
(if (locate-dominating-file default-directory "bro-path-dev.in")
@ecashin
ecashin / flippity.py
Last active August 29, 2015 14:09
Trivial Make-Running HTTP Server
#! /usr/bin/env python2.7
'''flippity.py
This is a stupid simple way to make sure that make-maintained
generated code gets served based on its dependencies.
In the example below, flippity.js is created by transpiling
flippity.ts, as specified by the makefile.
Usage::
@ecashin
ecashin / gist:09c1f6923ed77e17d5d4
Created November 5, 2014 14:19
.emacs on OS X
;;; Used with GNU Emacs 24.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2013-03-13 on bob.porkrind.org
;;; Miscellaneous notes:
;;;
;;; This is nice for debugging on type error:
;;; (message (prin1-to-string (type-of (car paths)))))
(setq line-move-visual nil)
(menu-bar-mode -1)
(tool-bar-mode -1)
@ecashin
ecashin / ptars.py
Created July 31, 2014 02:31
Process tar files in parallel
#! /usr/bin/env python2.7
from multiprocessing import Pool, Queue
import os
from sys import argv
import tarfile
BLACKLIST = ['.git']
EXTENSIONS = ['.tgz', '.tar', '.tar.gz', '.tar.bz2']
N_PARALLEL = 10