Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
definitely snacking

Fotios Lindiakos thefotios

💭
definitely snacking
View GitHub Profile
@thefotios
thefotios / visualize_query.rb
Created Jan 18, 2022
Format and visualize AR queries using https://explain.dalibo.com
View visualize_query.rb
class VisualizeQuery
# Takes an AR relation (query), runs explain, and then uploads it to
# https://explain.dalibo.com for better visualization
#
# The query is also nicely formatted before visualizing using https://github.com/darold/pgFormatter
# - This is run via `docker`
# - If the placeholders are sensitive (for instance emails in a 'where' clause)
# you can pass `anonymize: true` and they'll be replaced with random strings
method_object :query, [title: nil, anonymize: false]
@thefotios
thefotios / verified_double_extensions.rb
Last active Jul 31, 2020
Allow instance_double's to pass class equivalence checks (see https://github.com/rspec/rspec-mocks/issues/794)
View verified_double_extensions.rb
module VerifiedDoubleExtensions
CLASS_EQUIVALENCE_FUNCTIONS = %i[is_a? kind_of? instance_of?].freeze
def verified_double(klass, *args)
instance_double(klass, *args).tap do |dbl|
CLASS_EQUIVALENCE_FUNCTIONS.each do |fn|
allow(dbl).to receive(fn) do |*fn_args|
klass.allocate.send(fn, *fn_args)
end
end
View dcos.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"PublicSubnet": {
"Description": "Subnet ID for use by all public agent nodes",
"MaxLength": "18",
"ConstraintDescription": "must be a valid CIDR.",
"Default": "0.0.0.0/0",
"AllowedPattern": "^([0-9]+\\.){3}[0-9]+\\/[0-9]+$",
"MinLength": "9",
@thefotios
thefotios / day1.sh
Last active Dec 2, 2015
Advent of Code 2015
View day1.sh
# Part 1
awk 'BEGIN{ FS = ""} {for(i = 1; i <= NF; i++) if($i ~ /\(/){ floors++}else{floors--} } END { print floors}'
# Part 2
awk 'BEGIN{ FS = ""} {for(i = 1; i <= NF; i++){ if($i ~ /\(/){ floors++}else{floors--}; if(floors < 0){print i; break}}} END { print floors}'
@thefotios
thefotios / emojify.sh
Created Jul 21, 2015
Makes properly sized emoji for slack. Just point this at any URL. You'll need to have `convert` (part of ImageMagick)
View emojify.sh
#!/usr/bin/env bash
url=$1;
output=${2-output.png};
size=${3-128};
curl --silent -kL $url | convert - -resize ${size}x${size} $output;
View keybase.md

Keybase proof

I hereby claim:

  • I am thefotios on github.
  • I am thefotios (https://keybase.io/thefotios) on keybase.
  • I have a public key whose fingerprint is 2264 2751 B5AD E6D2 DC85 FA4A 91BD C79C 39F3 48FD

To claim this, I am signing this object: