Skip to content

Instantly share code, notes, and snippets.

View digikata's full-sized avatar

Alan Chen digikata

View GitHub Profile
@digikata
digikata / simple-polars-calc-column-main.rs
Last active August 5, 2024 20:15
simple-polars-calculated-column
use polars::prelude::*;
fn main() {
let df = df!["foo" => ["A", "A", "B", "B", "C"], "val1" => [10, 20, 20, 45, 200], "val2" => [1, 2, 2, 4, 2], ].unwrap();
let ratio = (col("val1") / col("val2")).alias("ratio");
let df2 = df.lazy().with_column(ratio);
let out = df2.collect().unwrap();
println!("{out}");
@digikata
digikata / ANSI.md
Created March 12, 2023 23:55 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@digikata
digikata / mermaid?
Created August 13, 2022 15:00
Do mermaid text diagramss work in gists
flowchart LR
id
@digikata
digikata / grube
Last active January 30, 2018 19:42
script to select default kernel boot entry on many fedora/rhel/centos distros
#!/bin/bash
# https://fedoraproject.org/wiki/GRUB_2#Create_a_boot_menu_entry
# list the default, set a default then apply the setting int othe grub config
# reboot should cause the default kernel boot selection to boot on many
# recent fedora systems
# list grub entries
grlist() {
@digikata
digikata / work_queue.rs
Created August 30, 2017 18:10 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
// Here is an extremely simple version of work scheduling for multiple
// processors.
//
// The Problem:
// We have a lot of numbers that need to be math'ed. Doing this on one
// CPU core is slow. We have 4 CPU cores. We would thus like to use those
// cores to do math, because it will be a little less slow (ideally
// 4 times faster actually).
//
// The Solution:
@digikata
digikata / subl-unpack
Created April 24, 2017 16:34
My sublime text tarball install script
#!/usr/bin/env ruby
latest = nil
Dir.glob('sublime_text_3_build*.bz2').each do |f|
puts f
if latest.nil? || (f > latest)
latest = f
end
end
@digikata
digikata / print-override.rs
Created March 22, 2017 16:58
Overrides the println! error on write to stdout behavior. Useful for command line output handling to piped cmd sequences which might close the pipe early. e.g. cmd | head
// println!() calls print!() internally, so that's the only macro we have to
// override
macro_rules! print (
// The extra scope is necessary so we don't leak imports
($($arg:tt)*) => ({
// The `write!()` macro is written so it can use `std::io::Write`
// or `std::fmt::Write`, this import sets which to use
use std::io::{self, Write};
if let Err(e) = write!(io::stdout(), $($arg)*) {
// Optionally write the error to stderr
@digikata
digikata / userContent.css
Created March 9, 2016 17:05 — forked from graue/userContent.css
My userContent.css for Firefox (makes Hacker News comments and Humbug messages more readable)
@-moz-document url-prefix(https://news.ycombinator.com) {
.comment {
font-family: Alegreya, serif !important;
font-size: 15pt !important;
}
.comment code {
font-family: Inconsolata-g, fixed !important;
font-size: 10pt !important;
}
@digikata
digikata / watch-exec.sh
Created February 18, 2016 23:39
Watch a file, execute the given command
#!/bin/bash
# Author: Khaja Minhajuddin (A.Chen modified...)
# Wait for go files to be modified and then execute them
# Dependency: inotify-tools
# Install on ubuntu using: apt-get install inotify-tools
fpath=$1
cmd=$2
wdir=`pwd`
gspec="^$fpath\$"