Skip to content

Instantly share code, notes, and snippets.

View bradgessler's full-sized avatar

Brad Gessler bradgessler

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Navigator.plugins</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
class Sub
def name_please
self.class.name
end
end
class Super < Sub
end
super_man = Super.new
arr = [{:a => 1}, {:a => 2}, {:a => 3}, {:a => 4}, {:b => 3}, {:b => 4}, {:a => 5}]
# I want to get ...
#
# [
# {:a => [1,2,3,4]},
# {:b=> [3,4]},
# {:a => [5]}
# ]
<html>
<head>
<link rel="alternate" type="application/json+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DGvxCi06sc2I&format=json" title="Dancing Girls! (10-16-09 Vlog #5)" />
<link rel="alternate" type="text/xml+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DGvxCi06sc2I&format=xml" title="Dancing Girls! (10-16-09 Vlog #5)" />
[...]
</head>
<body>
[...]
</body>
</html>
/* Polls the server for new JSON data at a defined interval. Requests are garunteed to not stack up on each other.
Example Usage:
var poller = $.poller({
url: function(head){
var base = '/messages/';
return (head) ? (base + '?since_id=' + head.result.id) : base;
},
receive: function(set){
# A hacky way to put files in Capistrano with sudoer permissions
def sudo_put(data, target)
tmp = "#{shared_path}/~tmp-#{rand(9999999)}"
put data, tmp
on_rollback { run "rm #{tmp}" }
sudo "cp -f #{tmp} #{target} && rm #{tmp}"
end
ActiveRecord::Base.connection.execute %{
UPDATE memberships, accounts
SET memberships.is_owner = true
WHERE memberships.user_id = accounts.owner_id AND memberships.is_user = true
}
%{Hey I'm a string}
%(Hey I'm another string)
%[Hey its me, yep... another string!]
ActiveRecord::Base.connection.execute <<-SQL
UPDATE memberships, accounts
SET memberships.is_owner = true
WHERE memberships.user_id = accounts.owner_id AND memberships.is_user = true
SQL
# Creates an array out of the words in a string
>> %w[one two three]
=> ["one", "two", "three"]
# Executes a system command and captures the output as a string
>> %x[ls]
=> "Applications\nDesktop\nDocuments\nDownloads\nDropbox\nLibrary\nMovies\nMusic\nPictures\nProjects\nPublic\nSites\nVirtual Machines\npe\n"
# Creates a regexp object
>> %r{(\w+)\.html}