Skip to content

Instantly share code, notes, and snippets.

#http://blog.wyeworks.com/2009/7/13/paperclip-file-rename
Paperclip.interpolates :default_image_type do |attachment, style|
attachment.instance.get_user_default_profile_image
end
Paperclip.interpolates :normalized_avatar_file_name do |attachment, style|
attachment.instance.normalized_avatar_file_name
end
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
# = Icebox : Caching for HTTParty
#
# Cache responses in HTTParty models [http://github.com/jnunemaker/httparty]
#
# === Usage
#
# class Foo
# include HTTParty
# include HTTParty::Icebox
# cache :store => 'file', :timeout => 600, :location => MY_APP_ROOT.join('tmp', 'cache')
# = Icebox : Caching for HTTParty
#
# Cache responses in HTTParty models [http://github.com/jnunemaker/httparty]
#
# === Usage
#
# class Foo
# include HTTParty
# include HTTParty::Icebox
# cache :store => 'file', :timeout => 600, :location => MY_APP_ROOT.join('tmp', 'cache')

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
require 'rubygems'
require 'httparty'
require 'benchmark'
require 'thread'
class Google
include HTTParty
base_uri 'http://google.com'
def self.benchmark
/* Pre-Define HTML5 Elements in IE */
(function(){ var els = "source|address|article|aside|audio|canvas|command|datalist|details|dialog|figure|figcaption|footer|header|hgroup|keygen|mark|meter|menu|nav|picture|progress|ruby|section|time|video".split('|'); for(var i = 0; i < els.length; i++) { document.createElement(els[i]); } } )();
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */
window.matchMedia || (window.matchMedia = function() {
"use strict";
// For browsers that support matchMedium api such as IE 9 and webkit
var styleMedia = (window.styleMedia || window.media);
// For those that don't support matchMedium
if (!styleMedia) {
var style = document.createElement('style'),
<script type="text/javascript" src='http://code.jquery.com/jquery-2.1.3.min.js'></script>
<audio id="myAudio" src="http://sqr.bartekdrozdz.com/demo/soundviz/assets/spy.mp3" controls><p>Your browser does not support the audio element.</p></audio>
<!-- <audio id="myAudio" src="./a-little-something.mp3" controls><p>Your browser does not support the audio element.</p></audio> -->
<div id="visualization" style="width:100%; height:500px"></div>
<script type="text/javascript">
Number.prototype.map = function ( in_min , in_max , out_min , out_max ) {
return ( this - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min;
}
# Basic Code
class Image
has_attached_file :attachment
def attachment_url(url)
require "open-uri"
self.attachment = open(url)
end
end