Skip to content

Instantly share code, notes, and snippets.

@rgarner
rgarner / extract.js
Created September 19, 2018 07:54
Pullng people out of a Twitter thread with jQuery
let people = {};
$('.ThreadedConversation--loneTweet .account-group').each(function(a, acc) {
let b = $(acc).find('.username b');
let name = b.text()
people[name] = { handle: '@' + name, name: $(acc).find('.fullname').text() };
}
);
console.log(JSON.stringify(people));
@rgarner
rgarner / encodings.md
Last active February 22, 2018 12:24
A conversation about encodings transcribed into a gist

Anyway, about encodings: the most useful thing I find to remember is that we can only exchange any information at all because we have a previous agreement about what things mean. This applies as much to this conversation and the language in which we are having it as it does to encodings, it’s just that encodings are rather more precise agreements.

So.

If I send you something, it’s just a stream of bytes. If I POST something to your form, it’s just a stream of

@rgarner
rgarner / csharp7-switch.cs
Created August 26, 2016 21:29 — forked from mythz/csharp7-switch.cs
Proposed pattern matching in C#
// From: https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/
switch(shape)
{
case Circle c:
WriteLine($"circle with radius {c.Radius}");
break;
case Rectangle s when (s.Length == s.Height):
WriteLine($"{s.Length} x {s.Height} square");
break;
@rgarner
rgarner / hash_deep_diff.rb
Created July 1, 2016 09:57 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@rgarner
rgarner / eg.sh
Created August 4, 2015 14:07
New symbol behaviour in Ruby 2.2
➜ ~ rbenv shell 2.1.5
➜ ~ ruby -e '{ "hello": "world" }'
-e:1: syntax error, unexpected ':', expecting =>
{ "hello": "world" }
^
-e:1: syntax error, unexpected '}', expecting end-of-input
➜ ~ rbenv shell 2.2.0
➜ ~ ruby -e '{ "hello": "world" }'
➜ ~
@rgarner
rgarner / guess.rb
Last active August 29, 2015 14:24
Guess the encoding of a line-based resource on the web and print it to STDERR, followed by the contents
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'csv'
require 'charlock_holmes'
def read(url)
contents = File.read(open(url))
@rgarner
rgarner / 9.1-post-hmrc-with-43K-staging.output
Last active August 29, 2015 14:06
Query plans for update on hits import
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Update on hits (cost=111.65..925161.69 rows=13 width=130) (actual time=3022770.690..3022770.690 rows=0 loops=1)
-> Nested Loop (cost=111.65..925161.69 rows=13 width=130) (actual time=3022770.687..3022770.687 rows=0 loops=1)
Join Filter: ((hits.count IS DISTINCT FROM st.count) AND (st.path = (hits.path)::text))
-> Hash Join (cost=111.65..1885.26 rows=47071 width=60) (actual time=5.025..312.918 rows=47071 loops=1)
Hash Cond: ((st.hostname)::text = (hosts.hostname)::text)
-> Seq Scan on hits_staging st (cost=0.00..1008.71 rows=47071 width=65) (actual time=0.020..112.589 rows=47071 loops=1)
-> Hash (cost=79.62..79.62 rows=2562 width=35) (actual time=4.978..4.978 rows=2562 lo
@rgarner
rgarner / .psqlrc
Created July 31, 2014 09:27
Small .psqlrc
-- disable output temporarily
\set QUIET on
\timing
\x auto
\pset linestyle unicode
-- nicer rendering for null
\pset null 'NULL'
@rgarner
rgarner / leaderboard.sql
Last active August 29, 2015 14:04
Leaderboard
SELECT organisations.title,
COUNT(*) AS site_count,
SUM(site_mapping_counts.mapping_count) AS mappings_across_sites,
SUM(unresolved_mapping_counts.mapping_count) AS unresolved_mapping_count,
SUM(error_counts.error_count) AS error_count
FROM organisations
INNER JOIN sites
ON sites.`organisation_id` = organisations.id
LEFT JOIN (SELECT sites.id AS site_id,
COUNT(*) AS mapping_count
@rgarner
rgarner / monkey_futz.rb
Last active August 29, 2015 14:03
Futz random-ish input to import_mappings
#!/usr/bin/env ruby
if ARGV.length != 1
puts 'Usage: monkey-futz <host>'
exit 1
end
@host = ARGV.first
TYPES = [:archive,