Skip to content

Instantly share code, notes, and snippets.

View coryodaniel's full-sized avatar
☘️
O'Internets

Cory O'Daniel coryodaniel

☘️
O'Internets
View GitHub Profile
@coryodaniel
coryodaniel / routeQueue.js
Last active January 8, 2016 19:13
Queue up functions to run against a specific controller/action pair
var Page = Page || {};
(function(Page) {
'use strict';
var routeQueue = [];
Page.runRouteQueue = function(){
routeQueue.forEach(function(cb, index, array) {
cb();
});
};
@coryodaniel
coryodaniel / active_model_serializer_matcher.rb
Last active February 8, 2016 23:23
rails-api/active_model_serializers rspec matcher
# expect(json).to have_serialized(post).with(PostSerializer)
RSpec::Matchers.define :have_serialized do |unserialized|
# The serializer to use on the resource
chain :with do |serializer|
@serializer = serializer
end
# The serializer to use on the collection
chain :wrap do |collection_serializer|
@collection_serializer = collection_serializer
@coryodaniel
coryodaniel / mysql_collation_and_character_sets.sql
Created February 26, 2016 00:44
MySQL Collation and Character Set export to CSV
MySQL Collation Checkup
SELECT @@character_set_database, @@collation_database
INTO OUTFILE '/tmp/table_defaults_charset.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
SELECT * FROM information_schema.schemata
INTO OUTFILE '/tmp/schema_charset.csv'
@coryodaniel
coryodaniel / blueprint.rake
Created July 11, 2016 16:19
Break up (apiary) blueprints into smaller manageable git-friendly pieces and compile together.
# * /blueprints
# * /{version_name}
# *
# * manifest.yml
#
# :v1:
# - meta
# - structures/*
# - resources/addresses
# - resources/countries
@coryodaniel
coryodaniel / dredd.rb
Created July 11, 2016 16:24
Run Apiary / Dredd using capybara, simplecov, factory girl and database cleaner
# instead of having dredd start up an endpoint, this will boot your endpoint up
# using capybara so that we can take advantage or ruby testing tools like FactoryGirl, DatabaseCleaner and SimpleCov
include DreddHooks::Methods
ENV["RAILS_ENV"] = "test"
require "rubygems"
require "bundler/setup"
unless ENV["SKIP_COVERAGE"]
@coryodaniel
coryodaniel / ENV_finder.rb
Created July 15, 2016 18:29
Find env variables
env = Dir['myproject/**/*.rb'].
map { |file| File.read(file).match(/ENV\[['"](.+?)(?=[\]'"])/) }.
compact.
map{|matchdata| matchdata[1]}.uniq.sort
@coryodaniel
coryodaniel / db_permissions.rake
Created August 5, 2016 18:25
Enforce/Revoke db permission restrictions against MySQL when migrating models to another app
namespace :app do
# List of models that are in the new app, that should not be revoked yet from app-transition
# The goal should be to keep this VERY SHORT. Users is being added here because its a god
# model.
DONT_REVOKE = %w(users)
ACCOUNT_NAME = 'app-transition'
SCHEMA_NAMES = ['app_development', 'app_test']
namespace :db do
desc "Disregard transitionary permissions on old MySQL Account"
@coryodaniel
coryodaniel / flog.rake
Created August 5, 2016 22:35
Rake task to flog your rails commits for CI
namespace :ci do
desc "Flog it"
task :flog do
max_score = 10.0
changed_files = `git diff develop --name-only | grep "app/" | grep ".rb" | tr '\n' ' '`.split(' ')
if changed_files.any?
avg_score = `flog -g -s #{changed_files.join(' ')} | tail -n 1`
score = avg_score.match( /(\d+\.\d+)/)[0].to_f
@coryodaniel
coryodaniel / filtering_params.rb
Created August 16, 2016 14:27
Using Rails params filter on an arbitrary hash
filters = Rails.application.config.filter_parameters
f = ActionDispatch::Http::ParameterFilter.new filters
f.filter user:{password: 'haha’} # => user: {:password=>"[FILTERED]"}
f.filter :password => 'haha' # => {:password=>"[FILTERED]"}
@coryodaniel
coryodaniel / routes.rb
Created August 18, 2016 13:49
UUID Regex for Rails router constraint
resource :foos, constraints: {:id => /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/}
resource :bars, constraints: {:id => /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(,[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})}