Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
@ddrscott
ddrscott / horz_reader.js
Last active August 29, 2015 13:59
Finds the div with the most p tags, then adds CSS Columns to it. I use http://mrcoles.com/bookmarklet/ to convert it to a bookmarklet.
function callback() {
(function ($) {
var h = $(window).height() + 'px',
w = '25em',
g = '2em',
r = '1px solid #eee',
most = 0,
content = $('body');
if ($('#content').length == 1) {
content = $('#content');
@ddrscott
ddrscott / background.js
Created May 21, 2014 18:23
Color background of all elements on a page via bookmarklet
// @see http://www.quora.com/Web-Development/What-are-the-most-interesting-HTML-JS-DOM-CSS-hacks-that-most-web-developers-dont-know-about
// @see http://qr.ae/Khvbr
var s=document.createElement('style');
s.textContent = "<style> * { background-color: rgba(255,0,0,.2) !important} * * { background-color: rgba(0,255,0,.2) !important} * * * { background-color: rgba(0,0,255,.2) !important} * * * * { background-color: rgba(255,0,255,.2) !important} * * * * * { background-color: rgba(0,255,255,.2) !important} * * * * * * { background-color: rgba(255,255,0,.2) !important}</style>";
document.getElementsByTagName('head')[0].appendChild(s);
background: linear-gradient(38deg, #20bc94, #757eba, #804598);
background-size: 600% 600%;
-webkit-animation: gradient-rotate 29s ease infinite;
-moz-animation: gradient-rotate 29s ease infinite;
-o-animation: gradient-rotate 29s ease infinite;
animation: gradient-rotate 29s ease infinite;
@-webkit-keyframes gradient-rotate {
0%{background-position:0% 51%}
50%{background-position:100% 50%}
100%{background-position:0% 51%}
@ddrscott
ddrscott / log_pipe.rb
Last active March 21, 2016 11:54
Simple script to handle multi-line logs
#!/usr/bin/env ruby
# # Simple script to handle multi-line logs.
# Adjust the global vars as needed.
#
# # Usage
#
# > chmod +x log_pipe.rb
# > tail -f log/development.log | ./log_pipe.rb
#
@ddrscott
ddrscott / .screenrc
Created December 1, 2016 20:09
screenrc with pretty colors
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
@ddrscott
ddrscott / sqlpp
Last active February 2, 2017 10:30
SQL pretty print using ruby and python
#!/usr/bin/env ruby
require 'coderay'
require 'open3'
# # Dependencies
# `coderay` is a ruby gem.
# Install it with:
# ```
# $ gem install coderay
# ```
@ddrscott
ddrscott / pry_psql.rb
Last active August 19, 2021 19:17
Pry command to execute SQL as text or Rails scopes
# Load this file in your `.pryrc`
#
# load 'path/to/pry_sql.rb'
#
# See how to use this by running: `psql --help`
# Originally created for Rails 3.
# Updated to Rails 6
module Rails
class DBConsole
APP_PATH = Rails.root.join('config', 'application')
@ddrscott
ddrscott / uptime_by_hour_lateral.sql
Last active February 27, 2018 16:15
Uptime by hour using lateral joins
SELECT
cal_date,
max(CASE WHEN hour = 0 THEN up_pct END) AS hour_0,
max(CASE WHEN hour = 1 THEN up_pct END) AS hour_1,
max(CASE WHEN hour = 2 THEN up_pct END) AS hour_2,
max(CASE WHEN hour = 3 THEN up_pct END) AS hour_3,
max(CASE WHEN hour = 4 THEN up_pct END) AS hour_4,
max(CASE WHEN hour = 5 THEN up_pct END) AS hour_5,
max(CASE WHEN hour = 6 THEN up_pct END) AS hour_6,
max(CASE WHEN hour = 7 THEN up_pct END) AS hour_7,
@ddrscott
ddrscott / uptime_by_hour_subqueries.sql
Created March 7, 2017 15:40
Uptime by hour using sub queries
SELECT
cal_date,
max(CASE WHEN hour = 0 THEN up_pct END) AS hour_0,
max(CASE WHEN hour = 1 THEN up_pct END) AS hour_1,
max(CASE WHEN hour = 2 THEN up_pct END) AS hour_2,
max(CASE WHEN hour = 3 THEN up_pct END) AS hour_3,
max(CASE WHEN hour = 4 THEN up_pct END) AS hour_4,
max(CASE WHEN hour = 5 THEN up_pct END) AS hour_5,
max(CASE WHEN hour = 6 THEN up_pct END) AS hour_6,
max(CASE WHEN hour = 7 THEN up_pct END) AS hour_7,
@ddrscott
ddrscott / grade_school.rb
Last active February 9, 2018 22:10
Grade school using funky lambda
alias λ lambda
sadd = λ {|ns, a| [*ns, a].sort }
hsort = λ {|h| Hash[h.sort] }
hadd = λ {|h, n, g| h.merge(g => sadd.(h[g], n)) }
school = λ {|gs| School.new(gs) }
School = Struct.new(:gs) do
define_method :add, λ {|n, g| (school . (hsort . (hadd . (to_hash, n, g)))) }
define_method :to_hash, λ {| | gs || {} }