Skip to content

Instantly share code, notes, and snippets.

View glittershark's full-sized avatar
🏳️‍⚧️

Aspen Smith glittershark

🏳️‍⚧️
View GitHub Profile
@glittershark
glittershark / tsvector_agg.sql
Created August 20, 2013 19:42
Postgresql aggregate function for tsvectors
CREATE OR REPLACE FUNCTION concat_tsvectors(tsv1 tsvector, tsv2 tsvector)
RETURNS tsvector AS $$
BEGIN
RETURN coalesce(tsv1, to_tsvector('default', ''))
|| coalesce(tsv2, to_tsvector('default', ''));
END;
$$ LANGUAGE plpgsql;
CREATE AGGREGATE tsvector_agg (
BASETYPE = tsvector,
@glittershark
glittershark / terrible.py
Created November 1, 2013 00:53
Intentionally terrible script made for an interview. The subject is asked to fix the script up, and add the functionality for the user to specify a specific file extension to copy.
import os
for index_variable in range(len(os.listdir('.'))):
if os.listdir('.')[index_variable][os.listdir('.')[index_variable].find('.'):] == '.txt':
print "found text file"
import shutil
import sys
shutil.copyfile('./' + os.listdir('.')[index_variable], sys.argv[1] + '/' + os.listdir('.')[index_variable])
for i in range(len(sys.argv) - 2):
if sys.argv[i + 2] == '--and':
shutil.copyfile('.' + os.listdir('.')[index_variable], sys.argv[i + 3])
@glittershark
glittershark / gist:7267851
Created November 1, 2013 16:21
500 points to the one who can figure out what this regex does
6,14s/^\s*'\(.\{-}\)'\s*=> ['"]\(.*\)['"]\(,\{,1}\)/\2 AS \1\3
@glittershark
glittershark / mock_geocoder.rb
Last active April 12, 2019 09:04 — forked from paveltyk/mock_geocoder.rb
Mock geocoding in Rspec, using the new 'expect' syntax
# In spec_helper:
# RSpec.configure do |config|
# ...
# config.include(MockGeocoder)
# end
#
# In your tests:
# it 'mock geocoding' do
# # You may pass additional params to override defaults
# # (i.e. :coordinates => [10, 20])

Keybase proof

I hereby claim:

  • I am glittershark on github.
  • I am glittershark (https://keybase.io/glittershark) on keybase.
  • I have a public key whose fingerprint is 0F11 A989 879E 8BBB FDC1 E236 44EF 5B5E 861C 09A7

To claim this, I am signing this object:

@glittershark
glittershark / shrug.sh
Created August 27, 2015 15:52
Xdotool script to type the shrug emoji
#!/bin/bash
echo -en "¯\\_(\xe3\x83\x84)_/¯" | xsel
xdotool key Shift+Insert

This doesn't work

  module Mixin
    def def_a_method
      define_method(:foo) { puts 'mixin' }
    end
  end

  class Thing
@glittershark
glittershark / aws_ssh.sh
Created June 7, 2017 22:25
SSH to an AWS server by name
function instance_by_name() {
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=$1" \
| jq -r '.Reservations | map(.Instances) | flatten | map(.NetworkInterfaces) | flatten | map(.Association.PublicIp) | first'
}
SSH_KEY="/path/to/ssh/key"
alias staging='ssh -i $SSH_KEY ec2-user@$(instance_by_name staging)'
alias production='ssh -i $SSH_KEY ec2-user@$(instance_by_name production)'
{-# LANGUAGE DerivingStrategies, GeneralizedNewtypeDeriving, DeriveAnyClass, FunctionalDependencies, DeriveGeneric #-}
module Lib where
import Control.Lens
import Control.Monad.Writer
import Control.Monad.Except
import Data.Monoid
import GHC.Generics
benchmarking Binary Encoding/big data/Data.Binary
time 216.2 ms (183.5 ms .. 245.8 ms)
0.993 R² (0.978 R² .. 1.000 R²)
mean 162.9 ms (136.6 ms .. 184.9 ms)
std dev 26.37 ms (20.48 ms .. 30.39 ms)
variance introduced by outliers: 38% (moderately inflated)
benchmarking Binary Encoding/big data/Codec.Serialise
time 218.2 ms (186.3 ms .. 246.4 ms)
0.993 R² (0.979 R² .. 1.000 R²)