Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
@stevenharman
stevenharman / music_library.rb
Created December 11, 2011 01:41
When wrapping AR behind an intentional interface, go explicit or generic/idiomatic?
# This is a record, as in a vinyl.
class Record < ActiveRecord::Base
belongs_to :user
belongs_to :album
# explicitly stating what is needed
def from_library_for_album(collector, album)
where(user_id: collector).where(album_id: album)
end
@adamlogic
adamlogic / gist:1435139
Created December 5, 2011 20:07
Setup instructions for developer machine (Ruby)

My setup for Rails dev on OS X Lion

  1. Back up

    A few things to think about:

    • media
      • photos, music, and videos should all be on external drive
    • projects/code
  • make sure all Git repos are pushed up
@dx7
dx7 / gist:1333785
Created November 2, 2011 14:33
Installing ruby-debug with ruby-1.9.3-p0
### UPDATE: ruby-debuy19 is no longer maintained, use https://github.com/cldwalker/debugger
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
@tonywok
tonywok / ios-test.css
Created October 19, 2011 19:08
iOS Media Queries
// iOS Media Queries
// Goal: capture styles for iPhone, iPhone 3G, iPhone 3GS, iPhone 4, iPhone 4S, iPad, and iPad 2
//
// Author: Tony Schneider (@tonywok)
// Please tell me where I fail. :)
// iPhone v(4,4S) portrait
// test: black text (overwritten by v* portrait) with blue background
@media all and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
a {
person = {
save: function(){
$.ajax('...', {
context: this,
success: this.saved,
error: this.errored
})
},
saved: function(data){
console.log('OMG. USEFUL SCOPING.')
@alloy
alloy / gist:1281203
Created October 12, 2011 13:17
ActiveRecord::Relation#merge example
class Edition < ActiveRecord::Base
scope :published, where(arel_table[:published_at].not_eq(nil))
scope :generated, where(arel_table[:generated_at].not_eq(nil))
scope :available, published.generated
end
class Magazine < ActiveRecord::Base
# This is where #merge works its magic, by allowing you to merge scopes from other models.
scope :with_available_editions, includes(:editions).merge(Edition.available)
end
@jcasimir
jcasimir / performance.markdown
Created September 21, 2011 13:27
Measuring Performance

Measuring Performance

Performance is often ignored in Rails development until it becomes a problem. If ignored too long, though, it can get very tricky to improve. It's valuable to regularly audit performance and look for hotspots or design choices that are slowing things down.

Inspecting the Logs

Inspecting the log will help identify the source of several performance issues the application may have.

The Rails application log outputs the time spent processing each request. It breakdowns the time spent at the database level as well processing the view code. In development mode, the logs are displayed on STDOUT where the server is being run. In a production setting the logs will be in log/production.log within the application's root directory.

@zspencer
zspencer / your_script.sh
Created September 6, 2011 22:58
Pair with Zee
#If you're on a mac/linux, you can just copy and paste this. If you're on Windows, you need to figure out how to do this using Putty.
ssh [email protected]
@catharinejm
catharinejm / gist:1196418
Created September 6, 2011 02:26
inner function closure in C
#include <stdlib.h>
#include <stdio.h>
int(*outer(int val))() {
int inner() {
return val;
}
return inner;
}
dc.ui.Document = Backbone.View.extend({
initialize: function() {
this.model.bind('change', this._onDocumentChange);
this.model.bind('change:selected', this._setSelected);
this.model.bind('view:pages', this.viewPages);
this.model.notes.bind('add', this._addNote);
this.model.notes.bind('reset', this._renderNotes);
this.model.pageEntities.bind('reset', this._renderPages);
}