Skip to content

Instantly share code, notes, and snippets.

@chausen
chausen / gist:afa162e24c470f553f57894e74206977
Created June 25, 2025 14:33
windows terminal sourcerer theme
{
"background": "#171717",
"black": "#000000",
"blue": "#6688AA",
"brightBlack": "#222222",
"brightBlue": "#90B0D1",
"brightCyan": "#87CEEB",
"brightGreen": "#B1D631",
"brightPurple": "#8181A6",
"brightRed": "#FF6A6A",
@chausen
chausen / compare_steps.py
Last active March 18, 2025 14:40
compare steps
import pandas as pd
df_day1 = pd.read_csv("day1_processed.csv")
df_day2 = pd.read_csv("day2_processed.csv")
# Each has columns like: ["relative_time_s", "CPU_usage", "FPS", ...].
# We assume day1["relative_time_s"]=0 at the start of Day 1's test, day2["relative_time_s"]=0 at start of Day 2's test, etc.
# Hypothetical times in seconds from the start of each day's recording
STEP_TIMES = {
@chausen
chausen / data_align.py
Created March 18, 2025 14:33
data alignment
# Goals
# Label each dataset with its day or config (e.g., “6 cores” vs. “10 cores”).
# Combine them into a single DataFrame (or keep them separate if you prefer).
# Align them by time so you can compare performance around similar test phases.
import pandas as pd
# Read each day, convert timestamp, label config
df_day1 = pd.read_csv("day1_raw.csv")
df_day1["timestamp"] = pd.to_datetime(df_day1["timestamp"])
@chausen
chausen / aggregate-frames.py
Created March 18, 2025 14:22
Handling raw per-frame data
import pandas as pd
# 1. Read raw PresentMon CSV
df = pd.read_csv("presentmon_raw.csv")
# 2. Convert "TimeInSeconds" to a time-based index (Step 1)
df["timestamp"] = pd.to_timedelta(df["TimeInSeconds"], unit="s")
df.set_index("timestamp", inplace=True)
# ------------------
@chausen
chausen / downsample.py
Created March 18, 2025 14:06
Downsample large data file
import pandas as pd
# 1. Read raw CSV
df = pd.read_csv("raw_data.csv")
# 2. Convert the timestamp column to datetime (adjust column name/format as necessary)
df["timestamp"] = pd.to_datetime(df["timestamp"])
# 3. Make the timestamp the index
df.set_index("timestamp", inplace=True)
@chausen
chausen / debug-stdin.py
Last active March 24, 2021 02:56
Using pdb to debug a python file when using input redirection
import sys
s = input()
# pdb uses stdin to be interactive; this switches stdin to be the teletype interface
# (terminal and keyboard) after getting the redirected input
sys.stdin = open("/dev/tty")
breakpoint()
def reverse_word_order(text):
newText = ""
position = 0
for t in text:
if t == " ":
newText = text[position:text.find(t, position)] + " " + newText
position = text.find(t, position) + 1
newText = text[position:] + " " + newText
public class Kata
{
public static string CreatePhoneNumber(int[] numbers)
{
return long.Parse(string.Concat(numbers)).ToString("(000) 000-0000");
}
}
@chausen
chausen / gist:e2c548b6b9e80fe943c2b1d1d2089d2e
Created March 11, 2018 17:27
Regex phone number formatting in C#
using System;
using System.Text.RegularExpressions;
public class Kata
{
public static string CreatePhoneNumber(int[] numbers) =>
new Regex("(...)(...)(....)").Replace(String.Concat(numbers), "($1) $2-$3");
}
@chausen
chausen / gist:cceb2397b8cd7d6c3b2ca27442148ee2
Created December 31, 2017 16:24
React Clock List with Add
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000