Skip to content

Instantly share code, notes, and snippets.

@mazuhl
mazuhl / gist:9366311
Last active August 29, 2015 13:57
Javascript - modified scoping example from p. 36 of Javascript: The Good Parts
var foo = function() {
var a = 3, b = 5;
console.log("a: " + a + ", b: " + b);
if (typeof c === "undefined") { console.log("c is undefined"); }
console.log("---");
var bar = function() {
var b = 7, c = 11;
@mazuhl
mazuhl / check-url-status.rb
Created May 12, 2014 07:59
Check URL status from input file list
File.foreach('URLS.txt') { |l|
system("curl -sL -w '%{http_code} %{url_effective}\\n' '#{l.chomp}' -o /dev/null")
}
@mazuhl
mazuhl / Code.gs
Last active August 29, 2015 14:02
Get MODx version number from GitHub Master branch and paste into Google Spreadsheet
function myFunction() {
var response = UrlFetchApp.fetch("http://www.example.com/get-modx-latest-version.php");
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(response.getContentText());
}
@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