Friday, July 29, 2011

Get links from a page with bash

Get anchor elements from a webpage can be done with

curl URL 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2


where you replace URL with your choice, just like here:
curl http://cookpad.com 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2

Tuesday, July 26, 2011

Switching back to the previous application with AppleScript

If you want to simulate cmd + tab with AppleScript, here it is

tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell


You can use the same thing in bash

echo 'tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell' | osascript

Thursday, July 14, 2011

Show Git Commits By Author

It is as simply as
git log --author=<PATTERN>

for example

git log --author=viktor

Tuesday, July 5, 2011

Resize and position windows with AppleScript


-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell

set width to x2 - x1
set height to y2 - y1

-- positioning iTunes, make it fullscreen
tell application "iTunes"
set the bounds of the first window to {x1, y1, x2, y2}
end tell

-- positioning Safari, halfwidth on the right
tell application "Safari"
set the bounds of the first window to {x1 + width / 2, y1, x2, y2}
end tell

-- positioning iTerm
tell application "iTerm"
set the bounds of the first window to {x1, y1, x1 + 1000, y1 + 600}
end tell

There are few useful blogposts about the topic.
www.ithug.com/2007/09/applescript-moving-and-resizing-windows or
www.ithug.com/2008/12/applescript-arranging-multiple-windows/

or you can use Divvy, which is an amazing window management app.

Generating QR Codes with Google

The google chart API has this feature.
http://chart.apis.google.com/chart?cht=qr&chl="+[YOUR_TEXT]+"&chs=[XSIZE]x[YSIZE]"

For instance
http://chart.apis.google.com/chart?cht=qr&chl="Hello World"&chs=120x120"

will generate this

Thursday, June 30, 2011

Changing the default google domain in Chrome

On a mac, make sure that you closed the Chrome browser.

Go to

cd ~/Library/Application\ Support/Google/Chrome

and edit the 'Local State' file,
change the following lines to whatever google domain you want.

"last_known_google_url": "http://www.google.com/",
"last_prompted_google_url": "http://www.google.com/",

start the browser.

If you use profiles you have to go to that profile folder and change the 'Local State' file there
cd ~/Library/Application\ Support/Google/Chrome/[PROFILE NAME]

Application Cache whitelisting the master entry

An application cache is a set of cached resources consisting of:

Master entries
These are documents that were added to the cache because a browsing context was navigated to that document and the document indicated that this was its cache, using the manifest attribute.

Explicit entries
These are the resources that were listed in the cache's manifest in an
explicit section (CACHE).

Fallback entries
These are the resources that were listed in the cache's manifest in a fallback section.

The resource that declares the manifest (with the manifest attribute) will always get taken from the cache, whether it is listed in the cache or not, even if it is listed in an online whitelist namespace.
This means that your HTML that includes the manifest file will be always a master entry which is cached and accessed from the cache even the client is online.
Let's face it, this is a pain in the neck in same cases.

There is a simple workaround
1. create an OTHER HTML that will include the manifest file
2. from the ORIGINAL HTML remove the manifest include and create an iframe that includes the OTHER HTML

In this case the master entry will be this OTHER HTML, which does not affect whitelisting the ORIGINAL HTML.

I'd like to emphases that this is just a workaround and i'd like to have a better solution.

You can also follow the related whatwg discussion.