Open Bash (a.k.a. Terminal) from Finder and Vice Versa
GUI’s are great. And so are shells. Here’s how you can have the best of both worlds with minimal mucking around:
Finder to Bash
Create this a simple apple script (see code below, after the jump) in the ‘AppleScript Editor’, save as an Application, and drag it into your Finder’s toolbar. Clicking this button will open that folder in bash! If you’re clever, you can open the package contents of ‘Terminal’, copy the icon file, then open the contents of your script application, find the icon and replace it with the Termainal one. Or if you’re lazy (and trusting) you can just download the one I prepared earlier.
In Lion you can also enable this as a right-click service of folders, go to System Preferences > Keyboard > Keyboard Shortcuts > Services and enable New Terminal at Folder or New Terminal Tab at Folder, then you can right click -> Services on any folder in finder and open it in Finder that way. You can also assign a keyboard shortcut.
Bash to Finder
If you’re in bash, you can simply open . to open the current directory in Finder (or open path/to/folder to open a different one). open-ing a file will also launch that file in the default app. Neat.
UIImagePickerController freezing/hanging in XCode 4.2
The UIImagePickerController docs say: “The delegate methods are responsible for dismissing the picker when the operation completes. To dismiss the picker, call the dismissModalViewControllerAnimated: method of the parent controller responsible for displaying the UIImagePickerController object.”
Following other docs, one would think the most reliable way to do this would be [[picker parentViewController] dismissModalViewControllerAnimated:YES]; (which calls dismissModalViewControllerAnimated of the parent controller).
However, in in XCode 4.2 this is no longer possible. NB. I say XCode4.2 here, and I mean XCode 4.2. This is unrelated to the iOS version, but rather the XCode version. I had code working on 4.0, 4.3 and 5.0 in XCode 4.1 which fails when built on XCode 4.2.
So instead, use whatever controller you presented the viewcontroller on to dismiss it too. [parentController dismissModalViewControllerAnimated:NO];. The old way worked pre XCode 4.2. But when you upgrade to XCode 4.2 it will suddenly return nil – causing the UIImagePickerController to not be dismissed, and thus effectively hanging.
This also seems to work, but isn’t really what the docs suggest. [picker dismissModalViewControllerAnimated:NO];.
Thanks to Omil for the tip.
Git
Here are some things that I find useful in git. Basically this is my scratch pad of commands I need.
Replacing one branch with another.
To set master to be equal to ‘tweaks’
git checkout tweaks git merge -s ours master git checkout master git merge tweaks
Stop your local file and accept theirs (or vice versa).
git checkout --ours filename.c git checkout --theirs filename.c
Undo the last commit (before you push)
git reset --soft HEAD^
git clean -d -x -n # removes all untracked and ignored files
Now something XCode Clear out all the cruft.
~/Library/Developer/Xcode/DerivedData
Reverting a commit (actually reverting it, i.e. a new commit with the reverse merge)
git revert
Splitting off a branch at a given commit, and rolling the origin branch back to that same commit
git checkout core git branch core-experimental git reset --hard <SHA of last commit you want to keep> git push -f <remote> core
Getting the SHA of the submodule of a tag
$ git ls-tree released-1.2.3 foo
Add all the files you don’t want to stash, then:
$ git stash --keep-index
Then unstage your changes if you didn’t really want to stage them with:
$ git reset --soft
Deleting a file from the index without deleting the local copy
git rm --cached filename
Beware: ALAsset URLs are non-unique
iOS4 introduced the ALAssetLibrary, a way you can reference the files stored in the user’s camera roll, etc. Pretty useful, albiet a slightly convoluted API (what’s new?).
Here’s the catch: the ALAsset URLs returned are *not* guaranteed to be unique! When the user downloads & deletes photos from the camera roll (a very common use-case), that URL can potentially be re-used for another photo.
I discovered this in GPS Log, where I record the ALAsset URLs for all images taken (which can be quite a lot), and noticed that mis-matches were occurring.
My workaround is this:
In my list where I store the ALAsset URL, I now also store the ALAsset creationDate (accessible with [myAsset valueForProperty:ALAssetPropertyDate]). Thus when retrieving the asset, I first check that the retrieved creation date matches the one I am expecting. If it doesn’t then I treat the asset as missing, just like I do should the ALAssetLibrary not return any asset for that URL.
I’m afraid I can’t share my implementation as it’s not really all that portable – but I think you can get the gist of what I did from that description. Annoyingly, getting that creationDate is not so straight forward, as you can’t just execute it in the main thread (due to ALAssetLibrary’s design).
Why are these URLs reused I don’t know. I would prefer to see some UUID type setup. But anyway – be aware of this limitation, and prepare accordingly.
Mobifone 3G Vietnam
Bought a SIM card for 50,000, seemed to have 50,005 credit. Not bad.
Internet setup details (use Chrome to translate easily)
What I did:
APN: m-wap
Username&Password: mms
iPhone4 config (others)
I actually got 750MB which was pretty good.
When it was time to apply a new package, the process was the same. I activated M70. The only difference was it told me I would lose my current package, and it asked me to confirm. To confirm, I simply sent `Y` to 999 after my `DK M70`. This time i got 1228MB so it is pretty decent!
5.1. Table of charges
Sending to 999: 200d/tin message
|
TT |
Package |
Expiry |
Subscription fee (VND) |
Free Traffic (MB) |
Freight traffic over packet (and / KB) |
Charging Method |
|
1 |
M0 |
0 |
0 |
0 |
1.5 e / KB |
50KB + 50KB |
|
2 |
M5 |
30 days |
5000 |
10 |
0.5 e / KB |
10KB + 10KB |
|
3 |
M10 |
10,000 |
30 |
|||
|
4 |
M25 |
25,000 |
120 |
|||
|
5 |
M50 |
50,000 |
350 |
|||
|
6 |
M70 |
70,000 |
600 |
|||
|
7 |
M100 |
100,000 |
1024 |
|||
|
8 |
D1 |
1 day |
8000 |
100 |
||
|
9 |
D7 |
7 days |
35,000 |
300 |
||
|
10 |
D30 |
30 days |
120,000 |
1536 |
( The above rates include 10% VAT )
Note: The maximum speed of all packages is 7.2 Mbps
Consult appropriate option package here
More Proof It’s a Good Idea to Update the Doctrine
I’ve always maintained that certain old books were written in the context of particular societal norms which may no longer be completely relevant 2011 years on. Guess that’s the problem if you believe in the infallibility of said book, unless you can “interpret” the bits you don’t like away.
Abstinence Only couples have pre-marital sex only 8% less than non-abstinence couples (80% to 88%). One reason? A while ago it would be common to be married by your 17th birthday anyway, so there was no need to wait into your late-20′s as is the average marrying age now. In other words: it was a lot more realistic. Also, due to the lack of contraception back then, it was a lot more important!
This is what I like about Buddhism, as Wikipedia states, Buddha taught: “Rejection of the infallibility of accepted scripture: Teachings should not be accepted unless they are borne out by our experience and are praised by the wise.” i.e. it’s OK to update to maintain relevance!
Rescuing HTTPClient Exceptions
I have a need in a rails app to rescue just exceptions raised due to fairly common situations in downloading data from URLs. Catching all exceptions is bad, as exceptions in my code are treated the same as connection errors, and not passed to my standard exception handling (HTTP 500, plus email to me).
From looking at the docs, there are two base-error classes HTTPClient raises due to http connection errors, BaseResponseError and TimeoutError (these are the two classes that extend RuntimeError). A bunch of others derive from these. I decided not to catch the ConfigurationError.
Adding in a catch for invalid domains / IP addresses, and my rescue statement looks like this:
rescue Errno::EADDRNOTAVAIL, Errno::ETIMEDOUT, HTTPClient::BadResponseError, HTTPClient::TimeoutError


