Skip to content

Instantly share code, notes, and snippets.

%td
= form_for task, :remote => true, :url => ajax_update_path do |f|
= f.collection_select :task_type_id, TaskType.all, :id, :name, {}, { :class => 'submittable'}
# Custom RSpec matcher to test that an array contains only a single class of object
RSpec::Matchers.define :contain_only_instances_of do |expected|
match do |actual|
classes = actual.map(&:class).uniq
classes.size == 1 && classes.first == expected
end
end
Hi,
Found what seems to be a bug in the issues section of the github API. it may exist elsewhere, but I am not sure.
Your documentation says under the pagination section "Requests that return multiple items will be paginated to 30 items by default"
But I only seem to be getting 25 by default. Tested this on my own private repos as well as public. See example here:
curl "https://api.github.com/repos/rails/rails/issues"
@southpolesteve
southpolesteve / gist:4020578
Created November 5, 2012 21:50
Macbook Air (2011, i7) vs Raspberry Pi

Last night I finally got my raspberry pi up and running one of my current rails projects. This project is relatively simple, only 30 specs, and I wanted to see how it would stack up against my macbook air.

TL;DR: The pi is about 20 times slower running the actual tests (46s vs 2.2s), but loading the test environment is by far the slowest part. ~7 minutes.

This result makes me believe that I could use my pi as a nice little CI server for personal projects as long as the test suites are simple. This week I will be taking a look at some light weight CI servers and try running them on the pi.

See the full results below.

@southpolesteve
southpolesteve / gist:4152385
Created November 27, 2012 04:31
Open Source License for a Commercial SaaS Application

Background

I am building a SaaS application and I would like to be able to publish the source code while retaining commercial rights to the application. I did some research and it seems that most popular licenses are not structured to fit this model. I realize this kind of license may not fit with the general spirit of open source, but the alternative for most SaaS companies is that their primary code base is closed source. I am not convinced that has be the case. Why couldn't an app like Github or Basecamp be open source? Why couldn't community members submit pull requests and be paid for their work? There may be valid reasons this model won't work, but I am interested in exploring this further and hearing opinions

License Goals

  • Code can be freely distributed
  • Code can be modified without consent
  • Code can be run on a personal machine for personal use
  • Code cannot be used for commercial purposes, for the benefit of a commercial entity, or to directly compete with the copyright owner ("the co

Strings in Ruby can be set with single or double quotes, but the behavior is slightly different. Double quotes allow for the ability to insert variables into a string. Check out the following example:

name = "Steve"
puts "My name is #{name}"
#=> My name is Steve
puts 'My name is #{name}'
#=> My name is #{name}
@southpolesteve
southpolesteve / gist:5060497
Created February 28, 2013 22:02
Rake taks for finding unused methods in your rails app. A bit hacky and slow, but seems to work for most cases!
namespace :cleaner do
task :find do
models = Dir.glob("app/models/**/*")
all_files = Dir.glob("app/**/*")
models.each do |model|
if File.file?(model)
File.open(model).lines.each do |line|
if line=~ /def ([a-z0-9._?!]*)/
method_name = line.match(/def ([a-z0-9._?!]*)/)[1]
method_name.sub!(/self./, '')
I have been playing with a lot of client side apps lately (mostly Ember). Writing the APIs to back these is often a bit tedious. I find myself writing code over and over to match Ember Data's expectations when really I just wanted Rails to automatically expose my models as these APIs. I struggled to find an existing gem that did this.
So over the past couple weekends, I built one: https://github.com/southpolesteve/api_engine
What is it? A Rails engine that automatically exposes your models in a Ember compatible API (including bulk operations). Serialization is done via Active Model Serializers. There is still a bit to be done before it is ready for wide release, but the basic functionality works.
Short term issues
- Add ability to create a model white list.
- Add ability to restrict exposed actions on a model.
- Do a proper release on rubygems
@southpolesteve
southpolesteve / kisok_BOM_v2.md
Last active May 1, 2019 20:24
Kiosk BOM V2
@southpolesteve
southpolesteve / image_spec.rb
Created August 9, 2013 16:28
A RSpec test that checks all your images for proper compression
require "spec_helper"
require 'fastimage'
describe "Image Compression" do
Dir[Rails.root.join("app/assets/images/*.{jpg,png,gif}")].each do |file|
context "#{file}" do
it "should be properly dimensioned" do
FastImage.size(file).each do |dim|
dim.should < 2000 # pixels