Skip to content

Instantly share code, notes, and snippets.

@zeisler
zeisler / rubocop-git-hook.rb
Last active April 27, 2021 20:28
rubocop git hook
#!/usr/bin/env ruby
require "fileutils"
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'tty-command'
end
def check!(project_root, git_root, force_exit = false, rubocop_format = 'fu')
@zeisler
zeisler / git-recent.rb
Last active April 5, 2021 22:18
git-recent
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'tty-prompt', '~> 0.18.1'
gem 'colorize', '~> 0.8.1'
gem 'time_ago_in_words', '~> 0.1'
gem 'git', '~> 1.5.0'
gem 'pry'
@zeisler
zeisler / migrate.rb
Created March 15, 2019 21:52
CLI for managing Rails Migrations
#!/usr/bin/env ruby
require "./config/environment"
require "active_record/migration"
require "tty-prompt"
migration = TTY::Prompt.new(interrupt: :exit)
migration_version = migration.select("Select Migration", filter: true) do |menu|
ActiveRecord::Base.connection.migration_context.migrations_status.reverse.each do |status, version, name|
menu.choice "#{status.center(8)} #{version.ljust(14)} #{name}", version
end
//
// AppDelegate.swift
// watchman_temp
//
// Created by Dustin Zeisler on 11/7/18.
// Copyright © 2018 Dustin Zeisler. All rights reserved.
//
import Cocoa
@zeisler
zeisler / call_object.rb
Last active February 2, 2018 00:11
Converts Object.new(<args>).call to Object.call(<args>)
require "reverse_parameters"
# Converts Object.new(<args>).call to Object.call(<args>)
# module must be extend after initialize method in order to transfer parameters
module CallObject
def create_callable
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def self.call(#{ReverseParameters.new(instance_method(:initialize)).parameters})
self.new(#{ReverseParameters.new(instance_method(:initialize)).arguments}).call
end
RUBY
@zeisler
zeisler / stack_overflow_debugger.rb
Created December 7, 2017 00:31 — forked from myronmarston/stack_overflow_debugger.rb
Stack overflow debugger (since Ruby doesn't provide the whole stack in this case)
max_stack_frames = 500
TooManyStackFrames = Class.new(StandardError)
TracePoint.new(:call) do |tp|
if caller.size >= max_stack_frames
raise TooManyStackFrames, "Stack has exceeded #{max_stack_frames} frames"
end
end.enable
@zeisler
zeisler / robbyrussell-with-travis.zsh-theme.bash
Last active January 6, 2017 00:59
Add Travis status to prompt, given travis command exists
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%}$(travis_status)$(git_prompt_info)'
function travis_status_dir {
GIT_ROOT=`git rev-parse --show-toplevel`
echo "${GIT_ROOT}/tmp/.travis"
}
function travis_status_file {
GIT_SHA=`git rev-parse HEAD`
@zeisler
zeisler / thread.rb
Created January 22, 2016 21:06
Pass attributes to child thread so that the current request id can be logged
require "thread"
class Thread
alias_method :_initialize, :initialize
def initialize(*args, &block)
inheritable_attributes = Thread.current.inheritable_attributes
_initialize(*args) do
Thread.current.inheritable_attributes = inheritable_attributes
block.call
class MyClass
def initalize(arg1: arg2:, **additional_args)
post_initalize(**additional_args)
end
def post_initalize(*)
end
end
class Sharer
def initalizer(stuff_name)
@stuff_name = stuff_name
end
def stuff
@stuff_name
end