Skip to content

Instantly share code, notes, and snippets.

Mike Subelsky subelsky

Block or report user

Report or block subelsky

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
@subelsky
subelsky / .railsrc
Last active May 3, 2017
How to make activerecord log SQL to the console
View .railsrc
# makes Rails logs appear in the console, useful for seeing the actual SQL query generated from an AR find for example
# put this in ~/.railsrc
require 'logger'
Rails.logger = Logger.new STDOUT
View nifi_jruby_example.rb
# There's not much documentation about nifi's JRuby API but it closely follows
# what the python API looks like:
# see http://funnifi.blogspot.com/2016/02/executescript-processor-hello-world.html
flow_file = session.get()
updated_flow_file = session.putAttribute(flow_file,"my-attribute","my-value")
session.transfer(updated_flow_file,REL_SUCCESS)
@subelsky
subelsky / rspec_template.rb
Created Aug 30, 2016
RSpec Template explaining basic test setup
View rspec_template.rb
# There should usually be one and only one require statement at the top of a spec, explicitly loading
# the only class this test relates to. That file should include any additional dependencies needed
# by the class (activesupport, nokogiri, etc.)
require "widget"
# Let's pretend we are testing a class called Widget that has only one method, .call (and in fact,
# almost all of our classes should be so simple they just have one method).
#
# class Widget
# # If you allow dependencies to be injected into your class, it's much easier to test and
@subelsky
subelsky / simple_ruby_test.rb
Last active Aug 30, 2016
Really simple Ruby test example
View simple_ruby_test.rb
class Adder
def add(a,b)
a + b
end
end
if __FILE__ == $0
adder = Adder.new
result = adder.add(1,2)
@subelsky
subelsky / ultisnips_yard.snippets
Last active Aug 26, 2016
Vim UltiSnips snippet for adding Ruby YARD tags to a method
View ultisnips_yard.snippets
# We document all of our Ruby code with YARD tags; see http://www.rubydoc.info/gems/yard/file/docs/Tags.md
# This snippet helps add all of the common tags to a method that I use everyday.
# The format is used by the UltiSnips Vim plugin; see https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
snippet yd "YARD tags"
# ${1:Method description}
# @param ${2:obj} [${3:Object}] ${4:description}
# ${0} @yield
# @yieldparam obj [Object]
@subelsky
subelsky / threading_and_forking.rb
Last active Apr 25, 2016
Ruby Threading & Forking Demo
View threading_and_forking.rb
#!/usr/bin/env ruby
# STAQ threading & forking training 4/26/16
#
# Invoke like so:
#
# ruby forking_and_threading.rb
# ruby forking_and_threading.rb thread
# ruby forking_and_threading.rb naive # seems to work OK
# env RBENV_VERSION=jruby-9.0.4.0 ruby ./forking_and_threading.rb naive # why does this give different results?
#
View thread-testing.rb
# This is how I'd use threads in rspec to test whether a shared state primitive works as expected
#(pessimistic database lock,advisory database lock, mutex, etc.)
around do |example|
die = false
lock_taker = Thread.new do
code_that_takes a lock do
loop do
break if die
sleep 0.1 # not strictly necessary but slows CPU churn
View date_time_monkeypatch_example.rb
# no need to require anything
module DateTimeFormatFunctions
def quarter
((month - 1) / 3) + 1
end
def strftime(format=nil)
super(format.to_s.tap.gsub!('%Q',quarter.to_s)
end
@subelsky
subelsky / keybase.md
Created Oct 11, 2014
Keybase identity assertion
View keybase.md

Keybase proof

I hereby claim:

  • I am subelsky on github.
  • I am subelsky (https://keybase.io/subelsky) on keybase.
  • I have a public key whose fingerprint is 5DFB 121D 24D8 CA6C 0F2C B51A 3D25 9BC3 602E CC74

To claim this, I am signing this object:

@subelsky
subelsky / large_redshift_tables.sql
Created Apr 18, 2014
Quick SQL command to find large tables in redshift
View large_redshift_tables.sql
-- based on http://stackoverflow.com/questions/21767780/how-to-find-size-of-database-schema-table-in-redshift
SELECT name AS table_name, ROUND((COUNT(*) / 1024.0),2) as "Size in Gigabytes"
FROM stv_blocklist
INNER JOIN
(SELECT DISTINCT id, name FROM stv_tbl_perm) names
ON names.id = stv_blocklist.tbl
GROUP BY name
ORDER BY "Size in Gigabytes" DESC
You can’t perform that action at this time.