Thursday, 31 May 2012

git: revert (reset) a single file

CREDITS TO:

http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file

This one is hard to find out there so here it is. If you have an uncommitted change (its only in your working copy) that you wish to revert (in SVN terms) to the copy in your latest commit, do the following:
git checkout filename
This will checkout the file from HEAD, overwriting your change. This command is also used to checkout branches, and you could happen to have a file with the same name as a branch. All is not lost, you will simply need to type:
git checkout -- filename
You can also do this with files from other branches, and such. man git-checkout has the details.
The rest of the Internet will tell you to use git reset --hard, but this resets all uncommitted changes you’ve made in your working copy. Type this with care.

Wednesday, 30 May 2012

who knew

CSS classes have hierarchy. The lower you put them in a file the more priority they have.

Tuesday, 29 May 2012

The burnout... not that it will ever hapen to me

CREDIT TO:

http://www.codingninja.co.uk/logout-before-you-burnout/


Burnout amongst software engineers is a real danger. Years ago when I had first heard about “burnout” I brushed it off as a myth. After seeing it first hand and experiencing a little burnout myself, I can attest it is indeed real.
Software engineering demands a high level of concentration. Debugging software and troubleshooting complex problems are mentally taxing. It is in the nature of most developers that we tend to fixate on a particular problem until it is resolved. In this mode of operation it is not difficult to end up working overtime a lot. Being persistent is good, but it may come at a cost.
Putting all the focus on our work means that other things get relegated to the background. While this is not a problem in the short term, in the long run it can become a problem. Working all those extra hours, means there is less time to rest. As a result tiredness creeps in; instead of acting on natures red flag we try to counter it. Use of stimulants such as energy drinks and coffee are taken to combat fatigue. However continued use of stimulants may lead to prolonged fatigue.
When work becomes the main focus engineers may start setting unrealistic targets and goals to achieve high ambitions. If targets are missed or not reached, when questioned by co-workers or management, the response can often be met with aggression because we lack clarity to see the real reasons for failure. We will not notice a change in our behaviour and mood but others certainly will. Continually missing targets and goals can slowly turn this initial anger to self doubt.
Instead of turning for help, we can turn inwards. Self doubt can start to creep in. Why can’t I reach these goals? It must be my fault! By blaming ourselves and self criticising we devalue ourselves.  Continued devaluation may lead to negativity, hopelessness and depression.
In hindsight it looks like common sense. Burnout may not be detected early on as it is something that happens gradually over time, and the signs can easily be missed.
By making changes in our working habits it may be possible to avoid burnout in the long run.  The following are suggestions of positive habits:
  • When the office closes, stop working. Tomorrow is another day.
  • Don’t think about work at home, relax and do fun non work related things.
  • Set an alarm to go to bed, yes the opposite of waking up.
  • Reduce the amount of coffee intake, if you’re feeling tired try and get some more sleep.
  • Take up some physical activity; play sports with friends or hit the gym.
Summary
The causes of burnout may not be consistent between two people. There are no “silver bullet” cures for burnout. We need to be more vigilant and notice negative patterns. If any symptoms are spotted, it may be wise to start closely paying attention to them and addressing them. The very first step would be to logout, switch off and take time off.
“Logout, before you burnout”

Thursday, 24 May 2012

Mongodb repair for Ubuntu

CREDIT TO:
 
 
I've have this problem for a couple of times now. I am not sure why but i found this easy fix and it works.
 
This evening I tried to connect to my MongoDB instance using the command line mongo tool and got the following error message: Error: couldn't connect to server 127.0.0.1} (anon):1137. It turns out that the server wasn't running due to an improper shutdown at some point in the past. Here's what you need to do to fix it.
Note: my instructions are specific to Ubuntu 10.04 (& probably other versions of Ubuntu).

Why Won't MongoDB Start?

One of the lame things about MongoDB is that it doesn't handle a crash on it's own very well. If the database crashes or otherwise doesn't shut down properly, then the next time you try to start it, you'll get a nice error saying that there is an old lockfile and that you probably need to remove it and run mongod --repair. However, on my laptop running Ubuntu 10.04, I ran into a few confusing things that I'd like to share, hopefully to save someone else out there some time.

