Skip to content

Instantly share code, notes, and snippets.

@al3x
al3x / newpost.rb
Created April 22, 2009 23:50
Handy new post script for Jekyll blogs or similar
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = "/Users/al3x/src/al3x.github.com/_posts/#{date_prefix}-#{postname}.textile"
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
class Object
# An object is blank if it's false, empty, or a whitespace string.
# For example, "", " ", +nil+, [], and {} are blank.
#
# This simplifies
#
# if !address.nil? && !address.empty?
#
# to
#
@lwe
lwe / brew-more.rb
Created July 14, 2010 08:53
Try to scrape formula information from @formula.homepage.
# Small utility which uses the homepage and nokogori to get a description from the formula's homepage.
#
# As written in the homebrew wiki:
# > Homebrew doesn’t have a description field because the homepage is always up to date,
# > and Homebrew is not. Thus it’s less maintenance for us. To satisfy the description
# > we’re going to invent a new packaging microformat and persuade everyone to publish
# > it on their homepage.
#
# Too bad no packaging microformat has yet been invented, but brew-more just first looks for a
# `<meta name="description">` tag, then for an `a#project_summary_link` tag (which is used in
@RobertAudi
RobertAudi / preg_grep_keys.php
Created July 21, 2010 15:14
Return array keys that match the pattern.
<?php
function preg_grep_keys( $pattern, $input, $flags = 0 )
{
$keys = preg_grep( $pattern, array_keys( $input ), $flags );
$vals = array();
foreach ( $keys as $key )
{
$vals[$key] = $input[$key];
}
@RobertAudi
RobertAudi / gist:487163
Created July 23, 2010 08:04
Recent Items Stack
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }'
@RobertAudi
RobertAudi / gist:487657
Created July 23, 2010 16:26
Replace first occurrence of the search string with the replacement string.
<?php
/**
* Replace first occurrence of the search string with the replacement string.
*
* @param string $needle : The value being searched for.
* @param string $replace : The replacement value that replaces found search values.
* @param string $haystack : The string being searched and replaced on.
* @return string : The (modified) haystack.
* @author tapken at engter dot de
@RobertAudi
RobertAudi / README.markdown
Created July 25, 2010 12:32
End of file comment Textmate command

I just created this little textmate command that acts like a snippet and inserts an End of file command a la CodeIgniter. Example:

/* End of file eof.tmsnippet.php */
/* Location: ./Sandbox/php/Textmate_Commands/eof.tmsnippet.php */

If you want to start using it right away, I uploaded the .tmCommand file in CloudApp. I also created a gist with the code of the command so that you can easily modify it if you want to. The links is at the bottom of the post.

Alternatively, you can create the command manually. Here are its attributes:

  • Save: Nothing
@RobertAudi
RobertAudi / gist:620925
Created October 11, 2010 17:43
Format unix permissions
<?php
/**
* Toggle the formatting of unix permissions between:
* - 0644 OR 755
* - -rw-r--r--
*
* @param string|int $permissions : The permissions string or int that needs to be formatted.
* @param string $is_dir : if true, the first char of the long permissions format will be 'd'. ie: drw-r--r--
* @return string: The formatted permissions.
@mikelikespie
mikelikespie / refresh_css.js
Created October 27, 2010 18:31
This refreshes all the css on a page by changing the query string
/*
Add a bookmark to this
javascript:(function(){var c=document.getElementsByTagName("link");for(var d=0;d<c.length;d++){var a=c[d];if(a.rel=='stylesheet'||a.type=="text/css"){var e="css_buster_"+Math.floor(Math.random()*1000000000);var g=a.href.split("?",2);var f;if(g.length>1){var b=g[1].indexOf("&")==-1;if(b){f=e}else{f=g[1]+"&"+e}}else{f=e}a.href=g[0]+"?"+f}}})();
*/
(function() {
var links = document.getElementsByTagName('link');
for (var i = 0; i < links.length; i++) {
var l = links[i];
if (l.rel == 'stylesheet' || l.type == 'text/css') {