Skip to content

Instantly share code, notes, and snippets.

View thbar's full-sized avatar

Thibaut Barrère thbar

View GitHub Profile
today = Date.today.strftime("%Y-%m-%d")
yesterday = (Date.today - 1).strftime("%Y-%m-%d")
cmd = "svn log -r {#{yesterday}}:{#{today}}"
puts cmd
raise "Error!" unless system(cmd)
@thbar
thbar / gist:55108
Created January 30, 2009 15:28
better ts:index ?
Index: thinking-sphinx/tasks/thinking_sphinx_tasks.rb
===================================================================
--- thinking-sphinx/tasks/thinking_sphinx_tasks.rb (revision 809)
+++ thinking-sphinx/tasks/thinking_sphinx_tasks.rb (revision 881)
@@ -59,12 +59,12 @@
puts "Generating Configuration to #{config.config_file}"
config.build
end
-
+
@thbar
thbar / gist:56865
Created February 2, 2009 10:21
TinyTL and ThinkingSphinx
preprocess {
Item.delete_all
}
source(:csv_file) {
FasterCSV.open(get_var(:source_file),"rb", :col_sep => ';', :headers => true)
}
each_row { |row|
Item.create!(row[:data].to_hash) # if (@counter = (@counter || 0) + 1) < 200
preprocess {
# mark the current data for deletion - do not delete right away
# to avoid ending up with no data on the web-site
Item.update_all('marked_for_deletion = 1')
}
source(:csv_file) {
FasterCSV.open(get_var(:source_file),"rb", :col_sep => ';', :headers => true)
}
When calling rake ts:index or rake ts:start, if the command is not successful, you'll get something like:
=======================================
The following command failed!
indexer --config /Users/login/Work/my_app/trunk/my_app/config/development.sphinx.conf --all
This may be caused by a PATH issue in your environment (cron/passenger/... ?). Here is the current PATH:
/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin
<VirtualHost <%= public_ip %>:80>
ServerName <%= server_name %>
# server aliases (generated from config)
<% ((server_aliases.keys + server_aliases.values).flatten - [server_name]).each do |server_alias| %>
ServerAlias <%= server_alias %><% end %>
DocumentRoot <%= public_path %>
<Directory "<%= public_path %>/">
/* the helper, built as a Control extension method */
public delegate void Action();
public static void InUIThread(this Control control, Action action) {
if (control.InvokeRequired)
control.EndInvoke(control.BeginInvoke(action));
else
action();
}
@thbar
thbar / InWorkerThread.cs
Created March 19, 2009 09:09
Windows Forms C# sugar
public static void InWorkerThread(this Control control, Action action) {
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (sender, e) => action();
worker.RunWorkerAsync();
while (worker.IsBusy)
System.Windows.Forms.Application.DoEvents();
}
module Ramaze
module Helper
module WillPaginateForRamaze
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include WillPaginate::ViewHelpers
def url_for(args)
url = case args
when Hash;
# patch to handle connection pooling outside of rails: http://www.williambharding.com/blog/rants/rails-22-connection-pools-mongrel-handlers-bloodbath/
# call ActiveRecord::Base.connection_handler.clear_connection! from your controller once you're done with ActiveRecord work
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def release_connection(conn_id = nil)
conn_id ||= current_connection_id
conn = @reserved_connections.delete(conn_id)
checkin conn if conn
end