Skip to content

Instantly share code, notes, and snippets.

View pythonandchips's full-sized avatar

Colin Gemmell pythonandchips

View GitHub Profile
require "test/unit"
def chop(int, array_of_int)
end
# http://codekata.com/kata/kata02-karate-chop/
class ChopTest < Test::Unit::TestCase
def test_chop
assert_equal(-1, chop(3, []))
assert_equal(-1, chop(3, [1]))
@pythonandchips
pythonandchips / task.rb
Last active September 9, 2022 18:39
object
class Task
def due_date
@due_date = DueDate.new(self)
end
end
class DueDate
def initialize(task)
@task = task
end
@pythonandchips
pythonandchips / techradar.csv
Last active August 29, 2022 14:38
tech radar
name ring quadrant isNew description
Stimulus Adopt Langages and frameworks TRUE Stimulus is a JavaScript framework with modest ambitions. It doesn’t seek to take over your entire front-end—in fact, it’s not concerned with rendering HTML at all. Instead, it’s designed to augment your HTML with just enough behavior to make it shine
Test context for stimulus tests Assess Techniques TRUE Some stimulus tests can result in setup contain several lines of html that is required to be setup differently for each test. Using test context can reduce the duplication of code and produce easier to maintain tests
Github projects Trial Platforms TRUE Some teams have been using github projects as an alternative to trello for managing projects and tracking work. The tighter integration with issue and pull requests makes it easier to link work together within the team
React with Redux Hold Tool TRUE React and Redux has been in the app for some time however we now feel its apporach to dealing with front-end interactivity adds s
const config = { attributes: true, childList: true, subtree: true }
const callback = (mutationsList : any) => {
mutationsList.forEach((mutation : MutationRecord) => {
if (mutation.type === "childList") {
if (mutation.target.nodeName.toLowerCase() === "form") {
mutation.target.dataset.turbo = false
} else {
if (mutation.target.dataset.turbolinks) {
mutation.target.dataset.turbo = mutation.target.dataset.turbolinks
/* eslint import/first: off */
/* eslint import/extensions: off */
process.env.NODE_ENV = process.env.NODE_ENV || "development"
import environment from "./environment.mjs"
export default environment({
path: "packs",
})
@pythonandchips
pythonandchips / gist:41fff86256d7619639e74cf72bdf602b
Created April 27, 2021 16:09
Extract data to restore company
#!/usr/bin/env ruby
# == Synopsis
# This is a simple script to export a single FreeAgent company
# as a SQL script file to reload on an alternate server
#
# == Examples
# This command exports company with id=1 to the file 1.sql
# company-export 1
#
@pythonandchips
pythonandchips / gist:16983a909a72b55ec9c3fc561b1ba5d5
Created April 23, 2021 14:34
Find invoices with incorrect cis deduction
def invoices_with_incorrect_deductions
filename = "invoices_with_incorrect_deductions"
invoices = Invoice.where("discount_percent > 0 AND cached_cis_deduction > 0")
writer = Metrics::CsvFileWriter.new(filename)
progress_bar = ProgressBar.new(invoices.count)
writer.open_csv_for_write do |csv|
@pythonandchips
pythonandchips / backfill_bill_items.rb
Last active March 29, 2021 09:43
backfill bill items
def backfill_bill_items
bills = Bill.all
progress_bar = ProgressBar.new(bills.count)
# Keeping the batch size low to reduce the time we are locking the 100 records
# for update
bills.select(
:id,
:contact_id,
@pythonandchips
pythonandchips / find_sent_invoice.rb
Created February 17, 2021 15:50
Fix sent invoices
def fix_sent_invoices(company_id, reference)
company = Company.find(company_id)
invoices = company.invoices.where(company_id: company_id, reference: reference)
return "Only #{invoices.length} found" if invoices.length < 2
puts "update #{invoices.length} invoices (#{invoices.map(&:id).join(",")}) for #{company.subdomain}?"
confirm = gets.chomp
return unless confirm == "y"
@pythonandchips
pythonandchips / dupliate_invoice_references.rb
Last active February 17, 2021 15:42
Find duplicate invoice references
require "perform_on_replica"
def find_duplicate_references
PerformOnReplica.perform_on_replica do
companies = Company.all
progress_bar = ProgressBar.new(companies.count)
companies.includes(:subscription).find_each do |company|
references = company.invoices.
group(:reference).