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
#!/usr/bin/env ruby | |
# This quick and dirty script imports posts and images exported by the | |
# Posterous backup feature into Octopress. Requires the escape_utils and | |
# nokogiri gems. Doesn't import comments. | |
# | |
# Videos and images are copied into a post-specific image directory used | |
# by my customized Octopress setup. Encoded videos are downloaded from | |
# Posterous. Images will probably need to be compressed/optimized afterward. | |
# | |
# Links to other posts in the same import will try to be converted. You will |
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
## I imagine this could be done in the migration, but it was giving me problems so I moved it to the model | |
## and just did it on the command line | |
> Tag.reset_questions_count |
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
#Here's what I'm using. Maybe you could adapt it to your case. I have this on a Message model. | |
def method_missing(method_name, *args, &block) | |
if method_name =~ /(.*)_recipients$/ | |
self.correspondences.where('recipient_type = ?', $1.to_s.humanize) | |
.collect{ |c| c.recipient }.flatten.uniq | |
else | |
super | |
end | |
end |
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
jQuery -> | |
$('[id^="best_in_place_your_object_"],[id$="address"]').on 'best_in_place:update', (event) -> | |
$address = $(event.target) | |
$address.data('bestInPlaceEditor').original_content = $address.html() | |
$address.html $address.html().replace(/[\n\r]+/g, '<br>') |
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 update | |
@client = current_user.clients.find(params[:id]) | |
respond_to do |format| | |
if @client.update_attributes(params[:client]) | |
format.html { redirect_to @client, notice: 'Client was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: "edit" } |
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 Student < ActiveRecord::Base | |
has_many :grades do | |
def below_average | |
where('score < ?', 2) | |
end | |
end | |
end |
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
1.9.2p0 :002 > f = User.first | |
User Load (0.4ms) SELECT "users".* FROM "users" LIMIT 1 | |
=> #<User id: 1, email: "[email protected]", encrypted_password: "$2a$10$LTc6zq5VorMZzsDSv7nD2eZpQkV30BaylB2Q6oY4yYjJ...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2012-06-13 08:12:53", last_sign_in_at: "2012-06-13 08:09:08", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", name: "Ayy Bee Cee", created_at: "2012-06-13 08:08:01", updated_at: "2012-06-13 08:12:53", confirmation_token: nil, confirmed_at: "2012-06-13 08:09:08", confirmation_sent_at: "2012-06-13 08:08:01", unconfirmed_email: nil, authentication_token: nil> | |
1.9.2p0 :003 > f.categories | |
Category Load (8.1ms) SELECT "categories".* FROM "categories" INNER JOIN "categories_users" ON "categories"."id" = "categories_users"."category_id" WHERE "categories_users"."user_id" = 1 | |
=> [] | |
1.9.2p0 :003 > f.categories | |
=> [] | |
1.9.2p0 :007 > f.categories.create({:id => 1}) | |
(0.1ms) |
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
Interactive ruby ready. | |
> food = ['chicken', 'steak', 'beef', 'pork'] | |
=> ["chicken", "steak", "beef", "pork"] | |
> food.each do |x| | |
.. puts x | |
.. end | |
=> #<SyntaxError: <script>:1: syntax error, unexpected end-of-file | |
food = ['chicken', 'steak', 'beef', 'pork'];food.each do |x|; | |
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
#(Element:0x8427df88 { | |
name = "a", | |
attributes = [ | |
#(Attr:0x841fe3a0 { | |
name = "href", | |
value = "http://google.com" | |
})], | |
children = [ #(Text "Google Home Page")] | |
}) |
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
# Get a URL's content to play with | |
content = contents[contents.keys.first] | |
# => [#<Nokogiri::XML::Element:0x48a9a86 name="p" children=[#<Nokogiri::XML::Text:0x48a9810 "The autobiography of Yohwan Lim, ">, #<Nokogiri::XML::Element:0x48a96ee name="i" children=[#<Nokogiri::XML::Text:0x48a9536 "Crazy As Me">]>, #<Nokogiri::XML::Text:0x48a931a " was released in Korea by BookRoad Publishers in October 25, 2004. This is my translation of the book, except the following four sections which were translated by BinaryStar of Teamliquid.net, which I have made minor changes: \"Hope on the Road Not Taken,\" \"Chapter One: The Game-crazed Kid,\" \"The Birth of the Emperor,\" and \"The Little Prince with Three Sisters.\"">]>, #<Nokogiri::XML::Element:0x48a9194 name="p" children=[#<Nokogiri::XML::Text:0x48a9022 "As of October 4, 2004:">]>, #<Nokogiri::XML::Element:0x48a8e92 name="p">, #<Nokogiri::XML::Element:0x48a8ce4 name="p" children=[#<Nokogiri::XML::Text:0x48a8af0 "The addition of e-sports organizations to major compani |