[GIT] How to replace the master branch with another branch.

TL;DR;
git checkout master
git reset --hard fixed-master-branch
git push origin master -f

Sometimes someone may pollute the ‘master’ branch and you may have noticed this only after you’ve fetched, rebased and pushed your commits.
So your history may end up like this (I’ll use decimal numbers on the commit IDs for illustrative purposes only):

commit: 87
Author: me
A good commit

commit: 86
Author: other guy
Merge: that brought back a lot of crap because they probably used some GUI based git client and they did a git pull without your permission

commit: 85
Author: other guy
Another commit that shouldn't be here

commit: 84
Author: me
Another the last good commit

Now, your master is all effed up and you’re about to have an anxiety attack. What you want is to have this in your git log.

commit: 87
Author: me
A good commit

commit: 84
Author: me
Another the last good commit

To get back to this state is pretty easy:

  1. Check out the last good commit

git checkout 84

Now you will be detached from master, let’s name this temporary branch ‘fixed-master-branch’

git checkout -b fixed-master-branch

Now the last commit you should see should be commit 84.

Let’s now bring our commit, and skip the 2 sucky commits

git cherry-pick 87

Now your ‘fixed-master-branch’ branch looks exactly how you want the master to look like.

But now, you want to replace the old master with the new one.

Go back to the broked master

git checkout master

And fix it, and fuck all that merge –strategy ours BS advice you will find on StackOverflow as it will leave the git log history really weird.

git reset --hard fixed-master-branch

Now when you look at your history, master will be the same as ‘fixed-master’, and to fix your remote repo, you will have to make a push –force and let everyone know that you did that because you needed to clean your repository’s history

git push origin master -f

You’re done.

How to import a backed up wallet in Bitcoin-Qt

The Bitcoin-Qt client has an export feature, but not an import feature, importing a wallet is a bit of a manual process and it can be quite scary for the non-computer saavy since you need to do this kind of stuff because you got a new computer or your old one broke.

First, close the Bitcoin-Qt client.

Then you have to localize your Bitcoin folder. For Windows, it should be here:

%APPDATA%\Bitcoin

In that folder, there should be a wallet.dat file.

If you have currently no bitcoins in your wallet, you can just delete that file and replace it with your backup.
If you have some bitcoins in this wallet as well, backup that wallet file as well, or send all the coins to an address from your backed up wallet.

When you placed the other wallet.dat file in place, you should run Bitcoin-Qt with the -rescan option. Here’s how to do that in Windows:

Go to C:\Program Files (x86)\Bitcoin using Windows Explorer.

In that folder, hold shift and right-click and select “Open command window here”
1

In the command prompt, type bitcoin-qt.exe -rescan and hit enter
2

Now Bitcoin-Qt should start and rescan the blockchain to calculate the balances of the addresses in your wallet.dat file.

How to add an existing GIT repository to github.

Most of the times, it makes more sense to start working on something that slowly transforms into the beginning of a project that deserves to be on github. This post is about creating a local repository and putting it on github.

1. First we must convert the main local folder into a git repository. For this example let’s call the folder “my-new-project”. With your terminal go to that folder and type:
[bash]git init[/bash]

the repository will initialize but nothing will be added to it yet. If you type git status you will see all the things you can add to it, so use git add to add the folders you want to track, and then go ahead and do a git commit -m “initial commit”

2. Now go to github.com and create your repository “my-new-project”, and copy the clone url of the repo, I personally like to work with the one that starts with “ssh://” since I like to work with ssh keys and not have to deal with passwords.

You can easily configure your ssh certificates for multiple things, not just github but keys for many many servers working with the ~/.ssh/config file (no need to deal with effing ssh-agent).

If you created this github repository with some other account, make sure to give yourself contributor access on the github role settings, otherwise you won’t be able to pull/push.

3. Time to pull (fetch+merge) the remote repo and then push this baby up.
You do that by invoking the following commands (let’s suppose the remote url is git remote add origin git@github.com:myaccount/my-new-project.git):
[bash]git remote add git@github.com:myaccount/my-new-project.git
git pull origin master[/bash]

you should see something like below coming from the remote repo’s master branch:

[bash]warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From github.com:myaccount/my-new-project
* branch master -> FETCH_HEAD
Merge made by the ‘recursive’ strategy.
.gitignore | 6 ++++++
README.md | 2 ++
2 files changed, 8 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md[/bash]

and then just
[bash]git push[/bash]

and you’re done, you should see your initial commit on github now.

How to resize a VirtualBox fixed size virtual drive (.vdi) on Mac

So you created a disk for your Windows or Linux VirtualBox VM and you made the mistake of not creating the drive as a dynamically expanding storage drive, you chose fixed size.

Now you’re running out of space and all your Google searches point you to stupid posts on the virtualbox.org forums that lead to nowhere, specially if you are a MacOSX user, look no further, you’ve found the solution to your problem on this post.

VirtualBox for Mac comes with a tool called VBoxManage, this tool is all you need to resize your virtual disk.

When you’re using the VBoxManage tool make sure your VM is not running, stop it completely to be safe.

