%e # rather than %d
Time.now.strftime("%e")
Archive for the ‘ruby’ Category
Ruby Strftime Day Without the Leading Zero
Category ruby
Hello Rack
What is Rack?
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
- Rack API Docs
Create and name your file config.ru If rack isn’t installed get it with this command
gem install rack
In your config.ru file
require 'rubygems'
require 'rack'
class HelloRack
def call(env)
[200, {"Content-Type" => "text/html"}, "Hello Rack!"]
end
end
Rack::Handler::Mongrel.run HelloRack.new,
ort => 8888
Reading, Writing, Removing Files and Directories in Ruby
Category ruby
These aren’t all of them, but I think they are some of the most useful.
# making a directory in another directory that doesn't yet exist...
FileUtils.mkdir_p '/path/to/your/directory/that/doesnt/exist/yet'
# recursively remove a directory and the contents
FileUtils.rm_rf("/path/to/directory/you/want/to/delete")
# write a file from the contents of another file...
File.open("/path/to/the/file.ext", "wb") {|f| f.write(@your_other_file.read)}
How to Install a Ruby Package without Ri or RDoc
Category ruby
gem install --no-rdoc --no-ri rails