Create a new instance of Magick::Image out of uploaded form data
def file=(new_file) new_file.rewind image = Magick::Image::from_blob(new_file.read).first end
12110 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
def file=(new_file) new_file.rewind image = Magick::Image::from_blob(new_file.read).first end
dial *#0000#
>>> import sysinfo >>> sysinfo.sw_version() u'V 3.42.1 16-10-03 NHL-10 (c) NMP' >>> firmware = _.split(' ')[3] >>> firmware u'NHL-10' >>>
>>> mapping = { 'RM-51': '3230', 'RM-38': '3250', 'NHM-10': '3600', 'NHM-10X': '3620', 'NHL-8': '3650', 'NHL-8X': '3660', 'RM-25': '6260', 'RM-29': '6260b', 'NHL-10': '6600', 'NHL-12': '6620', 'NHL-12X': '6620', 'RM-1': '6630', 'RH-67': '6670', 'RH-68': '6670b', 'RM-36': '6680', 'RM-57': '6681', 'RM-58': '6682', 'RH-51': '7610', 'RH-52': '7610b', 'NHL-2NA': '7650', 'RM-49': 'E60-1', 'RM-89': 'E61-1', 'RM-10': 'E70-1', 'RM-24': 'E70-?', 'NEM-4': 'N-Gage', 'RH-29': 'N-Gage QD (asia/europe)', 'RH-47': 'N-Gage QD (americas)', 'RM-84': 'N70-1', 'RM-99': 'N70-5', 'RM-67': 'N71-1', 'RM-112': 'N71-5', 'RM-91': 'N80-3', 'RM-92': 'N80-1', 'RM-42': 'N90-1', 'RM-43': 'N91-1', 'RM-158': 'N91-5' } >>> mapping[firmware] '6600' >>>
class WpBlogComment < ActiveRecord::Base # if wordpress tables live in a different database (i.e. 'wordpress') change the following # line to set_table_name "wordpress.wp_comments" # don't forget to give the db user permissions to access the wordpress db set_table_name "wp_comments" set_primary_key "comment_ID" belongs_to :post , :class_name => "WpBlogPost", :foreign_key => "comment_post_ID" validates_presence_of :comment_post_ID, :comment_author, :comment_content, :comment_author_email def validate_on_create if WpBlogPost.find(comment_post_ID).comment_status != 'open' errors.add_to_base('Sorry, comments are closed for this post') end end end
class WpBlogPost < ActiveRecord::Base set_table_name "wp_posts" set_primary_key "ID" has_many :comments, :class_name => "WpBlogComment", :foreign_key => "comment_post_ID" def self.find_by_permalink(year, month, day, title) find(:first, :conditions => ["YEAR(post_date) = ? AND MONTH(post_date) = ? AND DAYOFMONTH(post_date) = ? AND post_name = ?", year.to_i, month.to_i, day.to_i, title]) end end