Skip to content

Instantly share code, notes, and snippets.

@kfatehi
kfatehi / nzb_import.rb
Created May 30, 2011 02:39
nn import script
#!/usr/bin/env ruby
=begin
Created by keyvan
#newznab on irc.synirc.net
This script is for importing a giant dump of NZB files into newznab. Be warned, it's HACKY!
1) I expect you have downloaded a big archive full of nzbs and have extracted it.
The directory structure should be like this:
dump/
MoviesHD/
@kfatehi
kfatehi / gsyncd.rb
Created July 8, 2011 02:24
Gist Sync Daemon
#!/usr/bin/env ruby
# I didn't know gists were not editable by multiple people when i first wrote this... oh well.
class GistFile
def initialize(filename, gist_id)
@filename = filename
@file = File.new(filename)
@gist_id = gist_id
end
- (NSArray *) NSArrayOfNSDictionariesOfSize:(int)size {
NSMutableArray *returnedArray = blah bla bla
for(int i=size;i<size;i++)
create a dictionary, stuff it in the returnedArray at position i
return returnedArray;
}
module UserAbilities
def can?(verb, target)
Ability[verb].call(self, verb, target)
end
Ability = {
:use=>lambda { |user, verb, target|
# This depends primarily on what the target is.
Target[target.class.to_s].call(user, verb, target)
}
@kfatehi
kfatehi / HstoreModel.rb
Created April 29, 2012 21:22
Hstore ActiveRecord::Base method_missing
## Hstore Method Missing Extension
module HstoreModel
def method_missing(method, *args, &block)
if !self.class.attribute_methods_generated?
self.class.define_attribute_methods
if respond_to_without_attributes?(method)
send(method, *args, &block)
else
super
end
@kfatehi
kfatehi / Guardfile
Created June 27, 2012 22:03
example guardfile
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
class PolymorphicThing
# I am trying to prevent duplicate records as such.
validates :user_id, :uniqueness => {:scope => [:verb, :resource_type, :resource_id]}
end
# It works but there must be a better way to prevent dupes?
# The fields referenced are the only columns on this table
/Users/keyvan/Projects/Hokkaido/lib/motion_mock.rb:11:in `require': cannot load such file -- /Users/keyvan/Code/cucumber/lib/Users/keyvan/Code/cucumber/lib/cucumber.rb (LoadError)
from /Users/keyvan/Projects/Hokkaido/lib/motion_mock.rb:11:in `<<'
from /Users/keyvan/Code/cucumber/lib/cucumber.rb:33:in `block in <main>'
from /Users/keyvan/Projects/Hokkaido/lib/motion_mock.rb:15:in `call'
from /Users/keyvan/Projects/Hokkaido/lib/motion_mock.rb:15:in `setup'
from /Users/keyvan/Code/cucumber/lib/cucumber.rb:30:in `<main>'
The #require removal was not a success.
def write_manifest
correct_load_order_array = []
load_last = []
@require_libs_hash.each do |root_file, nested_requires|
# Fix path for root files (needed since we derive from path and not a #require line)
load_last << root_file.gsub(lib_folder+File::SEPARATOR, '')
correct_load_order_array << nested_requires.reverse.flatten
end
[12] pry(#<Hokkaido::GemModifier>)> @require_libs_hash
=> {"/Users/keyvan/Code/cucumber/lib/cucumber.rb"=>
["cucumber/broadcaster", "cucumber/step_definitions"],
"/Users/keyvan/Code/cucumber/lib/cucumber/platform.rb"=>[],
"/Users/keyvan/Code/cucumber/lib/cucumber/parser.rb"=>["cucumber/ast"],
"/Users/keyvan/Code/cucumber/lib/cucumber/ast.rb"=>
["cucumber/ast/comment",
"cucumber/ast/features",
"cucumber/ast/feature",
"cucumber/ast/background",