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
alert("i'm a popup")
@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 / yaml-expand.rb
Created October 28, 2020 22:31
Expand YAML anchor merges
require "yaml"
require "json"
puts YAML.dump(JSON.load(YAML.load_file(ARGV.first).to_json))
@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
sudo apt-get update
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
@emilong
emilong / cb_2018_us_county_20m.kml
Created December 28, 2019 01:22
cb_2018_us_county_20m.kml
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document><name>cb_2018_us_county_20m</name><visibility>1</visibility><LookAt><longitude>-102</longitude><latitude>38.5</latitude><heading>0</heading><tilt>10</tilt><range>7000000</range></LookAt><Style id="KMLStyler"><LineStyle><color>ffbc822f</color><width>2</width><gx:labelVisibility>0</gx:labelVisibility></LineStyle><PolyStyle><color>7fe1ca9e</color></PolyStyle><IconStyle><scale>0.8</scale><Icon></Icon></IconStyle><LabelStyle><scale>1.0</scale></LabelStyle></Style><Schema name="cb_2018_us_county_20m" id="kml_schema_ft_cb_2018_us_county_20m"><SimpleField type="xsd:string" name="STATEFP"><displayName>STATEFP</displayName></SimpleField><SimpleField type="xsd:string" name="COUNTYFP"><displayName>COUNTYFP</displayName></SimpleField><SimpleField type="xsd:string" name="COUNTYNS"><displayName>COUNTYNS</d
@emilong
emilong / cb_2018_us_county_20m.kml
Created December 28, 2019 00:57
cb_2018_us_county_20m.kml
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by FME 2017.1.2.0 (Build 17722) -->
<kml xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.opengis.net/kml/2.2">
<Document><LookAt>
<longitude>-102</longitude>
<latitude>38.5</latitude>
<range>7000000</range>
<tilt>10</tilt>
<heading>0</heading>
</LookAt>
@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 / ruby_hashes.md
Last active August 16, 2019 17:07
Ruby hash surprises

Some possibly surprising things about Ruby hashes

Accessing values

Ruby hashes can have keys of any type, but Strings and Symbols are the most common.

For symbol keys there is a special syntax (similar to Javascript's object literal syntax).

{ "this is a string key" =&gt; 3 }