Skip to content

Instantly share code, notes, and snippets.

View somenugget's full-sized avatar
🐙
Doing stuff

Dmitriy Shcherbakan somenugget

🐙
Doing stuff
View GitHub Profile
@somenugget
somenugget / run-app-in-iterm.scpt
Last active January 22, 2022 23:46
Run App In iTerm
on run {input, parameters}
tell application "iTerm"
if not (exists first window) then
create window with default profile
end if
tell current window
-- leave only one tab opened
repeat (count of tabs) - 1 times
tell current tab
module Concerns
module BrowserCheck
extend ActiveSupport::Concern
NOT_SUPPORTED_VERSIONS = {
ie: 11,
edge: 19,
ios: 12,
android: 6
}.freeze
@somenugget
somenugget / session_switch.rb
Created March 9, 2021 18:40
Switch sessions in test
When(/^nothing$/) do
user1 = FactoryBot.create(:account_user)
user2 = FactoryBot.create(:account_user)
user1_session = User.serialize_into_session(user1)
user2_session = User.serialize_into_session(user2)
inject_session 'warden.user.user.key' => user1_session
visit '/'
@somenugget
somenugget / cuprite_setup.rb
Created February 27, 2021 20:21
cuprite_setup.rb
require 'capybara/cuprite'
# Then, we need to register our driver to be able to use it later
# with #driven_by method.
Capybara.register_driver(:cuprite) do |app|
Capybara::Cuprite::Driver.new(
app,
**{
window_size: [1200, 800],
# See additional options for Dockerized environment in the respective section of this article
@somenugget
somenugget / hook.rb
Created February 7, 2021 13:53
Run overcommit from sublime-merge
encoding_env_vars = 'LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8'
required_ruby_version = File.open('.ruby-version').read.chomp
env_ruby_version = ENV['RUBY_VERSION'].chomp
project_path = File.expand_path("#{File.dirname(__FILE__)}/../..")
if required_ruby_version != env_ruby_version
require 'pty'
PTY.spawn("#{encoding_env_vars} rvm in #{project_path} do #{__FILE__}") do |stdout, stdin, pid|
while !stdout.eof?
puts stdout.gets
@somenugget
somenugget / currying.rb
Last active January 18, 2019 15:30
Currying in Ruby
# https://www.morozov.is/2019/01/11/partial-application-in-ruby.html
fun = ->(tag, text) { "<#{tag}>#{text}</#{tag}>" }
curried_fun = fun.curry
bold_fun = curried_fun.('b')
p fun.('b', 'yo') # "<b>yo</b>"
p curried_fun.('b').('yo') # "<b>yo</b>"
p bold_fun.('yo') # "<b>yo</b>"
@somenugget
somenugget / out.rb
Created July 20, 2018 06:34
Replace last console output
require 'time'
loop do
time = Time.now.to_s + "\r"
print time
$stdout.flush
sleep 1
end