Skip to content

Instantly share code, notes, and snippets.

require "multi_json"
module OliveBranch
class Checks
def self.content_type_check(content_type)
content_type =~ /application\/json/
end
end
class Transformations
require "multi_json"
module OliveBranch
class Middleware
def initialize(app, args = {})
@app = app
@camelize_method = args[:camelize_method] || method(:camelize)
@dasherize_method = args[:dasherize_method] || method(:dasherize)
@content_type_check_method = args[:content_type_check_method] || method(:content_type_check)
end
@zdennis
zdennis / foo_spec.rb
Created January 11, 2018 19:17
rspec-given's Given! behaves differently than rspec's let!
require 'spec_helper'
RSpec.describe "Foo" do
before do
puts "Was bananas called yet?"
end
Given(:bar) { puts "bar" }
Given!(:bananas) { puts "bananas" }
@zdennis
zdennis / olive-branch-transformations-snippet.rb
Created December 1, 2017 20:30
OliveBranch transformation snippet for blog post
camelCasedPayload = OliveBranch::Transformations.transform(
{ key.to_sym => payload },
OliveBranch::Transformations.method(:camelize)
)
import Ember from 'ember';
export default Ember.Component.extend({
// detect a control click
contextMenu(){
console.log("I've been ctrl-clicked.");
window.open("https://www.google.com", "_blank");
// do not show the default right-click menu
return false;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
filter: 'all',
init: function () {
this._super();
Ember.run.schedule("afterRender",this,function() {
this.updateSortable();
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
clicked(){
const clicked = this.get('clicked');
this.get('model').toggleProperty('completed');
if(clicked) { clicked(); }
}
}
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
clicked() {
this.$().append("Clicked");
}
}
});
@zdennis
zdennis / snippet1.rb
Last active July 15, 2016 14:41
code snippets for importing-data-and-handling-conflicts-in-ruby-on-rails-applications
create_table :authors do |t|
t.string :name
t.string :key
t.integer :revision
t.datetime :last_modified_at
t.timestamps
end
add_index :authors, :key, unique: true
@zdennis
zdennis / YapUsages.md
Created July 7, 2016 17:56
Yap Usages

I used this snippet copy a CircleCI page with a bunch of spec failures. I pasted that into foo.txt and then ran the following command to extract all of the specs that failed:

cat foo.txt | !contents.scan(/[^\s]+_spec\.rb/).sort.uniq.join(' ').gsub("'", '')