Skip to content

Instantly share code, notes, and snippets.

Given the following CoffeeScript class:

class Foo

  constructor: ()->
    @bar()

  bar: ->
 $("body").on "click", (e)=>
@silasjmatson
silasjmatson / integration.rb
Last active August 29, 2015 14:06
Stripe Customer & Card
class API::Registrar
# Is this possible?
attr_reader :stripe_customer, :postgres_user, :stripe_card
def initialize(user_params, card_params)
@postgres_user = initialize_postgres_user(user_params)
@stripe_customer = initialize_stripe_customer(user_params)
@stripe_card = initialize_stripe_card(card_params)
end
@silasjmatson
silasjmatson / AppDelegate.swift
Last active January 2, 2018 21:42
Kill iTunes whenever it opens
//
// AppDelegate.swift
// iTunesKiller
//
// Created by Silas J. Matson on 12/18/14.
//
import Cocoa
@NSApplicationMain
@silasjmatson
silasjmatson / countdown.zsh
Created May 13, 2017 02:38
A simple zshell egg timer that runs a timer in a detached process and posts a Notification to Apple's Notification Center
# Usage: countdown <n> [second(s)|minute(s)|hour(s)] [message]
# Be sure to quote the 'message' argument
function countdown(){
if [ -z $1 ]; then
echo "Fuzzy Wuzzy wuz a bear, but now he's a sad \
bear because you didn't tell him how long to wait. 🐻"
return 1
fi
@silasjmatson
silasjmatson / database_query_streaming.rb
Last active June 14, 2017 18:37
Ruby Module to stream a SQL query to standard out, and yield each row to a block
module DatabaseQueryStreaming
def stream_query_rows(sql_query, options="WITH CSV HEADER")
conn = ActiveRecord::Base.connection.raw_connection
conn.copy_data "COPY (#{sql_query}) TO STDOUT #{options};" do
while row = conn.get_copy_data
yield row
end
end
end
class ApplicationRecord < ActiveRecord::Base
extend DatabaseQueryStreaming
self.abstract_class = true
end
class SalesReportsController < AdminController
include ActionController::Live
def export
respond_to do |format|
format.csv { stream_csv_report }
end
end
private
query.select("
AVG(sale.price) as average_price,
MAX(sale.price) as max_price,
MIN(sale.price) as min_price,
ROUND(AVG(EXTRACT(EPOCH FROM sale.completed_at) - EXTRACT(EPOCH FROM sale.created_at))) as average_sale_time
")

Keybase proof

I hereby claim:

  • I am silasjmatson on github.
  • I am silas (https://keybase.io/silas) on keybase.
  • I have a public key ASAArOJcqNT9RVatbJ0T-Hy9JLn5IHXUObsUyLapQdFwYQo

To claim this, I am signing this object:

@silasjmatson
silasjmatson / emoji-formatter.rb
Created August 3, 2017 05:51
Give your spec result format that millennial touch
module RSpec
module Core
module Formatters
class EmojiFormatter < BaseTextFormatter
def example_passed(_notification)
output.print '👌 '
end
def example_pending(_notification)