Skip to content

Instantly share code, notes, and snippets.

Brad Gessler bradgessler

Block or report user

Report or block bradgessler

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bradgessler
bradgessler / docker.sh
Created Nov 15, 2016
First CLI commands
View docker.sh
$ docker run ubuntu /bin/echo 'Hello world'
Hello world
@bradgessler
bradgessler / initializer.rb
Last active Mar 10, 2017
MIddleware for making legacy versions of Internet Explorer (anything below 11) work with rails. I release this code under MIT license.
View initializer.rb
# ./config/initializers/rewrite_ie_header.rb
# Don't forget to include the middleware file! If you have a ./lib/middleware folder in rails
# a `require './lib/middleware/rewrite_ie_header.rb'` should do the trick
#
# IE has a really stupid accept header, so here we scope its domain of mime-types that it can negotiate, otherwise we'll
# end up with weird bugs where if you hit /mcp/:id, IE will download a .ppt file instead of the .html content.
#
# Issue documented in more detail at https://github.com/rails/rails/issues/9940.
Rails.application.config.middleware.use RewriteIEAcceptHeader do |ie_mime_types|
View bundle
#!/usr/bin/env bash
export IMAGE_NAME=my_app
CONTAINER_ID=$(docker run -d $IMAGE_NAME bundle $@)
docker logs -f $CONTAINER_ID
docker commit $CONTAINER_ID $IMAGE_NAME
View pundit_matcher.rb
module PunditExampleGroup
extend ::RSpec::Matchers::DSL
matcher :permit do |action|
match do |policy|
policy.public_send("#{action}?")
end
failure_message do |policy|
"#{policy.class} does not permit #{action} on #{policy.record} for #{policy.user.inspect}."
@bradgessler
bradgessler / license.rb
Created Jul 2, 2014
Print a list of licenses for gems in a bundle.
View license.rb
require 'bundler'
require 'yaml'
def format(hash)
Hash[hash.keys.map(&:to_s).zip(hash.values)].to_yaml
end
Bundler.load.specs.each do |spec|
puts format({
name: spec.name,
@bradgessler
bradgessler / list.hon
Last active Dec 29, 2015
JSON is too verbose for hypermedia APIs. HON (Hypermedia Object Notation) preserves the readability and implicit data structure of JSON while with the addition of line attributes for URL and pagination metadata. From http://bradgessler.com/articles/hon/
View list.hon
{
name: "Todo List",
items(href: '/lists/1203/items', next_href: "/lists/1203/items?page=2"): [
item(href: '/items/1'): {
description: "Pick up pizza",
status: "completed"
},
item(href: '/items/12'): {
description: "Eat pizza",
status: "non_started"
View a.json
{
a: {
attributes {
href: 'foo.html'
}
value: 'Click Here'
}
}
View link.json
@bradgessler
bradgessler / doc.erb.bd
Last active Dec 16, 2015
Sketch for a Tilt/Markdown extension that makes it a little easier to add structure to markdown after its rendered.
View doc.erb.bd
# How to tie your shoes
<%= toc.each do |id, text| %>
* [<%= text %>](#<%= id %>)
<% end %>
## Unlace them
Gotta make sure its untied before you tie it!
@bradgessler
bradgessler / sketch.md
Last active Dec 16, 2015
Why merge backburner with quebert?
View sketch.md

Assessment of Quebert & Backburner to figure out how to merge the two.

Quebert

  1. Build out an async proxy in place of #async_send so that TTR, delays, and priority can be specified in a cleaner way. This looks something like User.new.async(delay: 3).send(:notify_user) as opposed to the current User.new.async_send(:notify_user, :quebert => {delay: 3, pri: 1000})
  2. Quebert supports many back-ends: InProcess, Sync, and Beanstalk. Sync and InProcess were created to aid with testing assertions so that Quebert.backend.queue.should have(1).items is possible. It only needs Beanstalk, so the multiple-backends could be removed for the sake of simplicity. A stub could be provided for peeps that want to assert jobs are thrown on the queue in a test env.
  3. There's a controller layer between the Job and the Backend that communicates using exceptions, which is suppose to deal with multiple backends. Eww. I want to just pass a controller into the job and have it deal.

Backburner

You can’t perform that action at this time.