Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
@henrik
henrik / infix_search_named_scope.rb
Created September 2, 2009 20:58
Simple MySQL "LIKE"-based infix search in Rails. Case and accent insensitive.
class Foo < ActiveRecord::Base
named_scope :infix_search, lambda { |string|
if string.blank?
{}
else
tokens = string.chars.downcase.split.uniq.first(10) # Avoid too heavy queries.
fields = %w[
foo.bar foo.baz
oink.boink
@henrik
henrik / builder_default_cdata.rb
Created September 7, 2009 20:41
Make Ruby's Builder default XML data to CDATA and not bork numbers.
# Make Builder default to CDATA and not bork numbers.
# By Henrik Nyh <http://henrik.nyh.se> 2009-08-07 under the MIT license.
require "rubygems"
require "builder"
xml_1 = Builder::XmlMarkup.new
xml_2 = Builder::XmlMarkup.new
# Override Builder so CDATA is used by default to escape text, and with no whitespace
// Make jQuery UI tabs pick the selected tab from the URL hash,
// and set the selected tab id as the hash.
//
// By Henrik Nyh <http://henrik.nyh.se> 2009-09-10 under the MIT License.
// Based on code by Mark Yoon: http://articles.rootsmith.ca/mod_python/how-to-make-jquery-ui-tabs-linkable-or-bookmarkable#comment-10188
$('#foo').tabs();
$('.tabs').each(function() {
@henrik
henrik / commit-msg
Created September 10, 2009 18:25
Git commit-msg hook that automatically adds "Refs #123" when in the branch t123, "[#123]" when in the branch s123 etc.
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "t123", automatically
# adds "Refs #123." to commit messages unless they mention "#123" already.
# Include "#close" or "#finish" to add "Closes #123."
#
# For Pivotal Tracker, branch names like "s123" adds "[#123]".
# Include "#close" or "#finish" to add "[Finishes #123]".
#
# If you include "#noref" in the commit message, nothing will be added to
@henrik
henrik / jquery.tablednd_0_5.js.undraggable-fix.diff
Created September 15, 2009 19:39
Fix issue where adding "nodrag" and running tableDnDUpdate() would not make once-draggable rows undraggable.
diff --git a/public/javascripts/jquery.tablednd_0_5.js b/public/javascripts/jquery.tablednd_0_5.js
index d4c9fec..e391a62 100644
--- a/public/javascripts/jquery.tablednd_0_5.js
+++ b/public/javascripts/jquery.tablednd_0_5.js
@@ -144,7 +144,7 @@ jQuery.tableDnD = {
// Iterate through each row, the row is bound to "this"
var row = jQuery(this);
if (! row.hasClass("nodrag")) {
- row.mousedown(function(ev) {
+ row.bind('mousedown.tableDnD', function(ev) {
@henrik
henrik / prawn_stroke_dashed_horizontal_line.rb
Created October 8, 2009 08:07
Basic stroke_dashed_horizontal_line to draw dashed lines/dotted lines in Prawn.
module Prawn::Graphics
# E.g. stroke_dashed_horizontal_line(0, 5.cm, :at => 10.cm, :line_length => 1.cm, :space_length => 1.mm)
# Currently rounds up line/space periods: 1 cm line length + 1 mm space as a 3 cm line would be "- - -", 3.2 cm total.
def stroke_dashed_horizontal_line(x1,x2,options={})
options = options.dup
line_length = options.delete(:line_length) || 0.5.mm
space_length = options.delete(:space_length) || line_length
period_length = line_length + space_length
total_length = x2 - x1
# Workaround to get "Page 1 of 2". Based on
# http://groups.google.com/group/prawn-ruby/msg/f08f8b0da9db6eb6
class Prawn::Document
# Fixed in post-processing so only use as a replacable string.
def total_page_count
"#PP#"
end
alias_method :render_without_total_pages, :render
@henrik
henrik / Deploy.tmCommand
Created October 21, 2009 07:55
TextMate command to deploy a Jekyll site through a tasks/deploy shell script.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>C9BD1ADE-4FD9-4842-A641-DFB373B7D42C</string>
<key>command</key>
<string>#!/usr/bin/env ruby
@henrik
henrik / advancedsettings.xml
Created November 4, 2009 21:34
Plex advancedsettings.xml for "S01xE02" TV shows.
<?xml version="1.0"?>
<!--
Edit ~/Library/Application Support/Plex/userdata/advancedsettings.xml
See http://xbmc.org/wiki/?title=AdvancedSettings.xml#.3Ctvshowmatching.3E
and http://wiki.plexapp.com/index.php/Changing_TV_Show_Naming_Conventions
-->
<advancedsettings>
<tvshowmatching action="append">
<regexp>[\._ \-][Ss]([0-9]+)[\.\-xX]?[Ee]([0-9]+)([^\\/]*)</regexp> <!-- allow S01xE02, e.g. "Deadwood - S01E01 - Deadwood" -->
</tvshowmatching>