Skip to content

Instantly share code, notes, and snippets.

@emilong
emilong / Undo.md
Created January 8, 2025 00:58 — forked from mlynch/Undo.md
Undo/Redo

Undo/Redo

Undo/Redo is one of those features of an application that you almost always need to have if you are building serious GUI tools for people to do work.

The best way to look at undo/redo is two stacks of operations the user has performed:

  • The Undo stack is the "history" of what they've done
  • The redo stack is the breadcrumbs back to the initial state before they started undoing
@emilong
emilong / process_graph.sh
Created August 26, 2021 18:49 — forked from bisrael8191/process_graph.sh
Log and graph peformance metrics on a single process
#!/bin/bash
# Log and graph peformance metrics on a single process
# Based on: http://brunogirin.blogspot.com.au/2010/09/memory-usage-graphs-with-ps-and-gnuplot.html
#
# Requires gnuplot to be installed and on your path.
#
# Run: ./process_graph [process name] [pid]
DEFAULT_PROCNAME="Xorg"
@emilong
emilong / psql_useful_stat_queries.sql
Created March 5, 2020 17:24 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@emilong
emilong / idle-shutdown.sh
Created September 30, 2019 17:00 — forked from JustinShenk/idle-shutdown.sh
Google Cloud Platform (GCP) instance idle shutdown
#!/bin/bash
# Add to instance metadata with `gcloud compute instances add-metadata \
# instance-name --metadata-from-file startup-script=idle-shutdown.sh` and reboot
# NOTE: requires `bc`, eg, sudo apt-get install bc
# Modified from https://stackoverflow.com/questions/30556920/how-can-i-automatically-kill-idle-gce-instances-based-on-cpu-usage
threshold=0.1
count=0
wait_minutes=60
while true
@emilong
emilong / postgres_queries_and_commands.sql
Last active June 15, 2018 16:46 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- index usage stats
SELECT
relname,
100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used,
n_live_tup rows_in_table
FROM
pg_stat_user_tables
WHERE
seq_scan + idx_scan > 0
ORDER BY