Typically, the solution involves iterating through NSView’s - [NSArray subviews] and invoke the child’s - (void)removeFromSuperview method. This is tedious. A much easier solution is to set an empty list of childs on the parent NSView, like so:
[self setSubviews:[NSArray array]];
It’s simple, clean and better yet… won’t crash while you iterate the array and destroy the objects while you’re ennumerating ;-)
Here’s an easy way to convert an NSColor to a CGColor:
- (CGColorRef)NSColorToCGColor:(NSColor *)color
{
NSInteger numberOfComponents = [color numberOfComponents];
CGFloat components[numberOfComponents];
CGColorSpaceRef colorSpace = [[color colorSpace] CGColorSpace];
[color getComponents:(CGFloat *)&components];
CGColorRef cgColor = CGColorCreate(colorSpace, components);
return cgColor;
}
Easy.
How can I undo an accidental commit that hasn’t been pushed yet? Easy:
git reset --soft HEAD^
This will revert the commit and leave the changes in your local repo.
These commands and actions need to be performed from an account that has administrator privileges.
Download the image from a mirror or torrent:
http://www.raspberrypi.org/downloads
Verify if the the hash key is the same (optional), in the terminal run:
shasum ~/Downloads/2012-12-16-wheezy-raspbian.zip
Double click the zip, it will extract the image automatically.
From the terminal run
df -h
Connect the SD card reader with the SD card inside. Run df -h again and look for the new device that wasn’t listed last time. Record the device name of the filesystem’s partition, for example, /dev/disk3s1. Example:
TurboMonkey:Desktop tciuro$ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 233Gi 185Gi 48Gi 80% 48594722 12474718 80% /
devfs 197Ki 197Ki 0Bi 100% 682 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
localhost:/mxqCAh80ehTrmCCc-8n_X5 233Gi 233Gi 0Bi 100% 0 0 100% /Volumes/MobileBackups
/dev/disk1s1 15Gi 2.2Mi 15Gi 1% 0 0 100% /Volumes/NO NAME
Unmount the partition so that you will be allowed to overwrite the disk:
sudo diskutil unmount /dev/disk3s1
Using the device name of the partition work out the raw device name for the entire disk, by omitting the final “s1” and replacing “disk” with “rdisk” (this is very important: you will lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, rdisk3, not rdisk3s1. Similarly you might have another SD drive name/number like rdisk2 or rdisk4, etc. — recheck by using the df -h command both before & after you insert your SD card reader into your Mac if you have any doubts!). Example:
/dev/disk1s1 => /dev/rdisk1
In the terminal write the image to the card with this command, using the raw disk device name from above (read carefully the above step, to be sure you use the correct rdisk# here!):
sudo dd bs=1m if=~/Desktop/2012-12-16-wheezy-raspbian.img of=/dev/rdisk1
If the above command report an error(dd: bs: illegal numeric value), please change bs=1M to bs=1m (note that dd will not feedback any information until there is an error or it is finished, information will show and disk will re-mount when complete. However if you are curious as to the progress - ctrl-T (SIGINFO, the status argument of your tty) will display some en-route statistics).
After the dd command finishes, eject the card:
sudo diskutil eject /dev/rdisk1
Insert it in the Raspberry Pi, and have fun!
Why is it easier to say there’s some God that always existed, as opposed to the Universe always existed? How is it that a God could always exist, but not a Universe? Or conversely, how is it that a God could come from nothing, but not a Universe?
Problem
Oftentimes, we’re fixing a bug and as we go along we see other issues which end being fixed as well. The problem results in a different set of changes which would typically end up committed at once.
Solution
Commit selectively using git add -p …
Example
Locate the Git directory and check its status:
git status
It will list the files with changes, such as:
ipanema:MyProject tciuro$ git status
'# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo.m
# modified: bar.m
#
no changes added to commit (use "git add" and/or "git commit -a")
For each of the files, issue the following command (we’ll start with foo.m):
git add -p foo.m
It’ll display each of the changes separately:
@@ -113,21 +113,15 @@ typedef enum {
- // Preflight
- NSAssert(username.length > 0, @"the user name is required");
-
self.username = username;
- self.password = (password.length > 0 ? password : @"");
+ self.password = password;
self.authType = SSH;
}
Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? y
Type y or no and continue until you’re done. Repeat the same step with the other modified files.
By default, Tumblr doesn’t allow to search by tags. Assuming you have a theme with a search bar, chances are that even though you tagged your posts, nothing comes up when you search by tag.
No problem. It’s quite easy to fix this. Just follow these steps:
1) Open your blog and click “Customize.” A configuration panel opens to the right of the window.
2) Click “Edit HTML.”
3) Hit Command-F (i.e. Find…) and search for “body” (without the quotes).
4) Right after “body” paste the following script:
<body>
<script type="text/javascript">
<!--
function handleThis(formElm)
{
window.location="http://yourtumblrURLhere.tumblr.com/tagged/"+formElm.number.value+"";
return false;
}
</script>
...
...
Some users have their own custom domain (e.g. www.yourdomain.com). If this the case, replace the window.location URL above:
window.location="http://yourtumblrURLhere.tumblr.com/tagged/"+formElm.number.value+"";
with this:
window.location="http://www.yourdomain.com/tagged/"+formElm.number.value+"";
That’s it really! Just save the HTML changes, reload your blog, tag something and search. Happy tagging!
This brief tutorial explains how to generate SSH keys and publish them to a server. It’s been tested on Mac OS X Mountain Lion (10.8).
Objective
Generate an SSH key and upload them to a server. In our example, we’ll upload it to server.example.com.
Step #1
Launch Terminal.app and type:
ipanema:~ jdoe$ ssh server.example.com
The authenticity of host 'server.example.com (xx.xxx.xx.xxx)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:.
Type yes to add the host to your list of known hosts:
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server.example.com,xx.xxx.xx.xxx' (RSA) to the list of known hosts.
Enter the password. This will create an .ssh directory in your home directory with the proper permissions.
Password:
Last login: Tue Nov 6 20:33:46 2012 from xx.xxx.xx.xxx
Welcome to server.example.com.
This server is managed by the SEO Puppet configuration management system.
Local ad-hoc changes to this system are strictly discouraged. Any files
that contain an auto-generated header will be updated via puppet and local
changes will be overwritten. Please contact admin@example.com for more info.
server:~ jdoe$
We can close the connection for now:
server:~ jdoe$ exit
logout
Connection to server.example.com closed.
Step #2
Now we’ll generate the SSH key:
ipanema:~ jdoe$ ssh-keygen -t rsa
This will prompt you for a secret passphrase:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jdoe/.ssh/id_rsa):
Created directory '/Users/jdoe/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/jdoe/.ssh/id_rsa.
Your public key has been saved in /Users/jdoe/.ssh/id_rsa.pub.
The key fingerprint is:
15:db:96:0d:92:bc:51:4d:bf:d6:43:89:98:98:fb:c8 jdoe@ipanema.example.com
The key's randomart image is:
+--[ rsa 1024]----+
| .oooo. |
| *=o+o..|
| oo=+..o.|
| .o. . o|
| S. +.|
| . o . .|
| E . |
| |
| |
+-----------------+
ipanema:~ jdoe$
IMPORTANT
Always use a good passphrase and never leave it blank. If this works right
you will get two files called id_rsa and id_rsa.pub in your .ssh directory.
Step #3
Now it’s time to upload the credentials to server.example.com:
scp ~/.ssh/id_rsa.pub server.example.com:.ssh/authorized_keys2
This command copies the id_rsa.pub file to the other host’s .ssh directory with the name authorized_keys2. Now server.example.com is ready to accept your ssh key.
How to tell it which keys to use?
The ssh-add command will allow us to confirm which SSH key will be used:
bash-3.2$ ssh-agent sh -c 'ssh-add < /dev/null && bash'
Identity added: /Users/jdoe/.ssh/id_rsa (/Users/jdoe/.ssh/id_rsa)
The moment of truth
Everything looks good, so let’s try to ssh into server.example.com once again. This time, no prompt should appear because the magic of SSH keys will take over:
bash-3.2$ ssh serverexample.com
Last login: Tue Nov 6 20:18:18 2012 from 17.226.33.162
Welcome to serverexample.com.
This server is managed by the SEO Puppet configuration management system.
Local ad-hoc changes to this system are strictly discouraged. Any files
that contain an auto-generated header will be updated via puppet and local
changes will be overwritten. Please contact seo@example.com for more info.
server:~ jdoe$
Did you gain access without a prompt? If so, congratulations! Otherwise, start over and pay attention to the instructions ;-)
Bacteria produce a new generation every 20 minutes. And every time they reproduce, which is they copy themselves, they make little copying errors. So when those little copying changes make the bacteria stronger as opposed to weaker then that means they are better able to defend themselves against those compounds, antibiotics.—CDC (Centers for Disease Control and Prevention) Drug-Resistant Gonorrhea: Is The Antibiotic Era Coming To An End?
This is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.
So, first setup the remote repository:
ipanema:~ tciuro$ cd ~/Desktop
ipanema:Desktop tciuro$ mkdir RemoteRepo.git
ipanema:Desktop tciuro$ cd RemoteRepo.git
ipanema:RemoteRepo.git tciuro$ git --bare init
Initialized empty Git repository in /Users/tciuro/Desktop/RemoteRepo.git/
Now we have to setup the local sources directory. This directory contains your source files and must not have been initialized with Git, of course:
ipanema:RemoteRepo.git tciuro$ cd ../LocalSources/
ipanema:LocalSources tciuro$ git init
Initialized empty Git repository in /Users/tciuro/Desktop/LocalSources/.git/
ipanema:LocalSources tciuro$ git add *
ipanema:LocalSources tciuro$ git commit -m "Initial release"
[master (root-commit) 744e73a] Initial release
55 files changed, 3236 insertions(+)
...
...
Let’s verify that everything is in order by checking the branch:
ipanema:LocalSources tciuro$ git branch
* master
Before we can push the contents from our local sources directory to the remote repo, we have to link the local sources directory to the remote repo:
ipanema:LocalSources tciuro$ git remote add origin /Users/tciuro/Desktop/RemoteRepo.git
Cool. Now we can push the changes from local to remote:
ipanema:LocalSources tciuro$ git push -u origin master
Counting objects: 73, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (69/69), done.
Writing objects: 100% (73/73), 790.82 KiB, done.
Total 73 (delta 21), reused 0 (delta 0)
Unpacking objects: 100% (73/73), done.
To /Users/tciuro/Desktop/RemoteRepo.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Let’s start clean by making a new local repo:
ipanema:LocalSources tciuro$ cd ../
ipanema:ClonedRepo tciuro$ git clone /Users/tciuro/Desktop/RemoteRepo.git ClonedRepo
Cloning into 'ClonedRepo'...
done.
ipanema:Desktop tciuro$ cd ClonedRepo
ipanema:ClonedRepo tciuro$ git status
# On branch master
nothing to commit (working directory clean)
Excellent. Quick check to verify that we’re in business:
ipanema:ClonedRepo tciuro$ git log
commit 8aaa16b6feed7a8b0c01526472e7e89efaab6bd3
Author: Tito Ciuro <...>
Date: Fri Oct 5 10:40:06 2012 -0700
Initial release
ipanema:ClonedRepo tciuro$
Woohoo! That’s it! I hope this helps ;-)