Skip to content

Instantly share code, notes, and snippets.

Brad Gessler bradgessler

Block or report user

Report or block bradgessler

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:12027
<?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">
View gist:32547
class Sub
def name_please
self.class.name
end
end
class Super < Sub
end
super_man = Super.new
View Enumerable#segment
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]}
# ]
View OEmbed Discovery
<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>
View jquery.poller.js
/* 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){
View sudo_put.rb
# 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
View multiline.rb
ActiveRecord::Base.connection.execute %{
UPDATE memberships, accounts
SET memberships.is_owner = true
WHERE memberships.user_id = accounts.owner_id AND memberships.is_user = true
}
View string.rb
%{Hey I'm a string}
%(Hey I'm another string)
%[Hey its me, yep... another string!]
View heredoc.rb
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
View strings.rb
# 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}
You can’t perform that action at this time.