This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
original = 'ThisIsAStringInCamelCaseWithNumbersLike12And14' | |
# Convert a CamelCase string to snake_case | |
snake_case = original.gsub(/([\w^_](?=[A-Z]))|([a-z](?=\d+))/, '\1\2_').downcase | |
# Convert a snake_case string to CamelCase | |
camel_case = snake_case.gsub(/^\w|_\w/) { |match| match[-1,1].upcase } | |
puts snake_case # => "this_is_a_string_in_camel_case_with_numbers_like_12_and_14" | |
puts camel_case # => "ThisIsAStringInCamelCaseWithNumbersLike12And14" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
# This TextMate command takes an HTML IMG element and re-calculates its size. | |
# The currently selected image will then get the original dimensions. | |
# This is useful when you have changed an image and need to reset its dimensions | |
# in your HTML. | |
# | |
# This should work on the selected text or current line and replace the current | |
# selection. Scope: text.html. Assign a nice keyboard shortcut of your choosing. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let Ruby ping pingomatic.com | |
require 'xmlrpc/client' | |
XMLRPC::Client.new('rpc.pingomatic.com', '/').call('weblogUpdates.extendedPing', SITE_NAME, SITE_URL, FEED_URL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img\s+((alt|border|class|id|src|usemap|hspace|vspace)="[^"]+"\s*)+> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pattern = /<img\s+((alt|border|class|id|src|usemap|hspace|vspace)="[^"]+"\s*)+>/ | |
# Invoke sips to try and find the image's original dimensions | |
# This returns both the widht and height. | |
def get_original_size_for(image) | |
output = %x{sips -g pixelWidth -g pixelHeight "#{image}"} | |
if output.scan(/pixelWidth:[^\d]*(\d+).*pixelHeight:[^\d](\d+)/im) | |
return $1, $2 | |
else | |
exit_show_tool_tip "Could not get image size from #{output.inspect}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terms = { | |
'ë' => 'ë' | |
} | |
{ | |
'wp_posts' => %w{post_content post_title post_excerpt}, | |
'wp_comments' => %w{comment_author comment_author_url comment_content}, | |
'wp_terms' => %w{name}, | |
'wp_term_taxonomy' => %w{description} | |
}.each_pair do |table, columns| | |
columns.each do |column| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Cycle between a series of arguments. | |
* | |
* Usage: | |
* | |
* cycle('even', 'odd') # => 'even' | |
* cycle('even', 'odd') # => 'odd' | |
* cycle('even', 'odd') # => 'even' | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple widow prevention in ruby | |
# given a piece of HTML (not just text) this will look for ending | |
# tags to common block-level elements that should not have widows | |
# | |
# This can be used as a TextMate command -- I've got it mapped | |
# to option-w. Simply put this in there, working on selected text or entire | |
# document. | |
def widont(text) | |
tags = %w{li p div dt dd legend label h1 h2 h3 h4 h5 h6}.join('|') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple function that takes a text list and creates an HTML list | |
# from it. This is useful as a textmate command when marking up | |
# plain text. | |
# | |
# This will take the following text: | |
# | |
# 1. line 1 | |
# 2. line 2 | |
# | |
# And output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_list(text) | |
ol_prefix = /^\d+\.?\s*/ | |
dl_prefix = /^(.+):\s*/ | |
ul_prefix = /^[^\s]+\s*/ | |
lines = text.split("\n").map { |line| line.strip } | |
if lines.any? | |
tag, pattern = if lines.first =~ ol_prefix | |
['ol', ol_prefix] | |
elsif lines.first =~ dl_prefix |
OlderNewer