Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
@kylefox
kylefox / gist:4512777
Created January 11, 2013 18:15
If you want to use Xcode's FileMerge as your git mergetool, this is how you set it up.
# Tell system when Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff
@kylefox
kylefox / liquid-mode.js
Created November 11, 2011 00:02
Liquid syntax highlighting for CodeMirror.
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {
@kylefox
kylefox / attachment-utils.js
Created October 17, 2018 15:58
Convert Base64 data URLs to File objects for Trix attachments
window.AttachmentUtils = (function() {
var BASE64_MARKER = ';base64,';
var Utils = {
// Takes a file size (in bytes) and returns a human-friendly string representation.
humanFileSize: function(size) {
if(size < 1) return "0 bytes";
// http://stackoverflow.com/a/20732091
@kylefox
kylefox / modal-timed-close.js
Created April 16, 2014 17:56
Close jquery-modal 5 seconds after being opened.
// Attach an event handler to when the modal is opened.
$(document).on($.modal.OPEN, function(event, modal) {
// Use setTimeout to close the modal in 5 seconds (5000 milliseconds).
setTimeout(function() {
$.modal.close();
}, 5000);
});
@kylefox
kylefox / color.m
Created January 27, 2012 17:45
Generate a random color (UIColor) in Objective-C
/*
Distributed under The MIT License:
http://opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
@kylefox
kylefox / 001_add_record_uuid_to_active_storage_attachments.rb
Last active January 12, 2022 21:52
Migrations that make ActiveStorage attachments work with UUID primary keys. https://github.com/rails/rails/pull/32466
class AddRecordUuidToActiveStorageAttachments < ActiveRecord::Migration[5.2]
def change
# After applying this migration, you'll need to manually go through your
# attachments and populate the new `record_uuid` column.
# If you're unable to do this, you'll probably have to delete all your attachments.
# You've pretty much got useless garbage data if that's the case :(
add_column :active_storage_attachments, :record_uuid, :uuid
end
end
@kylefox
kylefox / find_unused_helpers.rb
Created March 28, 2019 21:49 — forked from kennethkalmer/find_unused_helpers.rb
Find unused helpers in a Rails app
#!/usr/bin/env ruby
#
# Shotgun approach (read: slow and dirty hack) to help find unused helpers in a Rails application
#
start = Time.now
# Build an array of filename globs to process.
# Only search file types that might use or define a helper.
extensions = %w[rb js haml erb jbuilder].map { |ext| "app/**/**/*.#{ext}" }
@kylefox
kylefox / __init__.py
Last active July 1, 2021 12:12
Connecting Django Signals using the AppConfig ready handler: https://docs.djangoproject.com/en/1.10/ref/applications/#django.apps.AppConfig.ready
default_app_config = 'cn.apps.users.config.UsersAppConfig'
@kylefox
kylefox / post_compile.sh
Last active October 23, 2020 08:42
Run Django database migrations after deploy to Heroku. This file must live at `bin/post_compile` within your root project directory.
# !/usr/bin/env bash
# File path should be ./bin/post_compile
# (.sh extension added in Gist just to enable shell syntax highlighting.
# https://discussion.heroku.com/t/django-automaticlly-run-syncdb-and-migrations-after-heroku-deploy-with-a-buildpack-or-otherwise/466/7
echo "=> Performing database migrations..."
python manage.py migrate
@kylefox
kylefox / context_for_sign_in_after_confirmation.rb
Created March 24, 2020 18:08
Rails controller concern for automatically signing in Devise users after they confirm their email address.
shared_context 'sign in after confirmation' do |resource_name:|
before do
@request.env['devise.mapping'] = Devise.mappings[resource_name]
end
shared_examples 'failed confirmation' do |error:|
it { is_expected.to have_http_status :ok }
it { is_expected.to render_template 'devise/confirmations/new' }
it "has errors on @#{resource_name}" do