Skip to content

Instantly share code, notes, and snippets.

🍂

Sean Linsley seanlinsley

🍂
Block or report user

Report or block seanlinsley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@seanlinsley
seanlinsley / iterable_weak_set.js
Last active Mar 21, 2020
Iterable WeakSet in JavaScript
View iterable_weak_set.js
// spec: https://github.com/tc39/proposal-weakrefs
// the spec contains an [iterable WeakMap implementation](https://github.com/tc39/proposal-weakrefs#iterable-weakmaps)
// NOTE: this WeakSet implementation is incomplete, only does what I needed
// In Firefox Nightly, visit about:config and enable javascript.options.experimental.weakrefs
class IterableWeakSet extends Set {
add(el) {
super.add(new WeakRef(el))
}
forEach(fn) {
@seanlinsley
seanlinsley / chromedriver.rb
Created Mar 14, 2019
Ensures that chromedriver always matches the version of Chrome that's currently installed
View chromedriver.rb
# https://github.com/flavorjones/chromedriver-helper/issues/79
# http://chromedriver.storage.googleapis.com/index.html
require 'open-uri'
require 'shellwords'
executable = if RUBY_PLATFORM =~ /darwin/
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
else
'google-chrome'
View better_precompile.rb
# Sprockets no longer creates undigested assets, so we have to emulate the old behavior to keep vendored JS libraries happy.
# This automatically uses the newest asset in cases where the same file exists multiple times (like with Capistrano).
#
# https://github.com/rails/sprockets-rails/issues/49
#
# digested: 4-star-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg
# undigested: 4-star.jpg
assets_without_digest = -> do
digest = /(-{1}[a-z0-9]{64}*\.{1}){1}/
assets = Dir.glob File.join Rails.root, 'public/assets/**/*'
View example_usage.js.erb
Backbone.View.extend({
template: Handlebars.compile(
<%= embed('template.hbs').inspect %>
// some .hbs.erb files are also loaded
),
// ...
})
View gem_analytics.rb
# written for https://github.com/rails/rails/pull/30919
# 1. find all gems that depend on a particular gem
# 2. download them all
# 3. search through their source!
auth = 'Authorization:YOUR_API_KEY'
gems = JSON.parse(`curl -H '#{auth}' https://rubygems.org/api/v1/gems/activerecord/reverse_dependencies.json`); nil
gems.size
View gist:2aa653362b11094cab5562016b1138f1
,.---._
,,,, / `,
\\\\ / '\_ ;
|||| /\/``-.__\;'
::::/\/_
{{`-.__.-'(`(^^(^^^(^ 9 `.========='
{{{{{{ { ( ( ( ( (-----:=
{{.-'~~'-.(,(,,(,,,(__6_.'=========.
::::\/\
|||| \/\ ,-'/,
View psqlprompt.sh
# This asks the user if they want a read-only or read-write PSQL session. PSQL
# provides `\prompt`, but that doesn't provide a way to conditionally prompt
# based on whether it was being run interactively, or from bash-completion.
#
# Save this file to ~/.psqlprompt and add the below to ~/.psqlrc:
#
# \set read_only `bash ~/.psqlprompt`
# set default_transaction_read_only = :read_only;
#
function psql_prompt() {
View retry.rb
begin
# your code
rescue
tries ||= 0
(tries += 1) < 3 ? retry : raise
end
@seanlinsley
seanlinsley / chat_controller.rb
Last active Dec 21, 2015
Websockets with Postgres listen/notify and the Tubesock gem
View chat_controller.rb
require 'pg_notify'
class ChatController < ApplicationController
include Tubesock::Hijack
@@notifier = PGNotify.new 'chat'
def chat
hijack do |websocket|
websocket.onopen do
@@notifier.subscribe websocket do |payload|
View flamegraph.html
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<meta charset=utf-8 />
<title>Flame Graph of Page</title>
You can’t perform that action at this time.