Skip to content

Instantly share code, notes, and snippets.

View andrewhavens's full-sized avatar

Andrew Havens andrewhavens

View GitHub Profile
@andrewhavens
andrewhavens / sse.rb
Created August 5, 2013 17:25
Working example of SSE using Sinatra and Redis, but with bad concurrency...please help to improve
require 'redis'
require 'sinatra/base'
class SSE < Sinatra::Base
def send_message(json)
"id: #{Time.now}\n" +
"data: #{json}" +
"\r\n\n"
end
@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"
@andrewhavens
andrewhavens / index.html
Created April 17, 2014 18:37
broken jQuery file upload example
<h1>Upload Documents</h1>
<form action="/documents" enctype="multipart/form-data" id="fileupload" method="post">
<input type="file" name="document[attachment][]" multiple="multiple">
<table>
<tbody id="files" class="files"></tbody>
</table>
</form>
<!-- jQuery 1.8.3 already included -->
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