Archive for the ‘Uncategorized’ Category
dfs in ruby :)
I wrote simple dfs in ruby:
def dfs(node, value, queue) return false if node.nil? return true if node.data == value queue.push node.right unless node.right.nil? queue.push node.left unless node.left.nil? dfs(queue.pop, value, queue) end
for node:
class Node attr_accessor :left, :right, :data end
Academia vs. Business

Gemcutter & Jeweler
More about gemcutter & jeweler can be found here.
Here are the steps how to publish patched gem cloned from github:
1. Append username to gem name in .gemspec or if you use jeweler open Rakefile and edit Jeweler::Tasks section save it and run:
rake gemspec
2. Build gem with:
gem build
3. Push new gem to gemcutter
gem push
BDD with Cucumber by Ben Mabey
auto escaping html in Rails to protect from XSS
Tonight I found a plugin to auto escape html in order to protect from XSS attacks. I’m not sure why rails doesn’t do it out of the box (you have to use h() helper). Anyway the plugin is called xss_terminate and it can be found here. The cool thing about it is that now you can forget about h()
.
Cron in Ruby
key-value store

daemon_controller + Thinking Sphinx
I’ve created simple rails initiator in order to start Sphinx through daemon_controller based on the Thinking Sphinx configuration. I hope it will help somebody.
require 'daemon_controller' def before_start if not ThinkingSphinx.define_indexes? config = ThinkingSphinx::Configuration.instance cmd = "#{config.bin_path}#{config.indexer_binary_name} --config \"#{config.config_file}\" --all" cmd << " --rotate" if ThinkingSphinx.sphinx_running? system cmd end end if defined?(ThinkingSphinx) if not ThinkingSphinx.sphinx_running? conf_instance = ThinkingSphinx::Configuration.instance @controller = DaemonController.new( :identifier => 'Sphinx search server', :start_command => "#{conf_instance.bin_path}#{conf_instance.searchd_binary_name} --pidfile --config \"#{conf_instance.config_file}\"", :before_start => method(:before_start), :ping_command => lambda { TCPSocket.new(conf_instance.configuration.searchd.address, conf_instance.configuration.searchd.port) }, :pid_file => conf_instance.configuration.searchd.pid_file, :log_file => conf_instance.configuration.searchd.log) @controller.start end end
The Rails Initialization Process
I found really nice description of rails initialization process here.
capistrano recipes for ubuntu
Few nice capistrano recipes which may help you automate Ubuntu Server setup: