Skip to content

Instantly share code, notes, and snippets.

View jinjagit's full-sized avatar
🏠
Working from home

Simon Tharby jinjagit

🏠
Working from home
View GitHub Profile
@jinjagit
jinjagit / update_home_pages_text_images.rake
Last active August 5, 2022 15:58
Task to update text_images (with dry_run as default)
# frozen_string_literal: true
namespace :fix_existing_tenants do
desc 'Update text_images if referenced in HomePage.bottom_info_section_multiloc'
# Usage:
# Dry run (no changes): rake fix_existing_tenants:update_home_page_text_images
# Execute (changes): rake fix_existing_tenants:update_home_page_text_images['execute']
task :update_home_page_text_images, [:execute] => [:environment] do |_t, args|
args.with_defaults(execute: false)
@jinjagit
jinjagit / strip_single_quotes.rb
Last active December 15, 2021 14:04
Useful template for file sanitization needs
# Strips single quotes from a file, line by line.
# Useful template for other sanitization needs.
lines =[]
File.readlines('some_file.csv').each do |line|
lines << line
end
File.open("some_file.csv", "w") { |f|
# Print summary of test failures and write to file.
# Intended to work with log files generated by log_rand_specs.zsh
# https://gist.github.com/jinjagit/1607b817df5dbaa5d443ea1a9a60938c
errors = {}
read_failures = false
n = 0
def record_errors(line, errors)
unless line.include?("Failed examples:") || line.include?("Randomized with seed") || line.chomp.empty?
#!/bin/zsh
# Zsh script to run rspec full test suite repeatedly (and in random orders).
# For overnight testing. Just 'Ctrl-C' repeatedly to terminate.
# Logs each full run to a separate log file.
# Interpolating date-time in filename avoids overwriting file with same name.
# Note: Make sure your computer will not sleep / hibernate in middle of process.
repeat 100 {
# Sleep gives time to Ctrl-C repeatedly before new file is created.
@jinjagit
jinjagit / api_curl.sh
Last active July 12, 2020 19:07
bash file to test the curl command examples on https://liquidvoting.io/ (Linux friendly)
#!/bin/bash
tput init
echo Testing locally, on http://localhost:4000 ...
echo
response1=$(curl -X POST http://localhost:4000 -H "Content-Type: application/json" -H "Org-UUID: b7a9cae5-6e3a-48b1-8730-8b5c8d6c9b5a" -d '{ "query": "mutation { createDelegation(proposalUrl: \"https://github.com/user/repo/pulls/15\", delegatorEmail: \"bob@example.com\", delegateEmail: \"alice@example.com\") { delegator { email } delegate { email } proposalUrl }}" }')
pass1=$(echo "$response1" | grep -o '{"data":{"createDelegation":{"delegate":{"email":"alice@example.com"},"delegator":{"email":"bob@example.com"},"proposalUrl":"https://github.com/user/repo/pulls/15"}}}')
fail1=$(echo "$response1" | grep -o '"message":"Could not create delegation"')
@jinjagit
jinjagit / auth.iex.exs
Last active July 3, 2020 16:16
adds aliases to iex shell for liquidvoting AUTH
# adds aliases and imports a / some module(s) to iex shell for liquidvoiting AUTH
# rename to .iex.exs and place in AUTH project root
# for dev environment, not production - add to / don't remove from your local gitignore
# <alias ... as> used to avoid referencing other module with name equivalent to alias
import Ecto.Query
alias LiquidVotingAuth.Application, as: App
alias LiquidVotingAuth.{
Organizations,
@jinjagit
jinjagit / api.iex.exs
Last active July 3, 2020 15:31
adds aliases to iex shell for liquidvoting API
# adds aliases and imports a / some module(s) to iex shell for liquidvoiting API
# rename to .iex.exs and place in API project root
# for dev environment, not production - add to / don't remove from your local gitignore
# <alias ... as> used to avoid referencing other module with name equivalent to alias
import Ecto.Query
alias LiquidVoting.Application, as: App
alias LiquidVoting.{
Delegations,