Feb posted 10 Feb 2010
sudo mdutil -a -i off sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search killall SystemUIServer
Source: http://www.macosxhints.com/article.php?story=20091030173117381
sudo mdutil -a -i off sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search killall SystemUIServer
Source: http://www.macosxhints.com/article.php?story=20091030173117381
Amazon recently changed its Product API requirements and it was a little tricky to get the new signature working, so here’s an example of a product search in PHP.
Pop out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | function _encode_query($s) { $s = str_replace(',', urlencode(','), $s); $s = str_replace(':', urlencode(':'), $s); $s = str_replace(';', urlencode(';'), $s); return $s; } function _encode_signature($s) { $s = str_replace('+', urlencode('+'), $s); $s = str_replace('=', urlencode('='), $s); return $s; } function fetch($power_query, $access_key_id, $associate_tag) { $url_base = 'http://webservices.amazon.com/onca/xml?'; $url_params = array( 'Operation' => 'ItemSearch', 'Service' => 'AWSECommerceService', 'AWSAccessKeyId' => $access_key_id, 'Version' => '2009-01-06', 'Sort' => 'salesrank', 'ResponseGroup' => 'ItemAttributes,Images', 'SearchIndex' => 'Books', 'Power' => $power_query, 'Availability' => 'Available', 'Condition' => 'All', 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z') ); $pairs = array(); foreach($url_params as $k => $v) { $pairs[] = $k.'='.$this->_encode_query($v); } sort($pairs); $canonical = implode('&', $pairs); $base = 'GET'.PHP_EOL.'webservices.amazon.com'.PHP_EOL.'/onca/xml'.PHP_EOL; $to_sign = $base.$canonical; $signature = base64_encode(hash_hmac('sha256', $to_sign, $associate_tag, true)); $signature = $this->_encode_signature($signature); $request = $url_base.$canonical.'&Signature='.$signature; $response = file_get_contents($request); $xml = simplexml_load_string($response); if (!is_object($xml)) { return null; } else { $products = array(); if (sizeof($xml->Items->Item) > 0) { foreach($xml->Items->Item as $item) { $products[] = $item; } } return $products; } } |
This function generates a linear gradient between two hex values. Specify the number of hex values in the returned array with $color_steps. (Haven’t used this in a long time, but if I’m not more diligent about throwing snippets up here, I’ll lose track of them forever.)
Pop out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | function get_gradient($hex_from, $hex_to, $color_steps) { $from_rgb = array( 'r' => hexdec(substr($hex_from, 0, 2)), 'g' => hexdec(substr($hex_from, 2, 2)), 'b' => hexdec(substr($hex_from, 4, 2)) ); $to_rgb = array( 'r' => hexdec(substr($hex_to, 0, 2)), 'g' => hexdec(substr($hex_to, 2, 2)), 'b' => hexdec(substr($hex_to, 4, 2)) ); $step_rgb = array( 'r' => ($from_rgb['r'] - $to_rgb['r']) / ($color_steps - 1), 'g' => ($from_rgb['g'] - $to_rgb['g']) / ($color_steps - 1), 'b' => ($from_rgb['b'] - $to_rgb['b']) / ($color_steps - 1) ); $gradient_colors = array(); for($i = 0; $i < $color_steps; $i++) { $rgb = array( 'r' => floor($from_rgb['r'] - ($step_rgb['r'] * $i)), 'g' => floor($from_rgb['g'] - ($step_rgb['g'] * $i)), 'b' => floor($from_rgb['b'] - ($step_rgb['b'] * $i)) ); $hex_rgb = array( 'r' => sprintf('%02x', ($rgb['r'])), 'g' => sprintf('%02x', ($rgb['g'])), 'b' => sprintf('%02x', ($rgb['b'])) ); $gradient_colors[] = implode(null, $hex_rgb); } return $gradient_colors; } |
Example:
Pop out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | get_gradient('#0084b4', '#a9e0f4', 10); ( [0] => 0084b4 [1] => 128ebb [2] => 2598c2 [3] => 38a2c9 [4] => 4bacd0 [5] => 5db7d7 [6] => 70c1de [7] => 83cbe5 [8] => 96d5ec [9] => a9e0f4 ) |
For all your pursuits on the, er, up-and-up …
Search engine bots:
Browsers:
Source: http://www.developertutorials.com/tutorials/php/scraping-links-with-php-8-01-05/page3.html
Add this to ~/.bash_profile, ~/.bashrc, or wherever you prefer. You can then recursively remove annoying .DS_Store files from a directory by executing the command rm_dss.
Pop out
1 | alias rm_dss='find . -name *.DS_Store -type f -exec rm {} \;' |
How handy! Lifehacker says:
Google Docs Download, a Greasemonkey script previously featured here for creating a Google Docs bulk download feature that should already be there, is now available as a (beta-level) Python script.
This function pipes a javascript file to a Python implementation of Douglas Crockford’s handy JSMin, a javascript minifier.
Pop out
1 2 3 4 5 6 7 8 9 10 11 12 13 | minify() { if [ -f $1 ] then MIN=${1%.[^.]*}.min.js cat $1 | python ~/path/to/jsmin.py > ${1%.[^.]*}.min.js BEFORE=`wc -c <$1` AFTER=`wc -c <$MIN` echo "$BEFORE $1" echo "$AFTER $MIN ($(echo "scale=2; 100*$AFTER/$BEFORE" | bc)%)" else echo "$1 not found" fi } |
It also prints the minified version’s character count as a percentage of the original’s:
$ minify prototype.js 126127 prototype.js 93689 prototype.min.js (74.28%)
Pop out
1 | import os |
List all files in a directory recursively, with relative paths:
Pop out
1 2 3 4 | def list_dir(dir_name): for r, d, f in os.walk(dir_name): files = [os.path.join(r, n) for n in f if not n.startswith('.')] return files |
Create a directory if it doesn’t already exist:
Pop out
1 2 3 | def make_dir(dir_name): if not os.path.isdir(dir_name): os.mkdir(dir_name) |
Empty an existing directory:
Pop out
1 2 3 4 5 | def empty_dir(dir_name): if not os.path.isdir(dir_name): os.mkdir(dir_name) else: [os.remove(f) for f in list_dir(dir_name)] |
Source: Indiana University UITS
Pop out
1 2 3 | RewriteEngine On RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L] |