Skip to content

Instantly share code, notes, and snippets.

View Lockyy's full-sized avatar
🏳️‍🌈

Naomi Lockhart Lockyy

🏳️‍🌈
  • London, United Kingdom
  • 01:57 (UTC +01:00)
View GitHub Profile
@Lockyy
Lockyy / gist:e448ffb784f4e61f5199
Last active June 6, 2023 16:25
Image Preloading
ready = ->
preloadImages = (imageFilePathArray) ->
images = new Array
for filePath, index in imageFilePathArray
images[index] = new Image()
images[index].src = filePath
imageFilePathArray = [
@Lockyy
Lockyy / gist:1609879f0fe3ae682429
Last active June 6, 2023 16:24
Installing phantomjs on a docker ubuntu box
apt-get update
apt-get install -y build-essential chrpath libssl-dev libxft-dev
apt-get install -y libfreetype6 libfreetype6-dev
apt-get install -y libfontconfig1 libfontconfig1-dev
apt-get install -y wget
cd ~
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
mv $PHANTOM_JS.tar.bz2 /usr/local/share/
cd /usr/local/share/
@Lockyy
Lockyy / copchanged.sh
Last active June 6, 2023 16:23
Run Rubocop on files that've changed in Git
#!/bin/bash
rubocop $(git diff --name-only --diff-filter=d main...) --force-exclusion "$@"
@Lockyy
Lockyy / reekchanged.sh
Last active June 6, 2023 16:23
Run Reek on files that've changed in Git
#!/bin/bash
reek --force-exclusion "$@" $(git status --porcelain | sed s/^...//)
@Lockyy
Lockyy / to_age.rb
Last active June 6, 2023 16:23
Monkey patch onto Date/Time/DateTime objects to allow them to be converted to an age, accommodating for leap years
def to_age
today = Time.current
year_diff = today.year - year
today_is_past_birthday = today.month > month || (today.month == month && today.day >= day)
today_is_past_birthday ? year_diff : year_diff - 1
end
namespace :db do
desc 'Dumps the database to db/backups'
task :dump, [:backup_name] => :environment do |_task, args|
params = gather_required_data(args)
cmd = [
'pg_dump',
'-F c',
'-v',
'-h', params[:host],
@Lockyy
Lockyy / colorize_string_monkey_patch.rb
Last active June 6, 2023 16:21
Monkey patch to add `.red`/`.green`/`.yellow` to the String class to color strings on console output
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
@Lockyy
Lockyy / Auto-fail on focused specs
Last active June 6, 2023 16:21
Triggers a failure automatically when a focused spec is encountered
if ENV['CI']
config.before(:example, :focus) {
raise "You've added a focused spec to a commit, this'll prevent CI from running properly and you should remove this."
}
else
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
@Lockyy
Lockyy / gist:d35c82c489c165ee5fae50ca83c5b2ff
Last active June 6, 2023 16:20
Git blame addition or removal of string in file
git log -S <string> path/to/file
@Lockyy
Lockyy / files-diff.sh
Last active June 6, 2023 16:16
Outputs a list of all files changed between your current HEAD and develop
#!/bin/bash
git diff --name-only --diff-filter=d main...