Skip to content

Instantly share code, notes, and snippets.

View bradgessler's full-sized avatar

Brad Gessler bradgessler

View GitHub Profile
@bradgessler
bradgessler / license.rb
Created July 2, 2014 06:07
Print a list of licenses for gems in a bundle.
require 'bundler'
require 'yaml'
def format(hash)
Hash[hash.keys.map(&:to_s).zip(hash.values)].to_yaml
end
Bundler.load.specs.each do |spec|
puts format({
name: spec.name,
module PunditExampleGroup
extend ::RSpec::Matchers::DSL
matcher :permit do |action|
match do |policy|
policy.public_send("#{action}?")
end
failure_message do |policy|
"#{policy.class} does not permit #{action} on #{policy.record} for #{policy.user.inspect}."
@bradgessler
bradgessler / bundle
Created March 18, 2015 04:23
Fast bundler
#!/usr/bin/env bash
export IMAGE_NAME=my_app
CONTAINER_ID=$(docker run -d $IMAGE_NAME bundle $@)
docker logs -f $CONTAINER_ID
docker commit $CONTAINER_ID $IMAGE_NAME
<?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]}
# ]
/* 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!]