Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile
@wojtha
wojtha / highline.rb
Created August 1, 2016 14:55
Ruby CLI menu prompts
require 'highline'
cli = HighLine.new
cli.say "Cannot pull because Git repository is dirty"
cli.choose do |menu|
menu.prompt = "WHAT TO DO?"
menu.choice(:reset) { sh 'git reset --hard' }
menu.choice(:stash) { sh 'git stash' }
menu.choice(:quit, "Exit program") { abort 'Quiting. Nothing to do.' }
menu.default = :quit
@wojtha
wojtha / spec_assets.rb
Created June 28, 2016 15:18
Experimental assets compilation before running test suite. However it does not give me any boost.
# See https://github.com/teampoltergeist/poltergeist/issues/677#issuecomment-222919584
# https://dzone.com/articles/precompiling-rails-assets
RSpec.configure do |config|
config.before :all do
ENV['PRECOMPILE_ASSETS'] ||= begin
case self.class.metadata[:type]
when :feature, :view
STDOUT.write "Precompiling assets..."
require 'rake'
@wojtha
wojtha / gist:d4d874c962ae5cc6d5c858a4aa081674
Created June 23, 2016 13:53 — forked from sgergely/gist:3793166
Midnight Commander Keyboard Shortcuts for Mac OSX
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@wojtha
wojtha / fail_fast_wisper_rectify.rb
Created June 10, 2016 08:33
FailFast with Wisper events and tweaked block evaluation durring the call - inspired by Rectify::Command.
require 'wisper'
module FailFastWisperRectify
def self.included(base)
base.include Wisper::Publisher
base.include Helpers
base.prepend Proxy
base.extend ClassMethods
end
@wojtha
wojtha / fail_fast_wisper.rb
Last active June 10, 2016 09:03
Fail fast with wisper events
require 'wisper'
module FailFastWisper
def self.included(base)
base.include Wisper::Publisher
base.include Helpers
base.prepend Proxy
end
@wojtha
wojtha / uniqness_validator.rb
Last active June 10, 2016 08:18
UniquenessValidator to be used outside the model (e.g. in form object)
# Class UniquenessValidator adds 'model' option to the options so it can be used
# outside the model.
#
# See http://stackoverflow.com/a/14671979/807647
#
# Example:
#
# class SignupForm
# include ActiveModel::Model
# attr_reader :email
@wojtha
wojtha / rich_return.rb
Last active June 9, 2016 13:25
RichReturn wraps call() method with rich return object and adds ability to fail fast with throw. Inspired by Hanami::Interactor
module RichReturn
def self.included(base)
base.extend Exposures
base.prepend Proxy
end
module Exposures
def exposes(*args)
@__exposures = args
attr_reader(*args)
@wojtha
wojtha / fail_fast.rb
Last active June 9, 2016 13:18
FailFast module proof of concept. Inspired by Hanami::Interactor
module FailFast
class Success
attr_reader :data, :error
def initialize(data)
@data = data
end
def success?
require "inflecto"
require "site_prism"
# Load all the page classes
Dir[SPEC_ROOT.join("pages/**/*.rb").to_s].each(&method(:require))
# Add a helper method for accessing each page class, with a name to match. A
# `_page` suffix is added for clarity, and to avoid name collisions, e.g.
#
# MyFriendsPage -> TestPageHelpers#my_friends_page
@wojtha
wojtha / namespaces_and_inheritance_problem.rb
Created May 29, 2016 21:44
Ilustration of ruby namespaces vs inheritance when reopening classes
class Base
end
class A < Base
end
class A
class Create
end
end