Posted by Dan Sosedoff
on January 25, 2011
Need to figure out closed/private API? Not a problem. Its always fun and challenging. There are few tools i use for that:
Proxie is another project of mine, which i finally extracted from a script written a while ago and published it as a ruby gem.
I used it to track Grooveshark API and it worked out great. Here is the list of features:
- Bind proxy server to any port (default is 8080)
- Define output database. It uses SQLite3 by default, but you can extend it with any other types
- Sinatra-base web interface to browse all your collected data
Installation:
Start a server:
After data collection just run:
The web interface runs on localhost:4567 by default.
Usage summary:
Usage: proxie [options]
-i, --info Display this information.
-p, --port PORT Listen on port (8080 default)
-d, --db NAME Store results to database
-w, --web Start a Web UI for databases
-f, --flush Delete all local databases
Project on GitHub: http://github.com/sosedoff/proxie
Posted by Dan Sosedoff
on September 17, 2010
What do you know about rapid development?
I guess something. Almost every developer experienced moments when you or someone have really interesting idea and wanted to jump on it right away. One of the obstacles – tools you use to achieve it. And the web framework is the first of them. Why? Because if you want to create something cool without being stuck on technology level you should use things that you dont really notice while making your app. Of course it varies from person-to-person, but just imagine yourself in traffic jam driving stick-shift car, switching gears like crazy all the time.
Back to webdev, with my experience i can only say that the best tool for rapid development is Sinatra. Its so small and powerful that i got hooked on it since first day i found it. Almost all my personal/work projects on early stages have been developed with Sinatra. Another big plus – small and usefull extensions, big players like AR or DataMapper. It was extracted from Merb project, another small and powerful web framework i like to work with. Its like a one-file web application. Perfect for super-fast development. Wanna do simple music downloads page? No problem. API – again, no problem. Deployment is simple and similar to most of frameworks, as it built on top of Rack: thin, passenger (nginx/apache).
What do you know about rapid development?
I say – i love it.
Posted by Dan Sosedoff
on June 18, 2010
Made a simple gem for website sitemap generation. Could be used in any Ruby/Rails/Merb/Sinatra application. It does not have any caching in that case if you want to use framework built-in cache methods.
Installation:
$ sudo gem install xml-sitemap
Example
pages = Page.all(:order => [:updated_at.desc] # DM model
map = XmlSitemap::Map.new('somedomain.com') do |m|
m.add(:url => '/', :period => :daily, :priority => 1.0)
m.add(:url => '/contractors', :period => :daily, :priority => 1.0)
pages.each do |p|
m.add(
:url => url_for_page(p),
:updated => p.updated_at,
:priority => 0.5,
:period => :never
)
end
end
# render the sitemap
puts map.render
Sinatra Example
# ... your code
get '/sitemap.xml' do
map = XmlSitemap::Map.new('domain.com') do |m|
m.add(:url => '/')
m.add(:url => '/posts', :period => :weekly)
end
headers['Content-Type'] = 'text/xml'
map.render
end
# ... more code
Options
:url – page path, relative to domain (ex.: /test), String.
:period – freqchange attribute, Symbol, :none, :never, :always, :hourly, :daily, :weekly, :monthly, :yearly
:priority – priority attribute, Float class,(0.0..1.0)
:updated – (optional) last_update attribute, Time class
Source Code
http://github.com/sosedoff/xml-sitemap
Posted by Dan Sosedoff
on May 03, 2010
Once you need to test mailers within your Sinara, Rails or Merb application you wish to see a real output. No need to setup delivery via SMTP. Just create an executable ruby script somewhere, for example: /usr/bin/fake-sendmail.sh with following content:
$ touch /usr/bin/fake-sendmail.sh
$ chmod +x /usr/bin/fake-sendmail.sh # make it executable (will require root priv.)
#!/usr/bin/ruby
path = "/tmp/fake-mailer"
Dir.mkdir(path) if !File.exists?(path)
File.open("#{path}/#{Time.now.to_i}.txt", "w") do |f|
f.puts ARGV.inspect
$stdin.each_line { |line| f.puts line }
end
And then configure your mailing system:
1. Sinatra
There is a plugin for Sinatra (ported from Merb, http://github.com/foca/sinatra-mailer),
Sinatra::Mailer.config = {:sendmail_path => "/usr/bin/fake-sendmail.sh"}
Sinatra::Mailer.delivery_method = :sendmail
2. Merb
Edit your development configuration file (config/environments/development.rb)
Merb::BootLoader.after_app_loads do
Merb::Mailer.delivery_method = :sendmail
Merb::Mailer.config = { :sendmail_path => '/usr/bin/fake-sendmail.sh' }
end
3. Rails.
Edit your development environment file with following options:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {:location => "/usr/bin/fake-sendmail.sh"}
Posted by Dan Sosedoff
on July 04, 2009
Developing with Merb or Sinatra ? Like web server nginx ? Ok, lets go.
Basically, Merb/Sinatra uses thin (based on eventmachine) server module, so it is working as stand-alone application. So, there is a way to connect nginx with these applications. Very simple – all you need to proxy requests to backend server. And all static files will be served by nginx.
upstream your_app {
server 127.0.0.1:YOUR_PORT_NUMBER;
}
server {
server_name YOUR_SERVERNAME;
listen 80;
charset utf-8;
client_max_body_size 64M; # maximum of proxied filesize (for uploads)
location / {
root /path/to/app/root;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
proxy_pass http://your_app;
break;
}
}
# static content (images, flash, styles, etc.)
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ {
root /path/to/your/public/dir;
access_log off;
}
}
Then, all you need – start your application in daemon mode. Dont forget to bind application server to listen only on local address (127.0.0.1).