Skip to content

Instantly share code, notes, and snippets.

Generated at Tue Nov 22 16:56:46 -0500 2011
OpenSSL::PKey::RSAError: private key needed.: no start line
/usr/lib/ruby/1.8/mixlib/authentication/signedheaderauth.rb:56:in `private_encrypt'
/usr/lib/ruby/1.8/mixlib/authentication/signedheaderauth.rb:56:in `sign'
/usr/lib/ruby/vendor_ruby/chef/rest/auth_credentials.rb:51:in `signature_headers'
/usr/lib/ruby/vendor_ruby/chef/rest.rb:321:in `authentication_headers'
/usr/lib/ruby/vendor_ruby/chef/rest.rb:366:in `build_headers'
/usr/lib/ruby/vendor_ruby/chef/rest.rb:216:in `api_request'
/usr/lib/ruby/vendor_ruby/chef/rest.rb:125:in `post_rest'
/usr/lib/ruby/vendor_ruby/chef/api_client.rb:243:in `save'
@avit
avit / SchedulableListener.php
Created February 8, 2012 23:58
How to get Event Adapter from a repository?
class SchedulableListener extends MappedEventSubscriber
{
// ...
public function getRecurrenceRuleClass(SchedulableAdapter $ea, $class)
{
return isset($this->configurations['schedulable']['recurrenceRuleClass']) ?
$this->configurations['schedulable']['recurrenceRuleClass'] :
$ea->getDefaultRecurrenceRuleClass();
}
@avit
avit / polymorphic.sql
Created February 14, 2012 22:13
Polymorphic associations in SQL
-- How to map this in Doctrine to have "commentable" entities (subclasses of Commentable)
-- associated to many comments?
-- These 2 tables are both "commentable"
CREATE TABLE IF NOT EXISTS `posts` (
`id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255)
`body` TEXT
@avit
avit / gist:1855725
Created February 17, 2012 22:10 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1855725)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@avit
avit / inject_callables.rb
Created February 21, 2012 06:48
Playing with duck-typed callables
module Import
module Translation
@translators = {}
def self.register(name, callable)
if callable.respond_to?(:call)
@translators[name.to_sym] = callable
else
raise Exception("Registered translators must be callable")
@avit
avit / ftp.rb
Created February 24, 2012 20:18
def fetch_data
Net::FTP.open(host, username, password) do |ftp|
begin
ftp.binary = binary
if file_name.is_a?(Regexp)
files = ftp.nlst.select { |i| i =~ file_name }
matching_file = files.pop
end
if file_newer && (@data_time = ftp.mtime(matching_file)) > file_newer
@data = ftp.get(matching_file)
@avit
avit / Cheffile
Created June 7, 2012 01:00
librarian-chef
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'application_nginx'
cookbook 'application_ruby'
cookbook 'apt'
cookbook 'git'
cookbook 'imagemagick'
@avit
avit / posts_controller.rb
Created June 12, 2012 19:46
Testing page caching
class PostsController < ApplicationController
caches_page :index
def index
render text: "html!"
end
end
@avit
avit / articles_controller.rb
Created June 18, 2012 23:17
Showing errors for a form partial
class ArticlesController < ActionController::Base
def show
@article = Article.find(params[:id])
# ... bunch of stuff to set up template display
end
end
@avit
avit / regexp.rb
Created June 22, 2012 21:47
Ruby Regexp match named capture
# Regex with two named captures both named "word"
r = %r{
(?<word>[a-z]+)\s+
(?<word>[a-z]+)
}xi
m = r.match("one two")
# => #<MatchData "one two" word:"one" word:"two">
m.captures