Skip to content

Instantly share code, notes, and snippets.

View CharlieHawker's full-sized avatar

Charlie Hawker CharlieHawker

View GitHub Profile
@CharlieHawker
CharlieHawker / MacUserGuideToSavingImagesForWeb.md
Last active July 19, 2017 14:43
Mac user guide to saving images for web

Mac Users' Guide to Saving Images for Web

It's generally good practice to ensure images, particularly photography are 'saved for web' before uploading them to a website; some websites do this for you, but if they don't you could be opening yourself up to display and/or security issues with regards to the metadata the images may contain.

Display issues 👓

If you find your image colours are changing when the files are uploaded, it's probably because image has an embedded color profile.

@CharlieHawker
CharlieHawker / example_monetized_product.rb
Created June 13, 2017 11:27
create ransackers for monetized fields on an ActiveRecord object
class ExampleMonetizedProduct < ApplicationRecord
monetize :price
monetize :rrp
monetized_attributes.each do |attribute, field|
ransacker :"#{attribute}", formatter: proc { |v| v.to_f * 100 } do |object|
object.table[:"#{field}"]
end
end
@CharlieHawker
CharlieHawker / direct_assigment_matchers.rb
Last active June 8, 2017 11:11
RSpec matchers for direct assignment of attributes to an object
module DirectAssignmentMatchers
require 'rspec/expectations'
RSpec::Matchers.define :prevent_direct_assignment_of do |attribute|
match do |object|
!DirectAssignmentMatchers::public_assign(object, attribute)
end
end
RSpec::Matchers.define :allow_direct_assignment_of do |attribute|
@CharlieHawker
CharlieHawker / rails_basic_setup_template.rb
Last active May 9, 2017 16:14
A rails app starting point with ActiveAdmin
# Usage: rails new APP_PATH -m rails_basic_setup_template.rb --database postgresql -T
gem "activeadmin"
gem "devise", github: "plataformatec/devise"
gem "cancancan"
gem "draper"
gem "pundit"
gem "haml-rails"
gem "simple_form"
gem "sidekiq"
@CharlieHawker
CharlieHawker / aliases.sh
Created August 3, 2016 09:25
Useful bash aliases
# Export variables from a .env file
alias setup_env_vars='export $(cat .env | xargs)'
# Display human-readable subdirectory sizes
alias subdirsizes="ls -AF | grep \/ | sed 's/\ /\\\ /g' | xargs du -sh"
# Heroku - Restore postgres backup to given database name
herokuPgBackupRestore() {
dbname=${1?param missing - database name}
heroku pg:backups capture
@CharlieHawker
CharlieHawker / gulp-favicons.js
Last active January 15, 2019 21:13
Generate favicons for common sizes automatically from an SVG file using gulp
var gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
rimraf = require('gulp-rimraf'),
imageResize = require('gulp-image-resize');
gulp.task('clean:favicons', function() {
return gulp.src('dist/favicon*')
@CharlieHawker
CharlieHawker / closest-color.scss
Last active August 29, 2015 14:09
Find the closest color match to a given hex/RGB color from a given palette
/* Find the closest color match to a given hex/RGB color from a given palette */
@function closest-color($color, $palette: ()) {
// break down into individual colors
$components: red($color), green($color), blue($color);
// set some matching vars
$diff: 765; // 255 * 3, maximum possible diff
$closest: false; // not set yet...
@each $palette-color in $palette {
$pdiffs: (