Skip to content

Instantly share code, notes, and snippets.

View robwilliams's full-sized avatar

Rob Williams robwilliams

View GitHub Profile
# frozen_string_literal: true
if Rake::Task.task_defined?('webpacker:clean')
puts %(Task webpacker:clean has already been defined. The monkey patch located in "#{__FILE__}" can be removed.)
else
module WebPackerClean
def clean
return if !config.public_output_path.exist? || !config.public_manifest_path.exist?
count_to_keep = 2
@at0g
at0g / component-no-children.jsx
Created May 8, 2015 06:12
react components with rest/spread props
'use strict';
var React = require('react');
var ComponentNoChildren = React.createClass({
getDefaultProps: function () {
return {
Component: 'div',
className: 'component-no-children'
}
},
@dsimard
dsimard / has_many_through_includes.rb
Created April 8, 2015 16:28
`has_many :through` an association that uses `includes` throws an error
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.1' # as well as '4.2.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
@richhollis
richhollis / cors_middleware.rb
Last active August 16, 2017 20:33
CorsMiddleware which can be useful for testing SwaggerUI resources in development
class CorsMiddleware
def initialize(app)
@app = app
end
def call(env)
default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET, POST, DELETE, PUT, PATCH, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, api_key, Authorization, origin'
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@andyfowler
andyfowler / merge_post.feature
Created May 23, 2014 20:00
Nutshell REST API merge spec
Feature: Merging entities
Background:
Given a Nutshell with an account
@wip
Scenario: Basic JSON API compliance
When the client requests POST /accounts/1-accounts/merge with the body:
"""
{"accounts": ["336-accounts","337-accounts"] }
@mitchwongho
mitchwongho / Docker
Last active June 26, 2024 07:28
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash
@jlecour
jlecour / post_to_slack.rb
Last active May 22, 2022 17:43
How to post alerts from Monit to Slack
# encoding: UTF-8
require 'optparse'
require 'net/http'
require 'json'
def parse_options(argv)
opts = {}
@parser = OptionParser.new do |o|
@diamondap
diamondap / S3 Download URL
Last active July 5, 2021 19:52
Overriding S3 HTTP Headers (Ruby)
# Given an S3 URL, this returns a signed S3 url that will force the browser
# to download the file rather than opening it in the browser window. The key
# is to add response-content-disposition to the query string, which tells S3
# to send the content-disposition header you specify. S3 will respect this
# parameter only if the URL is signed. You can override other S3 headers such
# as content-type using this same method. See:
#
# http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html
#
def s3_download_url(url)
@shiftkey
shiftkey / magic.md
Created January 9, 2014 22:10
Git: reverting a revert using the reflog

Recovering from a bad revert

Open up Git Shell for your repository and type this command:

git reflog

This will show a list of recent actions that Git has performed against your repository: