Skip to content

Instantly share code, notes, and snippets.

@Sam-Serpoosh
Sam-Serpoosh / web_based_file_explorer.rb
Created October 25, 2012 22:24
Simple webserver which let you explore your files and directories of your system in a browser!
require 'socket'
HTTP_HEADER = "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
CURRENT_DIR = "."
SPACE_IN_PARAM = "%20"
def file_explorer
webserver = TCPServer.new("localhost", 2000)
loop do
Thread.start(webserver.accept) do |session|
@Sam-Serpoosh
Sam-Serpoosh / some_domain_logic_spec.rb
Created July 27, 2012 22:44
This is a little helper method which take the path of a file relative to rails root directory and "require" that file in the test. Comes handy for the isolated tests in a rails project. Interestingly enough, I wrote this via TDD too!
#you can use this easily like the following in your spec files:
reuqire_relative "../spec_helper_lite"
reuqire_relative_to_root "lib/some_domain_logic"
describe "some domain logic" do
#specs will be here then
end
@Sam-Serpoosh
Sam-Serpoosh / current_version_sign_in_out_spec.rb
Created July 17, 2012 21:10
a simple sign_in & sign_out machinery for an app I'm currently working on. I try to follow good OO design & separation of concerns, etc. & extract domain objects as much as possible & have fast-isolated tests. But can't stub simple methods of a module in
module SessionsHelper
include SignInOut
def create_cookie(user_id, user_salt); end
def remember_token; end
def delete_cookie; end
end
@Sam-Serpoosh
Sam-Serpoosh / Gemfile
Created June 4, 2012 16:14
error in blog sample app in @avdi's Objects on Rails with nulldb setup!!!
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.1'
end
group :test do
@Sam-Serpoosh
Sam-Serpoosh / spec_helper_lite.rb
Created June 1, 2012 10:51
a handy method for requiring all ruby files in a folder which is in rails app folder (like controllers, views, helpers, etc.) really useful in rails specs (for me at least). it can be in a spec_helper_lite file in spec folder.
def require_folder(folder_name_in_app)
Dir[File.expand_path(File.dirname(__FILE__) + "/../app/" + folder_name_in_app + "/*.rb"].each { |file| require file }
end