Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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();
}
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 / pwd.rb
Created November 9, 2011 08:19
Is there any way to get the pwd as the symlink directory I'm working in?
puts Dir.pwd
resize
COLUMNS=181;
LINES=63;
export COLUMNS LINES;
%
diff --cc cookbooks/mysql/metadata.json
index 9010798,b3ab7ec..0000000
--- a/cookbooks/mysql/metadata.json
+++ b/cookbooks/mysql/metadata.json
@avit
avit / gist:1300452
Created October 20, 2011 04:57
Vagrant error on new veewee box with user "deploy"
Feature: vagrant box validation
As a valid vagrant box
I need to comply to a set of rules
Scenario: Checking login # /Users/andrew/.rvm/gems/ruby-1.9.2-p180@ops/gems/veewee-0.2.0/lib/veewee/../../validation/vagrant.feature:5
.. When I ssh to "127.0.0.1" with the following credentials: # veewee-0.2.0/validation/features/steps/ssh_steps.rb:56
| username | password | port |
| vagrant | vagrant | 7222 |
expected no Exception, got #<Net::SSH::AuthenticationFailed: vagrant> (RSpec::Expectations::ExpectationNotMetError)
And I run "whoami" # veewee-0.2.0/validation/features/steps/ssh_steps.rb:98