Skip to content

Instantly share code, notes, and snippets.

@esaborit4code
esaborit4code / copywise.rb
Last active September 28, 2018 18:47
Ignore or rename files with duplicated name
#!/usr/bin/env ruby
require 'fileutils'
require 'byebug'
VERBOSE = false
DRY_RUN = false
class Conflict
SUFFIX_SEPARATOR = '-'
@esaborit4code
esaborit4code / remove_unedited.rb
Last active February 3, 2023 19:23
Sloppy script to remove unedited photos from iPhotos export
#!/usr/bin/ruby
require 'fileutils'
def basename(file)
File.basename(file, File.extname(file))
end
def all
Dir.glob('*').map
@esaborit4code
esaborit4code / running_apps.rb
Last active July 17, 2018 14:23
Heroku running apps
p `heroku apps -o barkibu`.split("\n").drop(1).map { |app| app.gsub(/\s\(.*\)/, '') }.each_with_object({}) { |app, collector| collector[app] = `heroku ps -a #{app}` }.keep_if { |k,v| !(v =~ /No dynos/) }.keys
@esaborit4code
esaborit4code / bm.rb
Created August 9, 2018 10:33
Cheap Benchmark
class BM
def self.bm(name)
@stats ||= {}
@stats[name] ||= { time: 0, times_called: 0, avg_time: 0 }
start_time = Time.zone.now
yield
@stats[name][:time] += (Time.zone.now - start_time)
@stats[name][:times_called] += 1
@stats[name][:avg_time] = @stats[name][:time].to_f / @stats[name][:times_called]
end
@esaborit4code
esaborit4code / rspec_mock_kwargs_spec.rb
Last active February 27, 2024 10:58
Demonstration of issue in rspec-mocks. All these tests should fail, but the misbehavior makes "with double with `have_received`" pass.
require 'spec_helper'
class Dummy
def go(a:)
end
end
RSpec.describe 'test' do
# All these tests should fail, but the misbehavior makes "with double with `have_received`" pass.
subject { Dummy.new.go(args) }
@esaborit4code
esaborit4code / credentials.rake
Last active August 20, 2024 16:28
Rake tasks to manage credentials
# frozen_string_literal: true
# These are custom Rake tasks to decrypt credentials in plain files and encrypt them back after changes (useful for editing in your local IDE if the development environment is Docker, where `rails credentials:edit` can't open your IDE):
# ```bash
# # Decrypt credentials
# bin/rails credentials:decrypt
# # Encrypt credentials
# bin/rails credentials:encrypt