Skip to content

Instantly share code, notes, and snippets.

@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
@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");
}
public class Kata
{
public static string CreatePhoneNumber(int[] numbers)
{
return long.Parse(string.Concat(numbers)).ToString("(000) 000-0000");
}
}
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
@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()
@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 / 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 / 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 / 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 / info.md
Created March 18, 2025 14:44
ESXi TOP columns

Identifying Which ESXi TOP Columns Matter

ESXi “esxtop” data can be huge, especially if you capture all columns. Not all metrics are equally important. Typically, for diagnosing performance in a VM environment, you want to focus on:

  • CPU Usage (e.g., %USED, %RDY, %CSTP / co-stop for SMP VMs, etc.)

    • %RDY (ready time) is a key metric to see if the VM is waiting for CPU.
    • %CSTP (co-stop) indicates scheduling delays for multi-vCPU VMs.
  • Memory Usage (e.g., MEMCTL, MEM_ACTIVE, MEM_CONSUMED, MEM_OVERHEAD)

  • If memory is overcommitted, ballooning or swapping might occur.