This file contains 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
u = User.find(params[:id]) | |
u.activities.last # Does a find(:last) | |
# Add something to the activities | |
u.activities.create!({:description => "List activities"}) | |
u.activities.last # Fetches all activities of the user - Painfull when a user has 30000 activities |
This file contains 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 'lingua/en/readability' | |
class Haiku | |
def initialize(text) | |
@report = Lingua::EN::Readability.new(text) | |
@used_words = Array.new | |
end | |
def get_most_used_words(words) | |
top_words = Array.new | |
words.sort{|a,b| a[1]<=>b[1]}.slice(words.length/2..words.length).each do |a| |
This file contains 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 ApplicationController < ActionController::Base | |
protect_from_forgery | |
class << self | |
def responder *responders | |
if responders.any? | |
responder_class = Class.new(ActionController::Responder) | |
responders.each do |responder| | |
responder = responder.is_a?(Module) ? responder : "#{responder.to_s.classify}Responder".constantize | |
responder_class.send(:include, responder) |
This file contains 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
ruby-1.9.2-p180-patched :001 > (1..2).zip(1..2) | |
(irb):1: [BUG] Bus Error | |
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] | |
-- control frame ---------- | |
c:0027 p:---- s:0092 b:0092 l:000460 d:000460 CFUNC :next | |
c:0026 p:---- s:0090 b:0090 l:000085 d:000089 IFUNC | |
c:0025 p:---- s:0088 b:0088 l:000087 d:000087 CFUNC :each | |
c:0024 p:---- s:0086 b:0086 l:000085 d:000085 CFUNC :zip | |
c:0023 p:0014 s:0082 b:0082 l:001d18 d:000081 EVAL (irb):1 |
This file contains 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
[[MyClass alloc] initWithItem:self.item] | |
@implementation MyClass | |
- (void) speak | |
{ | |
NSLog(@"%@ costs %@", self.item.title, self.item.price); | |
} | |
// OR |
This file contains 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
$(document).on('click', 'a[href*="#"]', function(e) { | |
var $anchor = $(this), | |
hash = $anchor.attr('href'), | |
url = hash.substr(0, hash.indexOf('#')), | |
$hash = $(hash.substr(hash.indexOf('#'))); | |
if(url.indexOf(document.location.pathname) >= 0 && $hash.length > 0) | |
{ | |
e.preventDefault(); |
This file contains 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 Artist < ActiveRecord::Base | |
has_many :tracks | |
accepts_nested_attributes_for :tracks | |
end | |
class Track < ActiveRecord::Base | |
before_destroy :check_track | |
def check_track | |
return false if created_at > 1.week.ago |
This file contains 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
### Keybase proof | |
I hereby claim: | |
* I am DefV on github. | |
* I am defv (https://keybase.io/defv) on keybase. | |
* I have a public key whose fingerprint is CF6C 837A FC61 A672 EB88 B14A 8C49 44CF C9C3 6768 | |
To claim this, I am signing this object: |
This file contains 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
### Keybase proof | |
I hereby claim: | |
* I am DefV on github. | |
* I am defv (https://keybase.io/defv) on keybase. | |
* I have a public key whose fingerprint is CF6C 837A FC61 A672 EB88 B14A 8C49 44CF C9C3 6768 | |
To claim this, I am signing this object: |
This file contains 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
def icon_link_to(name, link, options = {}) | |
link_to link, options do | |
content_tag(:span, name) + content_tag(:i, '', class: "fa fa-#{options[:icon]}" | |
end | |
end |
OlderNewer