Skip to content

Instantly share code, notes, and snippets.

View andrewhavens's full-sized avatar

Andrew Havens andrewhavens

View GitHub Profile
@andrewhavens
andrewhavens / config.ru
Created November 7, 2012 07:18
Ruby static site with Rack
use Rack::Static, :root => "public"
run lambda { |env|
[200, {'Content-Type' => 'text/html'},
File.open('public/index.html', File::RDONLY)
]
}
@andrewhavens
andrewhavens / app.rb
Last active December 21, 2015 17:59
Gosu error on Raspberry Pi
require 'gosu'
class Window < Gosu::Window
def initialize
super(800, 600, true) # go fullscreen if possible
end
def button_down(button)
close if button == Gosu::KbEscape
end
@andrewhavens
andrewhavens / widget_management_spec.rb
Last active December 22, 2015 00:58
Example of a Capybara feature file, imperative style
feature "widget management" do
background do
@user = Fabricate(:user)
visit auth_login_path
fill_in "Username", with: @user.username
fill_in "Password", with: "password"
click_button "Log In"
end
@andrewhavens
andrewhavens / 0_widget_management_spec.rb
Last active December 22, 2015 00:58
Example of Capybara feature file, declarative style
feature "widget management" do
include AuthenticationSteps
include WidgetSteps
background do
i_log_in_as_a_user
end
scenario "creating a new widget" do
@andrewhavens
andrewhavens / 0_widget_management.feature
Created August 30, 2013 21:20
Cucumber example, declarative style
Feature: Widget Management
Background:
Given I am logged in as a user
Scenario: Creating a new widget
When I create a widget
Then I should see "Widget was successfully created."
@andrewhavens
andrewhavens / search_spec.rb
Last active December 24, 2015 10:29
Broken thinking sphinx rspec config
feature "Search for Models" do
let(:my_model){ FactoryGirl.create(:my_fancy_model) }
before do
ThinkingSphinx::Test.index
end
scenario "A user searches for models by title" do
visit "/models"
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
itemSelected(item) {
console.log("itemSelected", item);
this.get("itemCallback")(item);
}
}
});
@andrewhavens
andrewhavens / jsonapiembedded-records.js
Created April 28, 2016 04:49
JSON API compatible Ember Data EmbeddedRecordsMixin
import Ember from 'ember';
var camelize = Ember.String.camelize;
export default Ember.Mixin.create({
// The following is mostly identical to the JSONAPISerializer implementation,
// with the exception of adding an attributes key to the payload.
// https://github.com/emberjs/data/blob/v2.5.2/addon/serializers/json-api.js#L471
serializeHasMany(snapshot, json, relationship) {
var key = relationship.key;
@andrewhavens
andrewhavens / motion-version.sh
Created August 6, 2016 06:51
Checking your RubyMotion version
$ motion --version
4.8
@andrewhavens
andrewhavens / motion-create.sh
Created August 6, 2016 06:55
Displaying the list of available motion templates
$ motion create
Usage:
$ motion create APP-NAME
Create a new RubyMotion project from one of the following templates: android, gem, ios (default), ios-action-extension, ios-custom-keyboard, ios-document-picker, ios-file-provider, ios-framework, ios-photo-editing, ios-share-extension, ios-today-extension, ios-watch-app, ios-watch-extension, osx, tvos, redpotion-template.
Options:
--template=[NAME|URL] A built-in template or from a file/git URL