Symptoms

  • Try to connect (type mongo on the command line). You should get a connect failed error.
  • Verify that MongoDB is not running. Run sudo status mongodb. It should report mongodb stop/waiting.
  • Verify that you are unable to start MongoDB. Run sudo start mongodb. It will report mongodb start/running, process XXXX no matter what. But if you run sudo status mongodb again, you'll get stop/waiting.
  • Check your logs to see that you in fact have the same problem as me. Your logs should be at /var/log/mongodb/mongodb.log. You should see an error like this:
    ************** 
    old lock file: /var/lib/mongodb/mongod.lock.  probably means unclean shutdown
    recommend removing file and running --repair
    see: http://dochub.mongodb.org/core/repair for more information
    *************

Instructions To Get MongoDB Up Again

  • Manually remove the lockfile: sudo rm /var/lib/mongodb/mongod.lock
  • Run the repair script: sudo -u mongodb mongod -f /etc/mongodb.conf --repair.
    • You must run this command as the mongodb user. If you run it as root, then root will own files in /var/lib/mongodb/ that are necessary to run the mongodb daemon and therefore when the daemon trys to run later as the mongodb user, it won't have permissions to start. In that case you'll get this error: Unable to create / open lock file for lockfilepath: /var/lib/mongodb/mongod.lock errno:13 Permission denied, terminating.
    • On Ubuntu, you must specify the configuration file /etc/mongodb.conf using the -f flag. Otherwise it will look for the data files in the wrong place and you will see the following error: dbpath (/data/db/) does not exist, terminating.
  • Now you can start your MongoDB server with sudo start mongodb and verify it is running with sudo status mongodb and by trying to connect to it with mongo test.

Thursday, 17 May 2012

Ten thinks you didn't know about rails

I found this interesting rails ten things you didn't know.
I have learn a few things. Enjoy.



Iphone and Viewports

Operating System:
Iphone OS

Problem:
Because of some google analytics problems when a user browse a page with an iphone i was required to show a popup telling the user's that there is a app for the website and when you close it to show the old page.

Soution:

<<hide the page>>
$('meta[name="viewport"]').attr('content', 'width = device-width, maximum-scale=1.0;');
/*width = device-width show the smaller popup as fullpage. maximum-scale=1 dosen't allow the  popup to be zoomed in. */
<<Show popup>>
on close popup
<<show the page>>
$('meta[name="viewport"]').attr('content','width='+$(window).width() + ', height=' + $(window).height() + ', initial-scale=0.5;');

/*Set the content width to windows width and height as well. With the initial-scale you can play arrow. That is the value i found works best in my particular case*/

Resources:
https://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html - official apple doc. You can see the description for every value of the viewport there.

What have i learned:

Programming Javascript for Iphone OS and Android is very hard. They are very picky. I very big problem that i have was that after i close the popup the viewport use to leave a dark impression on the page even if it scrolled out. I have no idea how i managed to get ride of that but i finally did. Keep trying to swich around the values until they work.

Friday, 4 May 2012

Installing eventmagine 0.12.10 with ruby 1.9.3 on windows 7

Operating System:

Windows 7

Problem:

I was required to install the eventmachine 0.12.10 with my ruby 1.9.3 on windows 7

Solution:

Sorry, it's just not possible. Not as much as i could figure out. I simple installed Ubuntu and everything was ok. Maybe by the time you are reading this it will be possible but at the moment on Windows 7 the only solution is to have a older Ruby version or get the "gem install eventmachine -pre" to get the newest version of eventmachine.

Thursday, 3 May 2012

Moving a Mysql Database File Windows 7

Operating System:

Windows 7


Problem: 

So i have installed a huge MySQL database on my main drive which is very small and after everything was finished i had even fewer space left. So i had two options either moving the database or importing it again. Since it took about 4-5 hours to import it it would have been a waste a time so the only thing i could do was move it.

Solution:

Stop the server.

If you install MySQL like me without looking the data files are in C:\ProgramData\MySQL\MySQL Server 5.5
Move the data file in this folder.
Edit the my.ini file (remember you have to be a administrator to actually edit the file so open as administrator).
Change this line: "datadir" with the new location of the data folder

Restart the server.

Hello Ladies and Gentelmen

I will attempt to write in this blog all of the problems i have encounter during my next few years while i am learning ruby on rails. Most of the blogs will be related to Ruby and Ruby on Rails but there will also be design problems, MySQL and whatever i might encounter that i find interesting enough to share with the rest of the world.

Please feel free to correct me if you find errors or better solutions.