This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bigdecimal" | |
namespace :exchange_rates do | |
desc "Fetch exchange rates from https://github.com/ismartcoding/currency-api" | |
task sync_from_ismartcoding: :environment do | |
# Exchange rate data is simply stored as JSON files in a repository: | |
# https://raw.githubusercontent.com/ismartcoding/currency-api/main/{yyyy-mm-dd}/{24h hour}.json | |
FIRST_DATE = "2023-10-10" # First date that has completed data | |
DEFAULT_HOUR = "23" # Reference hour of the day to take exchange rates from | |
PRECISION = 6 # 6 decimal places |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark/ips" | |
classes = ["items-center", "justify-center", "px-4", "py-2", "text-sm", "font-medium", "border", "border-slate-300", "shadow-sm", "rounded-md", "focus:outline-none", "focus:ring-offset-2", "text-white", "bg-blue-600", "ring-blue-700", "hover:bg-blue-700", "focus:ring-offset-blue-50", "dark:border-slate-950", "dark:bg-blue-700", "dark:text-blue-50", "dark:ring-blue-950", "dark:hover:bg-blue-800", "pl-1", "pr-4", "dark:focus:ring-offset-blue-700"] | |
merger = TailwindMerge::Merger.new | |
Benchmark.ips do |x| | |
x.report("init new merger") { TailwindMerge::Merger.new.merge(classes.shuffle.join(" ")) } | |
x.report("reuse with cache") { merger.merge(classes.shuffle.join(" ")) } | |
x.compare! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "config/application" | |
Rails.application.load_tasks | |
# Overide the default Rake task extensions for assets:precompile from cssbundling-rails and jsbundling-rails. | |
# This is necessary because the default Rake task will try use yarn, but we want to use npm. | |
Rake::Task["css:build"].clear | |
Rake::Task["javascript:build"].clear | |
namespace :css do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.skewed-box__container { | |
position: relative; | |
/* Customise accordingly: */ | |
max-width: 10rem; | |
} | |
.skewed-box__text { | |
/* Customise accordingly: */ | |
color: white; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Metrics normalised by number of tweets over time periods of day | |
// `bucket` controls the hours over which data is binned, eg 4 = creates 4 hour windows | |
((bucket = 4) => { | |
const columns = {'Impressions': 3, 'Engagements': 4, 'Likes': 6, 'Profile clicks': 10, 'EPI': 5} | |
Object.entries(columns).forEach(([name, idx]) => { | |
const h = Array(Math.ceil(24 / bucket)).fill(0).map(() => [0, 0]); | |
[ | |
...document.querySelectorAll('tbody tr') | |
].map( | |
(e) => [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# copyright: Stephen Ierodiaconou 2020 | |
# Usage from console: | |
# require './no_autoload/migrators/change_acl' | |
# eg: Migrators::ChangeAcl.new.run(UserProfile, :profile_image) | |
module Migrators | |
class ChangeAcl | |
def run(model_klass, association_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
# Check where records are being created | |
# Inspired by https://thoughtbot.com/blog/debugging-why-your-specs-have-slowed-down | |
# This is best used by modifying Factory bot to return the `caller` call stack | |
# in factory_bot/factory_runner.rb , edit `instrumentation_payload` hash to include `caller: caller,` | |
record_counts = {} | |
config.before(:suite) do | |
ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |name, start, finish, id, payload| | |
strategy = payload[:strategy].to_s |