Skip to content

Instantly share code, notes, and snippets.

@turadg
turadg / subdomains.rb
Last active Oct 12, 2020 — forked from rtekie/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
View subdomains.rb
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@turadg
turadg / application.rb
Last active May 14, 2019
Handle only 404s dynamically. It uses a normal controller and route for 404s, letting everything else go to the Rails default /public error pages. In my case it was to use the subdomain logic in my ApplicationController.
View application.rb
module MyApp
class Application < Rails::Application
require Rails.root + 'lib/custom_public_exceptions'
config.exceptions_app = CustomPublicExceptions.new Rails.public_path
end
end
@turadg
turadg / install-ruby-2.0.0.sh
Last active Aug 9, 2018 — forked from sferik/install-ruby-2.0.0.sh
Install Ruby 2.0 with Readline and latest OpenSSL
View install-ruby-2.0.0.sh
#!/usr/bin/env sh
brew update
# upgrade any that were already installed
brew upgrade rbenv ruby-build readline openssl
# install what's missing
brew install rbenv ruby-build readline openssl
@turadg
turadg / generateFlowModuleNameMappers.js
Last active Jun 20, 2018
Helper to create .flowconfig module name mapper
View generateFlowModuleNameMappers.js
#!/usr/bin/env node
/**
* Flowtype understands Node (or Haste) imports but not Webpack.
*
* Many codebases have webpack set up like:
* src/foo.js
* src/components/Bar.jsx
*
* And then import them like `require('foo')` or `require/components/Bar.jsx`
*
@turadg
turadg / silence-React-15-deprecations.js
Last active Apr 13, 2018
Jest setup file to stop React 15.5 createClass / PropTypes deprecation warnings
View silence-React-15-deprecations.js
import React from 'react';
/**
* Since React v15.5, there's a warning printed if you access `React.createClass` or `React.PropTypes`
* https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings
*
* `import * as React from 'react'` is required by Flowtype https://flow.org/en/docs/react/types/ ,
* but the * causes both those deprecated getters to be called.
* This is particularly annoying in Jest since every test prints two useless warnings.
*
@turadg
turadg / removeUnusedModules.sh
Created Dec 8, 2017
Find in webpack builds modules that are never imported
View removeUnusedModules.sh
#!/bin/bash
echo "Testing prod build for modules in src that aren't ever imported."
echo
echo "NOTE: Any dev-only imports will appear to be unused."
USED_LIST_PATH=usedModules.txt
STATS_PATH=public/assets/stats.json
@turadg
turadg / rake.sh
Created Feb 23, 2011
Bash completion for ruby Rake
View rake.sh
# bash completion for rake
#
# some code from on Jonathan Palardy's http://technotales.wordpress.com/2009/09/18/rake-completion-cache/
# and http://pastie.org/217324 found http://ragonrails.com/post/38905212/rake-bash-completion-ftw
#
# For details and discussion
# http://turadg.aleahmad.net/2011/02/bash-completion-for-rake-tasks/
#
# INSTALL
#
View Send Chrome to OmniFocus.scpt
-- based on post by iNik: http://forums.omnigroup.com/showthread.php?p=101947#post101947
global theTitle, theTaskNote
set theTaskNote to ""
tell application "Google Chrome"
-- activate
tell window 1 to tell active tab
@turadg
turadg / swaggerTable.js
Created Jan 3, 2017
Generate a tab delimited table of endpoints on a Swagger-described API
View swaggerTable.js
#!/usr/bin/env node
/*
For Swagger 1.2 docs format.
Hardcode the base path in the urlFor() function.
Assumes Node 6+.
*/
View retroflow.sh
#!/bin/bash
#
# Retroflow
#
# This makes it easier to retrofit Flow type checking onto your existing code.
#
# Given a path argument, it finds all the js/jsx files under that path that
# don't have the Flow (flowtype.org) preamble. It then adds it and runs the
# Flow check. If anything fails, it removes it again.
#
You can’t perform that action at this time.