Skip to content

Instantly share code, notes, and snippets.

@tcannonfodder
tcannonfodder / testem.json
Last active December 10, 2015 18:08
This is a bare-minimum testem configuration file that will allow you to use testem with a rails project. You save it in the root directory of the project (at the same level as the Gemfile), and then you can navigate to the project and run testem. How it works: What this configuration does is precompile the assets before the tests are run using t…
{
"framework": "jasmine",
"src_files": [
"app/assets/javascripts/*.js",
"spec/scripts/*.js"
],
"serve_files": [
"public/assets/*.js",
"spec/scripts/*.js"
],
@tcannonfodder
tcannonfodder / spec_sheet_calculator.rb
Created February 21, 2013 14:59
Meant to be used with Markdown or other plaintext files. Looks for your estimated hours for a project, written in the syntax: [X hours]. Examples: [1 hour] , [10 hours], [10.5 hours], [.5 hours], [0.5 hours] Note that it doesn't work for estimations on the same line. I write my spec sheets where 1 bullet point has 1 estimation.
# Looks at the text file provided and uses my format of spec sheet hours to calculate the total hours of the project.
raise "Must provide Source File!" if ARGV.size < 1
total_hours = 0
spec_sheet = File.open(ARGV[0])
spec_sheet.each{ |line|
specced_hours = /\[[^0-9.]*(?<hours>\d*\.\d+|[^\.]\d*).*\]/.match(line)
@tcannonfodder
tcannonfodder / 1up_download.rb
Last active December 14, 2015 03:09
Download all the 1up shows, based on this pastebin: http://pastebin.com/Da1QMJUa . Heck, you could give it any text file of URLs and it would download them. Just did this for fun.
# require 'typhoeus'
episode_URLs = Array.new
URL_regex = /(?<url>http.*)\/(?<filename>.*)$/
URL_list = File.open("1upshow_urls.txt") # Read in the 1up show file
URL_list.each{
|line|
found_URL = URL_regex.match(line)
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
@tcannonfodder
tcannonfodder / gist:9939717
Last active August 29, 2015 13:58
Basic Controller
def new
@model = Model.new
@Title = "New Model"
end
def create
@model = Model.new(params[:model])
if @model.save
redirect_to model_path(@model), :flash => {:success => "Model Created"}
@tcannonfodder
tcannonfodder / freckle_recurring_budgets.rb
Created April 14, 2014 14:23
Sample script to create recurring project budgets for specific projects in your Freckle account using the API.
# Hey there!
#
# This is a basic script that shows how to give projects an "allowance", like
# 5 hours every month. First, it looks at how many hours you want to budget for
# each project. Then, it establishes a connection with the Freckle API, using your
# API token. It then loops through all the projects you listed, finding out how many
# minutes it needs to add or remove from the existing project budget. Finally, it
# updates the project and goes onto the next one.
#
# If you want to set a monthly budget, you would run this script once every month.
@tcannonfodder
tcannonfodder / gist:9ca5d465b92d59e43799
Created July 16, 2014 23:50
Freckle API v2 Error Message Example
{
"message": "you don't have permission to filter by imports",
"errors": [
{
"resource": "Entry",
"code": "insufficent_permissions",
"field": "import_ids"
}
]
}
@tcannonfodder
tcannonfodder / Gemfile
Created July 27, 2014 20:24
Sinatra Boilerplate
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'debugger', :require => false
gem 'mysql'
gem 'dbd-mysql'
gem 'dbi'
@tcannonfodder
tcannonfodder / backport.rb
Created July 31, 2014 19:07
Running Rail 2.3 LTS Performance Tests using Minitest
# include this in your test_helper.rb. It monkeypatches
# The methods used to actually run any performance tests
# subclassed from ActionController::PerformanceTest
# based on: https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/testing/performance.rb#L44
module ActiveSupport
module Testing
module Performance
def run(runner)
@tcannonfodder
tcannonfodder / add_allow_switch.rb
Last active August 29, 2015 14:05
Add test-spec's `add_allow_switch` to a MiniTest suite.
# Port of test-spec's `add_allow_switch` to MiniTest.
# This was originally written by @madrobby for Freckle: https://letsfreckle.com
# Make sure to rename `YourApp` to the namespace of your app.
module YourApp
class AddAllowSwitchCalledTwiceError < StandardError
# By overriding this method, we can provide a sort of default exception message
def self.exception(message)
super("Called add_allow_switch(#{message}) twice! Make sure you don't require your test helper twice.")
end