Skip to content

Instantly share code, notes, and snippets.

View michaelglass's full-sized avatar
🐡
I HAVE A LOT OF MARSHMALLOWS IN MY MOUTH

Michael Glass michaelglass

🐡
I HAVE A LOT OF MARSHMALLOWS IN MY MOUTH
View GitHub Profile
@michaelglass
michaelglass / NestedLoop.java
Last active August 29, 2015 14:06
nested loops
public class NestedForLoop {
public static void main(String[] args) {
int numRows = 4;
int numColumns = 7;
int[] columnSums = new int[numColumns];
for (int row = 0; row < numRows; row++) {
int rowSum = 0;
for (int column=0; column < numColumns; column++) {
int value = row * column;
System.out.print(value + "\t");
@michaelglass
michaelglass / keybase.md
Last active August 29, 2015 13:59
keybase.md

Keybase proof

I hereby claim:

  • I am michaelglass on github.
  • I am glass (https://keybase.io/glass) on keybase.
  • I have a public key whose fingerprint is 49AF 48CA BE8F AA22 8753 E158 8D8A C6D3 0FBD 81CD

To claim this, I am signing this object:

@michaelglass
michaelglass / Guardfile
Created February 13, 2014 22:20
guardfile modifications to play nice with zeus on vagrant
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
if Dir.pwd == '/vagrant'
Guard::UI.info 'detected vagrant, enabling force polling'
Guard.options[:force_polling] = true
Guard.listener.options[:force_polling] = true
end
guard 'rspec', cmd: 'zeus rspec', all_on_start: false, all_after_pass: false do
#...
@michaelglass
michaelglass / alerts_and_confirms.rb
Last active September 24, 2019 10:15
test alerts & confirms in poltergeist & capybara webkit
module AlertConfirmer
class << self
def reject_confirm_from &block
handle_js_modal 'confirm', false, &block
end
def accept_confirm_from &block
handle_js_modal 'confirm', true, &block
end
@michaelglass
michaelglass / deadlock_retryer.rb
Created December 12, 2013 16:13
Delayed Job Deadlock Retryer!
# Deadlock Retryer
# ================
#
# when you decorate a class with `retry_deadlocks_from :such_a_locker, :so_many_locks, :lock_it_to_me`
# the deadlocks will be retried using a small random delay. THIS MEANS THAT THEY CAN NO LONGER BE TREATED SYNCHRONOUSLY
module DeadlockRetryer
def retry_deadlocks_from(*method_names)
method_names -= retry_deadlocks.to_a
retry_deadlocks.merge method_names
@michaelglass
michaelglass / indefinite_article.rb
Created December 11, 2013 06:26
A vs An ported to ruby from: http://home.nerbonne.org/A-vs-An/ ported by my coworker, @jleven
# encoding: UTF-8
# by Eamon Nerbonne (from http://home.nerbonne.org/A-vs-An), Apache 2.0 license
class IndefiniteArticle
# Usage example: IndefiniteArticle.for("example ")
# example returns: "an"
# Note that the terminal space indicates this is a complete word - this is sometimes significant, particularly for acronyms!
DICT = "]08[09[0-11[0-4[0-4 ]0-6-[0-8[11[110]111]112]113]114]115]116]117]118]119]11.4]18[180]1800[1801[1802[1803[1804[1805[1806[1807[1808[1809[181-]181 ]182-]182 ]183-]183 ]184-]184 ]185-]185 ]186-]186 ]187-]187 ]188-]188 ]189-]189 ]8[800x]890]8,1]8,2]–i[#i[$11 [$11.[$18 [$18,[$18.[$8[&a[&o[*a[*e[*i[.av[.mp[.og[/a[/e[/h[/i[/l[/s/[@[`a[£8[∞[a[a ]abou]about-[agai]al-I]algu]alth]amon]an ]and]and\"[anda[ande[andr[anot]anyw]apart ]appears]apre]are ]are:]artí]A[A$]AAA]Akiz]Amar\"]Andaluc]Armat]Asturias]Athl]Athleti[Athlo[AU$]AUD]AUSC]Á[á[à[Ä[ā[Å[æ[Æ[Æn]Bhai[Bhá[Buddhism[contains[Chais[County,[das [dem [der [describes[Dinas[Diver-[Dún]e[e.g]each ]either ]either.]el-]ella]empez]enoug]eu]eup [e
import sublime_plugin
import os
class RemoteTouch(sublime_plugin.EventListener):
def on_post_save(self, view):
file_name = view.file_name()
needle = "PATH_FOR_YOUR_APP" # change this
if needle in file_name:
project_root = view.window().folders()[0]
relative_path = file_name.replace(project_root + '/', "")
@michaelglass
michaelglass / deadlock_retryer.rb
Last active December 26, 2015 14:08
DelayedJob DeadlockRetryer
# Deadlock Retryer
# ================
#
# when you decorate a class with retry_deadlocks_from :such_a_locker, :so_many_locks, :lock_it_to_me
# the deadlocks will be retried using a small random delay. THIS MEANS THAT THEY CAN NO LONGER BE TREATED SYNCHRONOUSLY
module DeadlockRetryer
def retry_deadlocks_from(*method_names)
method_names -= retry_deadlocks.to_a
retry_deadlocks.merge method_names
@michaelglass
michaelglass / dj_throughput.rb
Created September 18, 2013 21:34
ugly, brutish DJ throughput task
task :dj_throughput, roles: :delayed_job do
last_reported = Time.now
completed = {}
run "tail -f #{shared_path}/log/delayed_job.log" do |channel, stream, data|
host = channel[:host]
trap("INT") { puts 'Interupted'; exit 0; }
if data =~ /completed after/
completed[host] ||= 0
completed[host] += 1
end