Skip to content

Instantly share code, notes, and snippets.

@RobertAudi
RobertAudi / gist:465247
Created July 6, 2010 10:56
moc aliases
alias mg="mi-growl.sh &> /dev/null &" # launch growl support
alias mof="mocp -f" # next
alias mor="mocp -r" # prev
alias mop="mocp -G" # play/pause
alias mos="mocp -s" # stop
alias mox="mocp -x" # exit
@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 / insert_char_in_string.php
Created July 22, 2010 10:22
Insert a character at a certain position in a string.
<?php
/**
* Insert a character at a certain position in a string
*
* @param string $char : The character to insert.
* @param string $string : The input string.
* @param int|string $position : The position of the insertion; if the position is set to 'random', than the position will be ... random ...
* @return string
* @author Aziz Light
@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 / markdown.template
Created August 19, 2010 15:35
Markdown template for the InfoLister Firefox add-on.
text/plain;Markdown;[[***Last updated:** %lastupd%*
]][[**User Agent:** %useragent%
]][[## Extensions ##
*(enabled: %enabled_extensions_count%, disabled: %disabled_extensions_count%; total: %extensions_count%)*
{{extension:* **%name%** *%version%* %disabled-text%
}}
@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.
@RobertAudi
RobertAudi / gist:649132
Created October 27, 2010 14:34
Extract one or multiple archives of any type
#!/usr/bin/env ruby
# check if a command exists
def command_exists?(command)
system("which #{command} > /dev/null 2>/dev/null")
$?.exitstatus == 0
end
def usage
usage = "Usage: extract [-vz] <file> [<file> <file> ..]\n\n"
@RobertAudi
RobertAudi / m.rb
Created November 3, 2010 16:42
Small wrapper for the mate command
#!/usr/bin/env ruby
# This Script is a wrapper for the mate command.
# IT'S NOT A SUBSTITUTE!
# If you want to pipe to Textmate from the terminal,
# use the mate command instead.
# Also, its slower than the mate command, so if you don't
# mind typing a couple extra characters, but do mind one extra
# second of waiting at most, then use the mate command.