Step 0. Backup your current drive (optional)

I recommend that before you do anything you clone your existing drive, just in case…

You can clone your drive using guess what? yes, the VBoxManage tool. No need to download any external tools.

[bash]$ VboxManage clonehd <path to your original drive> <path of the copy>[/bash]

in my computer it looked exactly like this:

[bash]$ VBoxManage clonehd /Users/gubatron/VirtualBox VMs/windows7-64bit/windows7-64bit.vdi /Users/gubatron/windows7-64bit.cloned.vdi
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%[/bash]

If you don’t know where your .vdi file is, it’s very simple, right Click your VM > Settings > Storage, and mouse over the .vdi to see it’s physical location on your Mac hardrive.


Mouse over your virtual drive if you don’t know its location

Step 1. Resize!

The command to resize is:
[bash]$ VBoxManage modifyhd <path to your vdi> –resize <new size in megabytes>[/bash]

In my case I had a 20GB drive that I wanted to double in size (40GB), a quick Google search for “40GB to megabytes” yields the number 40960, so that’s what I put on my –resize parameter.

This is how it looked for me:
[bash]$ VBoxManage modifyhd /Users/gubatron/VirtualBox VMs/windows7-64bit/windows7-64bit.vdi –resize 40960
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%[/bash]

The ‘resizing’ is almost immediate.

Step 2. (Re)Start VirtualBox

After you’ve physically resized your drive, both VirtualBox and your OS should know about the changes.

At this point, clicking on your VM in the VirtualBox window will show that it still has the old size:

Before: (Note the size of the drive at the bottom of the image)

After doing the resize, shutdown completely your VirtualBox, and launch it again. When you see the information about the storage drives attached to your VM you should see the new disk size.

After: (Note the size of the drive at the bottom of the image)

Step 3. Let your OS know the new logical size of the drive


Your OS is still not aware of the changes, you need to let it know about them

When you start your VM, it won’t know right away what the new size of the disk is, you’ll have let the operating system know that there is additional space it can use.

If your VM is running Windows 7, the way to let the operating system know that it can use the additional space on your drive is very straight forward.

Click on the Windows (Start) Icon on the Bar > Right Click on “Computer” > Manage (You’ll need to be an Administrator)

The “Computer Management” window will open, in it go to:

Storage > Disk Management > Right Click on the partition you want to extend.

Select the option that says “Extend”, a Wizard will open, just hit Next until it ends if you want to use the whole space.

After you’re done, if you refresh your “Computer” on the File explorer the resized drive should show right away

That’s it, enjoy and let me know how it went.

Credit Cards for Dummies

The recent news about the credit card interest rate hikes has reminded me to write this post about how to use your credit card and never get in debt.

If you recently got your first credit card, please remember these very simple rules.

  1. Don’t buy shit you can’t afford
  2. Always pay your balance in full

If you follow these simple rules, you won’t ever be affected by stupid interest rate hikes since you’ll owe nothing to the bank.

To explain a little further rule #2, when your credit card statement comes, DON’T EVER pay the “Minimum Amount Due“, pay everything you charged for during the last period, leave the balance in 0, it will give you a warm fuzzy feeling in your belly to know the bank won’t stick it up your ass anytime soon.

If you can’t pay everything you charged, it means you didn’t follow rule #1, shame on you!

Another tip, don’t use your credit card for the “points” or the “Rewards”, it’s all a load of crap.

Remember, a Credit Card is not Free Money. Believe it or not there seems to be a shitload of people out there that don’t seem to follow these 2 simple rules and now they’re “pwned” by the banks and crying to papa Obama.

Again…

DON’T BUY SHIT YOU CAN’T AFFORD, AND ALWAYS PAY YOUR BALANCE IN FULL

Analizing a succesful “Digger”

How many times have you tried to get a story on digg.com and it just won’t get anywhere, but then you see stories submitted only 45 minutes ago, and they’re already on the home page?

I decided to take a look at the profile of a successful digger and analize him a little bit.
It turns out, just as expected, Digging your way through takes a lot of work… or maybe a lot of time wasted, depends on how you see it.

Digg, Digg, and then digg some more


From looking at this guy’s profile (who actually had 2 stories on the homepage by the time of this writing), it seems one of the most important things are to Digg a lot, and have a lot of important friends on digg. He hasn’t really invited any friends to join digg.com, instead it seems he’s made friends with people that actually love digg, just like him. Those are the people that will actually be digging. Also, he doesn’t really comment much.


This has been my experience too, none of my real friends do digg.com, so having your real friends on digg and begging for diggs on your submissions is probably not gonna cut it, you need the support of diggers with some sort of popularity on the site. The same principle applies to stumbleupon.com if you want to become a guru.

Use other social bookmarking networks
If you check this guy’s profile, he’s also on StumbleUpon.com, Twitter, and del.icio.us. His Twitter and del.icio.us accounts aren’t that amazing, but his StumbleUpon’s is truly amazing considering he’s been digging so much. This tells me that he probably diggs a lot of what he stumbles and he stumbles a lot of what he diggs.

Check out his StumbleUpon.com stats