Skip to content

Instantly share code, notes, and snippets.

View dominiceden's full-sized avatar
💭
🚀

Dominic Eden dominiceden

💭
🚀
  • Carebit
  • London, UK
View GitHub Profile
@dominiceden
dominiceden / test.jsx
Last active February 9, 2019 17:01
Testing Shopify Polaris form components with Enzyme and Jest
// I've spent a few hours working out how to simulate the selection of a select option in my React app using the Polaris. Polaris provides a
// <Select /> component to use that wraps the <select> DOM element, so simulating a change is a bit tricky and involves reading the Polaris
// source to work out what's going on. Here's how I got it working for me.
// Polaris wants an event object with currentTarget defined. Not sure why they use currentTarget instead of target...
mountedWrapper.find('select[name="location_id"]').prop('onChange')({
currentTarget: {
value: newLocationId,
},
});
@dominiceden
dominiceden / commit-msg.sh
Last active December 22, 2018 18:38
Automatically add branch name to every Git commit message
#!/bin/sh
#
# Automatically adds branch name to every commit message.
# e.g. [feature/some-feature] Commit message here
# Remove .sh extension when copying into your .git/hooks folder.
#
NAME=$(git branch | grep '*' | sed 's/* //')
echo "[$NAME]"' '$(cat "$1") > "$1"
@dominiceden
dominiceden / move_s3_files.rb
Last active January 14, 2018 14:21
RUBY: Move AWS S3 Paperclip files using a non-standard region (i.e. not us-east-1)
# I had issues with moving S3 files in a non-standard region, such as London
# (eu-west-2). The AWS docs don't seem to say that you cannot pass a simple
# string as the new_object destination - it must be a Hash that contains a
# Aws::S3::Client instance. This is so the region is set correctly - it's passed
# in the client instance. Otherwise, you get the error "The bucket you are
# attempting to access must be addressed using the specified endpoint".
# Tested and working using the Ruby AWS SDK v2.9.5 in January 2018.
client = Aws::S3::Client.new(region: 'eu-west-2')
resource = Aws::S3::Resource.new(client: client)
@dominiceden
dominiceden / reverse_lloyds_statement.rb
Created July 2, 2017 10:53
Reverse Lloyds Banking statement CSV
require 'csv'
in_csv = CSV.read('/Users/Dominic/Downloads/in.csv').reverse
CSV.open("/Users/Dominic/Downloads/out.csv", "wb") do |csv|
in_csv.each do |line|
csv << line
end
end

Keybase proof

I hereby claim:

  • I am dominiceden on github.
  • I am domeden (https://keybase.io/domeden) on keybase.
  • I have a public key ASA0XfiFjvsxD3PSUnzZICKWY2DvEtyQMeFz2t6_yC3zDgo

To claim this, I am signing this object:

@dominiceden
dominiceden / get_appointments_by_day_number_of_week.rb
Last active November 6, 2016 20:25
Get dates for a particular date range and a day of the week in PostgreSQL
# Monday is 1
# Tuesday is 2
# Wednesday is 3
# Thursday is 4
# Friday is 5
# Saturday is 6
# Sunday is 7
# Note - the Postgres isodow function as used below gives us Monday - Sunday as 0-7. The dow function does Sunday-Monday, 0-6.
require 'httparty'
redirects = [ # FIELD1 is the current URL; FIELD2 is the URL you want the user to be redirected to.
{
"FIELD1": "http:\/\/www.myshop.com\/products\/urban-camo-tracksuit",
"FIELD2": "http:\/\/www.myshop.com\/collections\/tracksuit\/products\/urban-camo-tracksuit-bottoms"
},
{
"FIELD1": "http:\/\/www.myshop.com\/products\/urban-camo-vest",
"FIELD2": "http:\/\/www.myshop.com\/collections\/mens-vests\/products\/kutula-urban-camo-vest"
@dominiceden
dominiceden / copy_files_with_delay.rb
Created November 28, 2015 17:54
This Ruby script will copy files from one directory to another with a small delay. This is useful for the Shopify Theme application for example, which will not upload files if they are copied all at once into a directory. By uploading them one by one with a delay, you can still upload them all and save time if you have lots of files.
require 'fileutils'
# Replace Dominic with your actual user name. Use 'pwd' command to find this if you're not sure.
source_dir = Dir["/Users/Dominic/Downloads/sourcedirectory/*.*"] # Get all files with any extension in the folder 'sourcedirectory'
source_dir.each do |item|
FileUtils.cp(item, '/Users/Dominic/Documents/targetdirectory/') # Copy the item in the loop to the folder 'targetdirectory'
sleep(5) # Wait 5 seconds before moving on to the next item in the loop.
end
@dominiceden
dominiceden / generate_alphanumeric_codes_ruby.rb
Created November 27, 2015 10:36
Generate random alphanumeric codes in Ruby and write them to a CSV file. This is useful for generating voucher codes etc.
# You can use this with irb.
require 'csv'
CSV.open("codes.csv", "wb") do |csv| # Open the empty csv file. Make sure you run irb in the directory where the empty codes.csv file is
(1..10000).each do |i| # Run 10,000 times
randAlphaNumeric = Array.new(8){[*"a".."z", *"0".."9"].sample}.join # Generate a random alphanumeric number that's 8 digits long
csv << ["prefix-" + randAlphaNumeric] # Generate a code that begins with prefix- (if required), add the alphanumeric code and write it to the CSV file
end
end