andhapp Random ramblings

Remove remote branch info locally from git

You use git for version control.

You got a new feature to write.

You do the work and push your work into a new feature branch.

Open a PR for your work either on BitBucket or GitHub or anything else.

PR gets merged and the remote branch is deleted.

But, wait, you have the remote repository still listing locally when you run: git branch -r

Now, I don’t want it. Once the branch has been disposed of remotely, it has no business on the local machine.

There are two ways to get rid of it.

  1. Remove all remote branches deleted remotely with this command: git remote update origin --prune

  2. Remove just one branch locally: git remote prune my-new-feature

There is however a subtle difference in the two, i.e. you can pass options to the latter command to execute a dry run before actually doing it, like the command below:

git remote prune -n my-new-feature

Hope it helps!

Selenium WebDriver and starting Safari in a clean session state

I first used selenium on a java project a while back. Since then selenium has grown by leaps and bounds. With continued support and a myriad of bindings, it’s a tool to go to for automated testing. However, it does sometimes stumps you with nuances you’ve not seen in the past. One such quirk I came across this week was starting safari in a clean session state. Unlike Chrome and Firefox, it’s impossible to start safari in a clean session state. A clean session state means devoid of any hangovers, cookies, for instance is a good example.

The project I was working on was set up with cucumber features using capybara that in turn uses selenium webdriver’s ruby bindings for communicating with the browser. Like any astute developer, I googled for solutions.

Beware! Google search for ‘safari in clean session state’ may throw you off into a completely different direction. Here are some of those solutions that won’t work.

  1. Pass clean_session state as true as an additional option when a new capybara driver is registered for Safari. However, this will not work. Because, there’s a comment in selenium webdriver’s code pointing out the fact that it’s still outstanding.

  2. Open Safari with different flags like -n -b -F. This doesn’t work either. Even if it did, you will have to delve deep in selenium webdriver land to pass that option in and monkey patch a solution for this. Thankfully, it doesn’t work because monkey-patching is never a reliable way to fix bugs.

So, what’s the solution?

Well, the only way to fix it is by deleting the cookies before a feature run. Typically, add some code to delete cookies in a before hook for capybara to run before each feature.

It took a lot of trying, experimentation and patience to find this solution and sincerely hope it helps someone.

Passing parameters to Angular providers in configuration phase

Providers are probably the most significant concept in Angular 1. Services and factories use providers underneath, which makes it even more powerful. Anyways, Angular 1 has two phases in it’s lifecycle - configuration phase and run phase. Providers are initialised in the configuration phase. In this phase none of other angular services, like, $http, $location and so on are available to use. I had to pass some values to a custom provider and the only way you can do it is through the config defined on the module.

I never knew you could do that and this tiny post is just a note to self as a reminder.

Python2 not found error on installing emscripten on Mac OS X (Yosemite)

On the weekend, I needed to use a C library and decided to give node.js a try as I have been spending more time in the JavaScript ecosystem. Google revealed few ways to connect to a C library from node, namely, node-ffi, emscripten and so on. Node-ffi is similar to ruby-ffi and is a wrapper around libffi.

Given that I have used ruby-ffi in the past, I decided to give emscripten a try this time around. The installation guides are spot on and work like a charm except for one minor thing. For some reason, on running the emscripten (using ./emcc command) it complained about not finding python2. Not sure why it’s looking for python2 in the PATH, but I created a symlink to the installation of python in /usr/bin and called it python2 instead.

Hope this simple fix doesn’t cause any more issues later on.

Responsive is the flavour of the month

You don’t have mobile and desktop anymore.

You have devices!

Small devices equate to mobile, medium ones to tablets, large to desktops and extra-large to retinas. I understand the whole responsive thing to an extent but to learn a bit more about the tools and techniques out there, I took the Responsive Images course at Udacity. It was to the point, concise and free. Here are a few things I picked up:

  • SVG Optimiser
  • pixel density across different phones
  • Picture element and the srcset attribute to provide a list of fallback options to the browser. srcset passes the responsibility of downloading and rendering the right image for the right device.
  • calc for figuring out the margin and width dynamically.
  • There’s an easy way to create your responsive images via grunt. I couldn’t find a similar thing for webpack, as webpack works quite differently from grunt (or gulp).

All in all, I enjoyed going through the videos and doing the exercises and highly recommend it to anyone feeling a bit weak on the whole responsive thing.