Skip to content

Instantly share code, notes, and snippets.

View aghecht's full-sized avatar

Alan Hecht aghecht

View GitHub Profile
@rtomayko
rtomayko / Tests Is Wrong
Created January 28, 2009 20:50
Why "require 'rubygems'" In Your Library/App/Tests Is Wrong
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@jcasimir
jcasimir / render_and_redirect.markdown
Created September 11, 2011 21:29
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

  • Use Jamfile to list jam dependencies.
  • Create a temp package.json with correct baseURL, etc.
  • Install external dependencies to app/assets/javascripts/lib/
  • Convert tag helper to add files in asset lib dir to requirejs config
  • Fix compilation to include digests
  • Update helper to check for digests.yml file
record = Post.new(:title => 'Yay', :body => 'This is some insert SQL')
# easiest way to achieve this is by calling protected #arel_attributes_values (tested in
# rails 3.2.13). the alternative is to build the entire insert statement using arel >_>
record.class.arel_table.create_insert \
.tap { |im| im.insert(record.send(:arel_attributes_values, false)) } \
.to_sql
@machty
machty / router-facelift-guide.md
Last active November 11, 2023 06:44
Guide to the Router Facelift

Ember Router Async Facelift

The Ember router is getting number of enhancements that will greatly enhance its power, reliability, predictability, and ability to handle asynchronous loading logic (so many abilities), particularly when used in conjunction with promises, though the API is friendly enough that a deep understanding of promises is not required for the simpler use cases.

environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
app_path = "/var/www/webapp"
bundle_path = "#{working_directory}/../shared/bundle"
#listen "/tmp/.sock", :backlog => 64
listen 8080, :tcp_nopush => true
timeout 30
worker_processes 12
preload_app true
@GavinJoyce
GavinJoyce / gist:6403776
Created September 1, 2013 11:06
Run Loop Metrics Bookmarklet
javascript:(function(){
var getTimestamp = function() { return new Date().getTime(); };
if (window.performance.now) {
getTimestamp = function() { return window.performance.now(); };
} else if (window.performance.webkitNow) {
getTimestamp = function() { return window.performance.webkitNow(); };
}
var startTime, endTime, loopCount = 0;
@slindberg
slindberg / ember-data.dependent-relations.js
Last active November 5, 2021 21:41
Dependent Relationships in Ember Data
/**
Ember Data: Dependent Relationships
This package extends Ember Data to support creating relationships
where a model's dirty state depends not only on its own attributes
but on the dirty state of models in dependent relationships as well.
```javascript
App.Thing = DS.Model.extend({
name : DS.attr('string'),
@slindberg
slindberg / README.md
Last active August 29, 2015 13:56
Model 'Fragments' in Ember Data