Skip to content

Instantly share code, notes, and snippets.

@mazuhl
mazuhl / gist:224117
Created November 2, 2009 12:06
Javascript to display images in Reddit thread - convert into a single line and paste into the address bar - I didn't write this, but thought I'd save it here!
var x = $(".content").find("a").each(
function(){
var href = $(this).attr("href");
if((!$(this).hasClass("drowsapMorphed")) && ($(this).next(".drowsapMorphed").length==0) && href && (href.indexOf('imgur')>=0 || href.indexOf('jpeg')>=0 || href.indexOf('jpg')>=0 || href.indexOf('png')>=0)){
var ext = (href.indexOf('imgur')>=0 && href.indexOf('jpg')<0 && href.indexOf('png')<0) ? '.jpg' :'';
var img = $("<a class='drowsapMorphed' href='"+href+"' target='blank' style='display:block'><img style='display:block;max-width:780px;' src='"+href+ ext+"' /></a>");
$(this).after(img);
}
}
);
module Harmony
# Allows accessing config variables from harmony.yml like so:
# Harmony[:domain] => harmonyapp.com
def self.[](key)
unless @config
raw_config = File.read(RAILS_ROOT + "/config/harmony.yml")
@config = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
end
@config[key]
end
@mazuhl
mazuhl / application_controller.rb
Created January 8, 2010 16:19
Putting together a traffic analytics model and controller for a Ruby on Rails app based on this presentation about Scribd http://www.scribd.com/doc/49575/Scaling-Rails-Presentation-From-Scribd-Launch (see slides 17 to 22).
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
before_filter :log_page_view, :except => [:destroy]
private
@mazuhl
mazuhl / iPhone.css
Created January 14, 2010 13:23
Quick and easy way to make a webpage look good on an iPhone
/* Quick and easy way to make a webpage look good on an iPhone */
<style type="text/css" media="only screen and (max-device-width: 480px)">
body { width:90%; padding-right:0;}
h1 { margin-top:25px; }
p { width: 100%; }
</style>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0" />
@mazuhl
mazuhl / lorem.rb
Created February 1, 2010 16:04
Lorem ipsum generator for quick launcher
require 'rubygems'
require 'faker'
require 'Win32API'
require 'win32/clipboard'
include Win32
=begin
= Lorem ipsum clipboard text for Windows
If you're using Windows and a quick launcher (like Launchy) you can use this script
to generate a paragraph of 'Lorem ipsum...' text and automatically copy it to your
@mazuhl
mazuhl / cleanup.rb
Created February 1, 2010 16:10
HTML cleaner for quick launcher - works with Windows clipboard
require 'rubygems'
require 'Win32API'
require 'win32/clipboard'
include Win32
text = Clipboard.data
=begin
= Ruby script to remove crummy HTML
awake: awoke
be: was
bear: bore
beat: beat
become: became
begin: began
bend: bent
beset: beset
bet: bet
bid: bid/bade
accept
add
admire
admit
advise
afford
agree
alert
allow
amuse
@mazuhl
mazuhl / jquery_get_favicons.js
Created February 4, 2010 13:52
jQuery script and accompanying CSS to pull in favicons for URLs
$(document).ready(function(){
jQuery('a.rss-item').filter(function(){
return this.hostname && this.hostname !== location.hostname;
}).each(function() {
var link = jQuery(this);
link.css('backgroundImage', 'url(' + 'http://s2.googleusercontent.com/s2/favicons?domain_url=' + escape('http://' + this.hostname) + ')');
});
});
@mazuhl
mazuhl / gist:294694
Created February 4, 2010 14:50
Embedding a PDF into a webpage
<!-- using <object> (doesn't work in IE) -->
<object height="450" width="600" type="application/pdf" data="/attachment/hello.pdf">
<h2>This content requires a PDF plugin</h2>
<p>View the PDF file here: <a href="/attachment/hello.pdf">hello.pdf</a></p>
</object>
<!-- using an iframe (does work in IE) pass options in the query string -->
<iframe height="900" width="99%" src="/attachment/hello.pdf#toolbar=0&amp;scrollbar=0&amp;navpanes=0"> </iframe>