Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env macruby
# % gdb macruby ns_url_protocol_test.rb
#
# (gdb) run ns_url_protocol_test.rb http://www.google.com/
# Starting program: /usr/local/bin/macruby ns_url_protocol_test.rb http://www.google.com/
#
# received 4900 bytes
#
# Program exited normally.
token Op {'/' || '*' || '+' || '-'};
token Value { \d+[\.\d+]? };
token Item { <Value> || <Op> };
token Expr { [<ws> <Item> <ws>]+ };
sub do_op($lhs, $rhs, $op) {
given $op {
when '*' { $lhs * $rhs }
when '+' { $lhs + $rhs }
when '-' { $lhs - $rhs }
@sstephenson
sstephenson / gist:134653
Created June 23, 2009 16:26
preserving_scroll_position.js
Element.addMethods({
preservingScrollPosition: function(element, callback) {
element = $(element);
var offset = element.cumulativeOffset().top - document.viewport.getScrollOffsets().top;
callback();
window.scrollTo(0, element.cumulativeOffset().top - offset);
return element;
}
});
(function() {
var focusInHandler = function(e) { e.findElement().fire("focus:in") };
var focusOutHandler = function(e) { e.findElement().fire("focus:out") };
if (document.addEventListener) {
document.observe("focus", focusInHandler, true);
document.observe("blur", focusOutHandler, true);
} else {
document.observe("focusin", focusInHandler);
document.observe("focusout", focusOutHandler);
// In most browsers, a <label> tag around a form field, e.g.:
//
// <label>
// <input type="checkbox" id="private" name="private">
// This message is private
// </label>
//
// works just as if you'd specified a for= attribute on the label
// for the first visible field inside the label. In Safari 4, this
// seems not to be the case (i.e. the for= attribute is required).
[RAILS_ROOT]/app/models/projects/comment.rb:146:in `ping_commentable'
[RAILS_ROOT]/app/models/projects/history.rb:13:in `ignore'
[RAILS_ROOT]/app/models/projects/comment.rb:146:in `ping_commentable'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
# Pipe Ars Technica's live Apple event coverage into a Campfire room.
# http://arstechnica.com/apple/news/2010/01/tablet-live-event-liveblog.ars
#
# Usage:
# $ gem install -r hpricot tinder
# $ ruby -rubygems ars_live.rb -ssl mysubdomain myroomid myapikey
require "hpricot"
require "open-uri"
require "tinder"
(function() {
var queue = [];
function checkQueue() {
if (queue.any())
queue.pop().fire("dom:modified");
}
var notify;
function deferFire(element) {
if (!queue.include(element))
#!/usr/bin/env zsh
function resolve_symlink() {
local result=`readlink $1`
[ -z $result ] && echo $1 || $0 $result
}
function expand_path() {
cd -qP $1
pwd
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell