Thursday, January 26, 2012

That's the difference

Time magazine interviewed obama on foreign policy and his responses were telling. That's what sets him apart from others. He actually recognizes that stability in Afghanistan (so long sought for), won't happen overnight; it will require decades.

Thursday, January 19, 2012

No apt-get or yum for Cygwin?

This is a shocker. Even MinGW has a CLI installer! You have to run setup.exe from Windows to download and install new packages. There is a project on google code, cyg-apt (or apt-cyg [1] and probably others, because one is never enough), that you can download and build, but another shocker, neither of these are included in the Cygwin Packages!

I am a newbie to Cygwin and to Linux in general so perhaps my shock is misplaced, so please disabuse me. But I'm wondering if Cygwin (and perhaps MinGW [2]) are still relevant with Ubuntu for Linux in a Windows environment and for MS Visual Studio Express for C++ development for free.


Update 2012-07-17


Well, I am still a n00b, but I feel like I have enough experience to disabuse myself. There are some really nice features in Cygwin, that you just can't get with MSYS. For example, you can't install Python in MSYS, without building it from source, although that probably wouldn't be necessary since there is a Windows version of Python. But Cygwin has tons of ports, e.g. Python, GTK, even mingw32 and it's sibling mingw-w64. Some of these also have Windows binaries, pre-compiled and packaged into installers already, but others, like dbus, can be tricky to build for Windows. Both MinGW/MSYS and Cygwin seem to be alive and thriving, but using a VM, especially on newer laptops with harware virtualization, free VM players, and the wide selection of light Linux distros, it does seem like you could get some of the same capability going that route. However, if you use a Linux VM, and your purpose is to do Windows development (in C/C++) then you will have to cross-compile, either with mingw32 or mingw-w64, both available for Linux. And that is the crux, if you want to develop in C/C++ for Windows, then you can either pony up for Visual Studio, get an express version or try MinGW, Cygwin, or one of it's buddies. For deployment, you may need to use freeware like NullSoft, InnoSetup or Wix. And in general, there may be some Linux ports that you'll need to develop your application, in which case you will absolutely need either MSYS or Cygwin, so maybe there is a place for these platform mediators after all. FYI: I haven't tried The Linux in Windows trick  yet, but after reading a bit, VM seemed superior. 


[1] apt-cyg is actually quite good. It is really just a wrapper for setup.exe which you can run from the command line, see "Does setup.exe except command-line arguments?" in setting up Cygwin faq's.

[2] Total n00b misconception! MinGW is a just a set of free GNU development tools, ported to windows. It is not like Cygwin, a *nix-like environment. That would be MSYS. You just need to read their website.

deleting a file

If you read any of the Git references they all say the way to delete a file from your repo is git-rm, but it turns out that you can also just as easily delete it (from your filesystem), stage it and then commit it.


If you come from Subversion, like me, this might seem like anathema but it works just fine (maybe it works just fine in Subversion too, ha!).


And it's quite convenient if you're like me and using an IDE but not using a Git plugin, and you didn't create a .gitignore file for your binaries, so every time you recompile, and your binaries change their changes are tracked, and if you had a Java inner class, so you got one of those file$1.class files, and then you removed the inner class then it got deleted when you recompiled, but you never ran the git-rm command, it's all going to be OK, because you can just do git-add --all and then commit. Ah, all better.

Wednesday, January 18, 2012

Using git bash on Windows with SSH

[UPDATED 2013-03-14]

TortoiseGit works great with remotes. If you are used to TortoiseSVN, then after a very short transition to DVCS style SCM you'll be cloning, branching, pushing and pulling in no time.

But what's that funny GitBash thing for? Well if you're like me and you started using Git from a terminal then you'll need to use GitBash (unless you opted out of the default mysysgit installation) to use commands. To get help, use git help instead of man git.

So the point of this post is how to use GitBash with remote repositories like GitHub or BitBucket with SSH. Of course both sites support HTTPS, but SSH is so much more James Bond you know you want it. If you installed TortoiseGit then you're probably using  PuTTY/Plink and Pageant which works pretty seamlessly with both sites. But I could not get the GitBash to work with PuTTY/Plink even with Pageant running. Luckily mysysgit (and Cygwin) come with SSH, so just generate a new key and give your public one to your remote. You also have to make a config file in your .ssh folder with host, user and private key file.

BitBucket has a good help page on how to set up mysysgit on windows here. That's where they show you step by step how to make a key, set up your SSH config file and also how to set up ssh-agent, so you don't have to keep typing in your SSH passphrase. I highly recommend this last step; that snippet of code is from a very old Cygwin post, so it's been tested literally millions of times. There's also some general information on using SSH with BitBucket here. Of course GitHub also has help on SSH issues here too. It has been revised since I originally wrote this post (over a year ago) and now has excellent setup instructions for all platforms, including Windows.

BTW: TortoiseHg will really only work with PuTTY/Plink and Pageant.

Deleting a remote branch

Deleting a remote branch is hard to remember.
git push origin :branch_to_delete
I like Progit's mnemonic; think of it as pushing nothing into that branch.
http://progit.org/book/

Monday, January 16, 2012

Ubuntu's Ugly Underside

So far I must say that I am really loving Ubuntu 11.10, aka Oneiric Ocelot. I'm still blown away by how fast it starts up. For something that is completely free it's pretty well supported, if you consider all of the online forums, Stack Exchange websites, blogs, etc. Since it's open source, I can't complain about bugs, and on the contrary, I think it's important to report them. Oneiric Ocelot has a bug with the bluetooth interface that affected me when I tried to pair my phone to send an apk (android package) to it. I was pretty frustrated, and it took me awhile to find any online resources that helped. I did learn a little about hcitools and bluez, but I'm scared with my extreme inexperience, I might break my box again, so I'm very cautious. Finally I found several bug reports in launchpad that exactly described the problem. So that's probably the first lesson: always check for bug reports. The fix so far for me was to pair the device manually using hcitool and bluez-simple-agent, them enabling personal file sharing for bluetooth, which was however tucked away and had I not known to look for it would never have found it. It can be access from the dash. The other part of the bug is slated to be fixed in Precise (12.04) coming out in April.

Here are the links to bug on launchpad:
#879923 No file transfers possible with cell phones, regression since oneiric alpha
#872044 Bluetooth 'Send files' returns permission denied error
#822141 Cannot receive or send files via bluetooth
#829703 "Select Device to Browse" dialog contains tiny listbox

Saturday, January 14, 2012

Passing data to an activity started by an intent

If you need to pass data from one Activity to another using intents, then you have to use the putExtra() methods (there is a general one and then one for almost every data-type) and then getIntent().getExtras() method.

I ran into a problem with this when using the setOnClickListener() method on a Button object to create an onClickListener to with the onClick callback when I got the button by id from the layout xml. I could not pass my data through the intent, maybe because the onClickListener was an anonymous inner class? I'm sure there was a solution to my possible incorrect totally plagiarized code, but then I found an even better solution, which I also plagiarized. Just use the onClick attribute in the layout xml to name the onClick() method in your activity that is the callback for the button. It's much easier and slicker.

See:
http://developer.android.com/reference/android/widget/Button.html

Thursday, January 12, 2012

export a repo git's way

Just so I don't forget, to export a branch or tag or any commit, just check it out, "git checkout branch", then use the command:
git checkout-index --prefix=/home/your/export/folder/ -a
Voila!
Note this is an export in the subverions sense, the .git and .gitconfig folders are ignored and the export is not a git repo.

Monday, January 9, 2012

Git Windows is so easy!

[UPDATED 2014-10-07] For a pure msysgit experience, check out Basic Git Work Flow.
[UPDATED 2013-04-11]
I feel I should update this site since it is so hopelessly out of date.
I got Git up and running on an XP with shell integration, and linked to my remote in under 15 minutes, and that's only because I got up to get a cup of water. Now I have it running on my Windows 7 x64 machines as well. As the msysgit project has matured, it has gotten even easier. And there are more Git clients now as well. Git is the most widely used distributed version control system and not just for source control management tool, even writers and others are using it. Why? GitHub, Bitbucket, Gitorious, CodePlex and others all host online Git repositories. Mercurial is also a very popular dvcs.

Here are some notes I took of my process. I'll clean it up later:

mysysgit

There is really no need to read any of these other than Scott Chacon's Pro Git book.
  1. For more info. Read: Github Help: Set up Git , SparkFun: Using GitHub with Windows , Sergio Pereira » Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink, and An Illustrated Guide to Git on Windows. Lots of good reading material on this subject now.
  2. Goto:  msysgit.
  3. Download and install msysgit. Note: if you use GitHub for Windows, you can skip this step as Git is installed for you.
  4. Leave all settings the same except: uncheck git-cheetah and select Git Bash Here and Git GUI here instead.
  5. You might prefer git-cheetah or git-extensions, but they are basically clones of gitk and git-gui which you will already have. They just add shell extensions, which msysgit also already has: git-bash (a bash console) and git-gui. TortoiseGit and GitHub for Windows will also add shell extensions.
  6. This part is really irrelevant. GitHub says it will not work with plink/putty ssh keys, which is the default in TortoiseGit, but I’ve seen numerous posts that say it does, maybe the docs are out of date. Also TortoiseGit will give you the option to use Git's SSH client, but claim Putty/Plink works better on Windows. Also since all 3 Tortoise projects share libraries, chances are if you have TortoiseSVN or TortoiseHg you already have Plink.

Git Clients TortoiseGit

In addition to TortoiseGit there is also Github for Windows and Atlassian's SourceTree. There are even more Git clients listed on the Git websiteFor now I would still recommend against GitHub for Windows, as it is helplessly stoopid. For TortoiseSVN users - I would recommend sticking with TortoiseGit. Either way you will find with Git, the command line is somehow irresistible.
  1. Install TortoiseGit. Look at the downloads and grab the latest version for your machine, either x64 or x86.
  2. Stick with Plink/Putty; and let’s see if it just works.
  3. You may need to restart, or you may not. Restart, yay! It works (and even better than tortoiseHg, I might just uninstall that since it only works best on Windows - there's a problem with the windows api’s that cause the sub-context menu items to appear off the left edge of the menu - I'm going to take a look into that.)

PuttyGen

  1. GitHub only uses ssh and https (Bitbucket also uses ssh and https), so you only need to do this for GitHub or if you want to use ssh, which is cooler so why wouldn't you.
  2. Do you already have a key pair generated? Look for a .ssh folder.
  3. Create a key: programsàtortoiseGitàputtyGenàgenerate
  4. make sure that you do not already have %userprofile%.ssh folder, click show hidden files in folder options, or in cmd shell use dir .* to list all dot folders.
  5. Save keys in %userprofile%\.ssh (you need to make this directory in cmd shell, mkdir .ssh
  6. Copy the text in the window of your public key and paste in a file, this is what you will paste into GitHub or Bitbucket.

Shell

Have a look at Console2 by bozho - it's my favorite! Also set up Meld as your diff/merge tool, beyond sweet!

Success!

More links on ssh/putty

  1. Just the last part: Bitbucket Documentation: Set up SSH for Mercurial
  2. Didn’t read this: TGit wiki: UsingPuTTY

JSON Jumble

The org.json library on json.org website has been recently updated, and it is far simpler to use than jackson, json-simple, gson or others. However, the org.json library included in the Android SDK is not exactly the same, probably since it's from API 1 (before Cupcake?), and doesn't have a stream reader. But wait, API 14 has a new android.json library with JSONreader and JSONwriter classes - couldn't be easier than that!

Remind me to copy some good JSON links here.

TortoiseSVN could be a DVCS

I've been using SVN for years, but it's about to become obsolete? Hard to believe, but Git's popularity is surging rapidly, and so are other distributed version control systems like Mercurial and Bazaar. But I just can't believe that Subversion can't adapt to the changing times. There are so many SVN users out there. And I really think TortoiseSVN (TSVN) is the key. With the very simple scripting I was able to duplicate a DVCS with 2 TSVN repositories. The basic idea is that each person, clones/forks an entire repository, which is stored on there machine. Now in SVN, these repositories might be able to sync with each other, but a repo can't be a mirror and a working copy at the same time. So the trick is to save the diffs and patches and play them back in order. I think the patches should be named with hashes just like in Git and Hg. Easy!

Update (2012-01-12): After thinking about this and rereading the response from Stefan King on the TSVN dev mailing list to my question about DVCS, I realized or starting to think that this was really an issue for SVN. Think about my experiment below, what commands are TSVN? None, they are all from SVN. So I searched the SVN mailing list for "DVCS" (zilch for DVCS on the TSVN mailing list) and I saw this article posted 2 years ago, Subversion Vision and Roadmap Proposal, which has a pretty compelling argument for not making SVN a DVCS; in fact it even made me question DVCS in general. Then I thought, what is the main feature of DVCS that trumps a centralized repo, and I think it's offline commits. Searching for "offline commits" I found this post, On Offline Commits and Why They Should Be Piloted in TSVN. Funny because the strategy was very similar to my experiment, but I haven't found any other work toward this goal. Oh well - I've already migrated to git (see label: git going) and git svn makes that super easy.

Here is an experiment I did to see if TSVN could actually act like a DVCS. It's incomplete and disorganzed, but it did work
  • Rationale:
    • Does anyone really care or want DVCS for svn?
    • especially when bzr, git and hg are already so good and can work with existing subversion repos!
    • but it would be sad to see tsvn go
      • there will still be many svn users
    • is offline the biggest strength of DVCS?
  • approach: 
    • need clone, push and fetch similar to other DVCS, leverage existing svn methods, pilot in tsvn
      • init a local repo
      • use patches to clone the remote svn repo to the local repo
      • work locally, commit locally
      • push to remote repo, replay all local patches on remote repo
      • fetch from remote repo, replay all remote patches on local repo
      • it works, but a lot of overhead, and overly simplified
  • notes: 
    • get log, date and author info and pipe to file output
      • svn propget -r <NUMBER/HEAD/etc.> -revprop svn:log
      • svn propget -r <NUMBER/HEAD/etc.> -revprop svn:date
      • svn propget -r <NUMBER/HEAD/etc.> -revprop svn:author
    • create diffs of local and patch to remote and vice versa
    • use export from remote to local
    • svn log also prints log messages and pipe to output, instead of propget
    • svn merge?
    • svn help and svn help command

Android Angst

Who knew to use the internet you have to ask the manifest for permission. Everybody but me. I spent nearly two hours dissecting my disgustingly disorganized dribble trying to find the cliche in the code, and it turns out there wasn't one. I finally pinpointed the problem with the BufferedReader, which thew an unknown host exception. Googling this led me to our savior, a Stack Overflow post, gratefully labelled Android: Unknown Host Exception, which although solving a slightly different dilemma had the answer I needed. In order to use the internet, you must have


<uses-permission android:name="android.permission.INTERNET" /


in your manifest.xml file. The easiest way to do this is with the eclipse plugin, just go to the manifest's permissions tab.


Of course I totally skipped the manifest section of the dev guide, so I have only myself to blame. Checking through the android sdk site, I did find a section on Building Web Apps, that I had already looked at, that mentions this requirement, although not in exactly the same context.


I really need to read through the entire dev guide. And maybe finish the java trails. And, and, and.

Sunday, January 8, 2012

Git going

This looks like it might be useful.
Pro Git - Table of Contents
I'm trying to plan my git workflow, after using svn for so long.

Wednesday, January 4, 2012

Casting an Object class

Object class is an unknown return, but you can cast it using:
NewClass objNew = (NewClass)objOld;

Fork me on GitHub