This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // assume that form is bound to $form and file input is named image | |
| // @requires: jQuery, jQuery validate | |
| // an array of valid file types | |
| var whitelist = ['png','jpe?g','gif']; | |
| $form.validate( | |
| rules : { | |
| image : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $exec = "phpunit" | |
| watch('./(.*).php') { |m| changed(m[0]) } | |
| def changed(file) | |
| run "phpunit" | |
| end | |
| def run(cmd) | |
| result = `#{cmd}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User editable slug - with defaults | |
| ---------------------------------- | |
| Case: | |
| We want our post class to have slug and title attribues that are editable by the user. | |
| The user should be able to edit the title and slug independently. | |
| The slug should default to a slugged version of the title. | |
| example output: | |
| ```ruby |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Given a controller that looks like this | |
| class ModelsController < ApplicationController | |
| load_and_authorize_resource #CanCan | |
| def show | |
| if stale? @model | |
| respond_to do |format| | |
| format.json do | |
| @model | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sourceMapper = require 'source-map-support' | |
| Dot = require '../../../node_modules/grunt-mocha/node_modules/mocha/lib/reporters/dot.js' | |
| module.exports = Dot | |
| ## | |
| parseLine = (line) -> | |
| [_, file, row] = line.match /file:\/\/\/(.*):(\d*)/ | |
| frame = | |
| getFileName: -> file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sets up `text` and `html` variables that can be used to test the different parts of a multipart email | |
| RSpec.shared_context 'multipart email' do | |
| let(:html) do | |
| Capybara::Node::Simple.new( mail.body.parts.find {|p| p.content_type.match /html/}.body.raw_source ) | |
| end | |
| let(:text) { mail.body.parts.find {|p| p.content_type.match /plain/}.body.raw_source } | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } | |
| #HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; } | |
| #HTMLReporter a { text-decoration: none; } | |
| #HTMLReporter a:hover { text-decoration: underline; } | |
| #HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; } | |
| #HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; } | |
| #HTMLReporter #jasmine_content { position: fixed; right: 100%; } | |
| #HTMLReporter .version { color: #aaaaaa; } | |
| #HTMLReporter .banner { margin-top: 14px; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| @language = 'english' | |
| string = 'Hello world' | |
| Benchmark.bmbm do |x| | |
| x.report { 100000.times { a = Hash[@language, string] } } | |
| x.report { 100000.times { a = { @language => string } } } | |
| x.report { 100000.times { a = { "{@language}" => string } } } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Parent < ActiveRecord::Base | |
| has_many :children | |
| has_many :skills, through: :children | |
| def self.with_skill(skill_type) | |
| eager_load(:skills, :children).map do |p| | |
| p.children = [] unless p.skills.any? { |s| s.skill_type = skill_type } | |
| p | |
| end | |
| end | |
| end |