Skip to content

Instantly share code, notes, and snippets.

View jnweaver's full-sized avatar

Nick Weaver jnweaver

View GitHub Profile
@jnweaver
jnweaver / has_many_attached.rb
Created October 26, 2023 13:00 — forked from fractaledmind/has_many_attached.rb
Vanilla Rails isomorphic attachment validations
# /app/models/concerns/has_many_attached.rb
module HasManyAttached
extend ActiveSupport::Concern
class_methods do
def has_many_attached(name, dependent: :purge_later, service: nil, strict_loading: false, **options)
super(name, dependent: :purge_later, service: nil, strict_loading: false)
if options[:file_types].any?
validate "validate_#{name}_file_types".to_sym
@jnweaver
jnweaver / mysql2sqlite.sh
Created October 12, 2023 12:59 — forked from esperlu/mysql2sqlite.sh
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@jnweaver
jnweaver / bower.json
Created January 21, 2015 20:57
Bower ignore test
{
"name": "UW_WP_Skeleton",
"version": "0.0.1",
"private": true,
"dependencies": {
"uw-ui-toolkit": "git://github.com/UWMadisonUcomm/uw-ui-toolkit.git#bowerignore"
},
"ignore": [
"**/.*",
"node_modules",
@jnweaver
jnweaver / gist:4e1d9ee41610308c7756
Created October 24, 2014 13:58
Wordpress Composer example
{
"name" : "uwmadison-umark/wordpress-skeleton",
"description" : "Skeleton WordPress Stack via Composer",
"authors" : [
{
"name" : "Nick Weaver",
"email" : "jnweaver@wisc.edu",
"homepage": "http://umark.wisc.edu"
}
],
@jnweaver
jnweaver / Capistrano_enviroment
Last active December 25, 2015 05:18
BASH cap bundler environment handling
# special handling for cap
function run_bundler_cap_cmd () {
if [ -e ./Gemfile ]; then
echo "bundle exec $@"
bundle exec $@
else
cmd=$@
echo ${cmd/cap /cap _2.15.5_ }
${cmd/cap /cap _2.15.5_ }
fi