Skip to content

Instantly share code, notes, and snippets.

View clarkbw's full-sized avatar
🐯
Hiring Product Managers!

Bryan Clark clarkbw

🐯
Hiring Product Managers!
View GitHub Profile
@clarkbw
clarkbw / replace-index.sql
Last active April 12, 2022 22:59
quick postgres SQL for replacing an index
-- get existing index names and SQL definitions
SELECT indexname, indexdef
FROM pg_indexes
WHERE schemaname = 'public' AND tablename = 'table'
ORDER BY indexname;
-- create new tmp index (example)
CREATE INDEX tmp_name_of_the_index ON public.table USING btree (time ASC);
-- drop existing index
DROP INDEX name_of_the_index;
@clarkbw
clarkbw / all-up-with-vars.sql
Last active March 8, 2022 20:32
linear regression (trend line) analysis of time series data in postgres SQL (demo)
-- bring all examples together and clean up with some top level variables
WITH vars AS (
SELECT INTERVAL '1 day' AS bucket,
(now() - INTERVAL '3 months') as time_from,
(now() + INTERVAL '1 month') as time_to
)
-- generate timeline into the past and future
,
timeline AS (
@clarkbw
clarkbw / create_hypertable_migration.rb
Last active February 10, 2022 17:19
A rails migration for creating and reverting a hypertable
class ActionsHypertable < ActiveRecord::Migration[7.0]
def change
@table_name = 'actions'
@time_column = 'created_at'
reversible do |dir|
dir.up do
execute <<-SQL
SELECT create_hypertable('#{@table_name}', '#{@time_column}', if_not_exists => TRUE, migrate_data => TRUE);
SQL
end
SELECT s.schemaname,
s.relname AS tablename,
s.indexrelname AS indexname,
pg_size_pretty(pg_relation_size(s.indexrelid)) AS index_size
FROM pg_catalog.pg_stat_user_indexes s
JOIN pg_catalog.pg_index i ON s.indexrelid = i.indexrelid
WHERE s.idx_scan = 0 -- has never been scanned
AND 0 <>ALL (i.indkey) -- no index column is an expression
AND NOT i.indisunique -- is not a UNIQUE index
AND NOT EXISTS -- does not enforce a constraint
<script>
{
let a = "foo";
}
{
let b = 42; // set breakpoint here: debugger shows b == "foo"!
}
</script>
@clarkbw
clarkbw / redux-performance-mark.js
Last active February 8, 2024 05:03
A User Timing middleware for redux to create performance markers for dispatched actions
const timing = store => next => action => {
performance.mark(`${action.type}_start`);
let result = next(action);
performance.mark(`${action.type}_end`);
performance.measure(
`${action.type}`,
`${action.type}_start`,
`${action.type}_end`
);
return result;
@clarkbw
clarkbw / ios-debugger.md
Last active September 19, 2016 20:54
Instructions for the debugger.html to debug Safari running in the iOS simulator

Safari

These are the instructions for getting the debugger.html project to connect to and debug Safari on various platforms.

iOS Simulator (Mac only)

Requirements

  • Xcode
  • Download and install Xcode from Apple
@clarkbw
clarkbw / re-dash-csv.js
Last active December 21, 2016 05:56
re:dash snippet for getting the latest CSV data results from your query
// edit these values
const API_KEY_ID = "9352fd37f2f4ce923932c9c6328829a5be7093ea3d";
const QUERY_ID = 1002;
const YOUR_REDASH = "https://your.redash.io/api/queries/";
// leave this
const API_KEY = `?api_key=${API_KEY_ID}`;
const RESULT_URL = `${YOUR_REDASH}${QUERY_ID}/results.csv${API_KEY}`;
d3.csv(RESULT_URL, function(data) {
@clarkbw
clarkbw / addLineWidget.patch
Created August 26, 2016 21:14
Uses addLineWidget in the debugger.html CodeMirror editor
diff --git a/public/js/components/Editor.css b/public/js/components/Editor.css
index ff6160c..3986f92 100644
--- a/public/js/components/Editor.css
+++ b/public/js/components/Editor.css
@@ -52,6 +52,10 @@
z-index: 0;
}
+.new-breakpoint .CodeMirror-linewidget .helpful-message {
+ background-color: yellow;
@clarkbw
clarkbw / snippets.md
Last active December 1, 2017 18:58
Useful snippets for mozilla re:dash