Chohdry

A blog by Kamran Chohdry

1 note

MySQL: How to fix “… is marked as crashed and should be repaired”

So you have received error as in title and are panicing now, here is a quick fix
  • Dont Panic, there are number of ways to fix it
  • Take a quick look at your backup first, if you don’t have any please for the love of Moon and Stars, have a scheduled backup plan
  • Take a backup of the current state of DB
    • Exporting from phpMyAdmin will NOT work, as you can check the exported file will have same error message
    • Try copying the whole data files (data folder in windows mysql installation folder OR /var/lib/mysql) in Linux
    • If all fails check my.ini for variable “datadir” for folder location
    • Copy the DB folder that needs repairing
  • Open phpMyAdmin, browse table list, select table(s), from drop down list in bottom select repair
  • Alternatively use this commandline: mysqlcheck —repair —all-databases
  • Be happy if you receive a success message
  • Set a backup schedule if you have not done so
  • Take a backup and try restoring locally, double check if it included ALL tables

Share this post if it helped you or comment with thanks.

Filed under mysql programming error fix disaster backup

0 notes

Visual Studio: Jumbled up Windows App in Display size 125% / 150%?

If you have created a Windows App (Application / Software I mean) and it is all messed up when displayed on a Windows 7 machine with display zoom set to 125% /150% here are a few things you can try.

  • First thing first, never design your UI while your system is at any display resolution other than 100%, unless you manage it properly to be displayed same on all zoom levels (see further steps to achieve this)
  • Make sure you create your app with flexible controls and add re-sizing procedure to appropriate events (specially Resize)
  • If however you have a fixed background that can not flex when you zoom in you should pick appropriate setting for Form.AutoScaleMode
    You can choose it to be either none (default on most systems), Font (resizeable controls expands in proportion to font size), DPI (resizeable controls expands in DPI % increase) and Inherit (usual zoom in effect, works best for fixed background)

The tips is generic for Visual Studio most versions (6.0, .NET, 2005, 2008, 2010, 2012) and not dependent on language choice as well (C#, Visual Basic (VB) / VB.NET). This also applies on older Windows version where you can set the DPI to 120 instead of default 96.

Filed under microdoft visual studio development UI windows

0 notes

[PROTIP] Google Apps Signup Error - Invalid Input

I was trying to signup for google apps for a company that has office in Kyrgyzstan and the form was coming back with error.

Invalid Input (right next to phone number)

I tried every way possible (at least I thought) to enter the phone number with no luck. A search on Google showed many unanswered similar queries. That is when I had an idea. I searched for the yellow pages for the country and searched for a random company. The listing came back with their phone number with following format:

(512) 123 - 2345

I reformatted my number on this and voila! it worked. So seems like whichever validator Google Apps is using it is using most used local format to verify (at least in this case). Best of luck if you have a similar problem.

Filed under google google apps error google apps error protip

38 notes

Programming Pitfalls - 002 - Structure your code logically

Second of the biggest trap new programmers (and some experienced ones) can fall into is not structuring their code logically. This might save you a few minutes when you are building something but should really be avoided. Not only you will save a lot of time in future but will also love yourself that you did something better. Things to keep in mind when programming to a better structure are:

  • Comment, Comment and Comment
    As somebody said before, comment your code as if your program will be maintained by a serial killer who knows your address. You would not mess with such a person so why risk it, comment all the things.

  • Your program should read better
    Your code should be written with your very junior colleague in mind. If you do not have a junior now just hope you will get a junior to help you out and your code should be structured easy enough for a student to read. Big hint: read comment, comment and comment again

  • Structured code makes it easier to find mistakes
    Your mind is a great optimiser and data compressor. Amazingly your mind has the the ability to skip information based on assumptions. For most of you, the brain would have assumed there is only one “the” in last sentence and skipped the second one. Similarly when you have very small but crucial spelling or syntax mistakes your mind can easily skip it unless you spot it due to character mis-alignment.

    Quick example:
    user_permissions = 0; user_permissoins = data; if(user_permissions<10) exit;
    vs
    user_permissions = 12;
    user_permissoins = data;
    if(user_permissions<10) exit;
    Which one you found easier to spot mistake in?
    Another example in Android SDK 

  • Structured code leaves no place to hide for that evil semi-colon
    It is one of the most time wasting issue when you can not figure out why your loop is not running.  

    Quick example:
    int_i = 0; for(i=0;i<10;i++);{ printf(“%d”,i);};
    vs
    int_i = 0; 
    for(i=0;i<10;i++);
    {
        printf(“%d”,i);
    };
     

  • Indentation makes code more obvious to read
    If you are going to logically analyse your code for mistakes you should better indent it logically. This is another one of benefits that are explained better with an example.

    Quick example:
    user_permissions = 10
    printf(“Checking permissions”);
    if (user_permissions>3) {
       printf(“Welcome user”);
     

  • Look out for false indentation 
    Carrying on with above logic, make sure you do not have false indentation on code that should not be indented. This is another one of benefits that are explained better with an example.

    Quick example:

    user_permissions = 10
    printf(“Checking permissions”);
    if (user_permissions>3)
       printf(“Welcome user”);
       printf(“Your permission level is good at: %d”,user_permissions);
     

  • Use indentation with blocks of code and use comments to specify start & finish of a block
    Generally the consensus is that each code block gets indentation, and a sub code block gets another indentation. If you think that it could get worse to read with 6 levels of sub-blocks then you should better worry about re-structuring your code logic to lesser sub-blocks. Never forget to comment the end of block. Specially in IDEs that do not auto highlight the ending of a block when you select the start of a block

  • Use a helpful IDE/Editor
    A lot of above issues can be reduced if you use an intelligent IDE/Editors. Some IDEs/Editors give your variable highlighted colour when you select a variable name. i.e. Notepad++, IntelliJ. Some of IDEs/Editors highlight block of code you are in or simply highlight the end of block when your cursor is on start of block. i.e. Notepad++ with plugins, IntelliJ, Dreamweaver, Eclipse with plugins

     


As always, if I remember anything else I reserve the right to edit my post later. If you think I have forgotten something please do message me.

Filed under programming learn development logic code

8 notes

PackageMaker - What do you need to know for migrating from XCode 3 to 4

Just a quick list for anybody who happen to come across same issues as me. If you have built an app and for some Godforsaken reason had to use PackageMaker following are things to watch out when moving your project to XCode 4 / Lion. (Yes you read correct, if you do not have to please please do not use PackageMaker, even Apple does not use it themselves)

  • XCode 4 output directory is now in Library

Not just that it builds your product in ~/Library it also creates a folder consisting of your productname-some_random_characters. Trouble with the folders in ~/Library is that these are not selectable in folder browser from PackageMaker (or elsewhere). It is also not guarenteed to work if you copy paste the complete path from Terminal. Copying the product does not copy everything needed and will fail the installer build as well.

There are two ways to change build location:

  1. XCode > Preferences > Locations (Change the default to Relative for a subfolder in workspace or Change to custom for a custom location) - this change is global and recommended.
  2. File > Project Settings > Build (similar changes as above) - this change is per project basis.
  • Double check location of resources and images

PackageMaker will not always give a helpful error if you have changed your core path of resources and product. Make sure you check path on everything including but not limited to Interface Editor - Background, app (as explained in first step), any other files and scripts.

  • Triple check location of scripts / jump into XML

If you have pre-install, post-install scripts then not all settings are changed (annoyingly) when you edit the path to your scripts in PackageMaker. Specially post-flight path in many cases. If you are still getting “Script not copied” error then you need to right click Project.pmdoc and click Show Package Contents and then double check paths in .xml files in any text editor. Re-open your PackageMaker file to try.

As always I will add anything if I remember, leave me a note if I saved you some time or if I forgot something. 

Filed under programming xcode mac packagemaker

11 notes

Programming Pitfalls - 001 - Name your variables sensibly

I promised myself about ten years ago that I would start writing about programming pitfalls, you know common mistakes programmers make. Sometime these mistakes are very common, silly and minuscular. So much so that you want to hit your head to brick wall while you are figuring the issues out and hit your monitor with your head when you find out where you were going wrong. Let’s start here, shall we, I am already ten years late:

Name your variables sensibly

  • Explain what it is in a quick look.
    year is a bad choice, current_year is better. You might think that in this small snippet of code there is only one variable that holds information like this, you will come to regret this when the project scales.

  • Avoid generic names including banana, potato, i, j & k.
    First ones because you are really not storing a banana or a potato
    Second ones because using loop_i or i_records makes more sense and are more searchable

  • Not too short that it loses meaning in few days when you revisit your code.
    rs1 is a really really bad choice, rs_students is much more sensible, again you might know each and every cryptic variable now that you are working on it. You will come to curse yourself in as few as 1 day when you come back to a piece of code with bananas and potatoes

  • Not too long that it becomes overkill, I am looking at you ObjectiveC ಠ_ಠ.
    students_manager_view_records_record_set_students : please just don’t, first we know we are in student manager application and secondly we are in view records controller, so record_set_students becomes longest sensible version

  • Follow the convention even if you have to ignore my last advise, when in ObjectiveC NameAsObjectiveCWillNameThings.
    Weather it is snake_case or the CamelCase pick one that is more conventional to language, framework or team you are working with and stick to it. student_age = current_year - DateOfBirth_Year breaks so many pro-codes in a single lines
    I personally prefer snake_case and will recommend it if you are at beginning of a project and can make the choice

  • Specify data type, it might help you identify mixed up names far quicker
    Speaking in office about this blog post, James Matthieson reminded me of this good technique. You basically add the prefix of data type to your variable name to avoid confusion when using these variables. int_current_year and str_student_name are good examples.

I will be adding more as I remember these

Filed under programming lessons

3 notes

Today is the day, the day I will fight,
Today is the day I take back my right.


Today is the day, I stand up and tall,
Look them in eye, make them fall.


Today is the day, I shout; I have a voice,
Whatever freedom takes, I’ll pay the price.


Today is the day, this white dove will roar,
You can take only one, we are but many more.


Today is the day, I need you to stand by me;
It won’t take much effort and we will be free.

- by Kamran Chohdry
… inspired by worldwide revolutions
… dedicated to youth of today who are striving hard to bring a change

Filed under poem revolution inspiration

35 notes

Running GitHub (GitLabHQ) / Source Control Manager (SCM-Manager) on your own server

This is not going to be a tutorial I am afraid, just a quick overview of a couple of projects.

SCM Manager

SCM manager claims to be

“The easiest way to share your Git, Mercurial and Subversion repositories over http.”

and quite rightly so. After trying gitolite, gitosis, svn+apache and a few other options manually and managing to run all I got a nice surprise when I tried SCM Manager. Most definitely the easiest way to do it. But wait, there is more:

  1. SCM Manager supports Central user, group and permission management, I have tried creating developers group and can easily put as many users I want into developers and they get all needed permissions automatically on all repositories. 
  2. SCM Manager is not limited to one platform, it supports both second and third generation version control systems, naming: Git, Mercurial and Subversion, all from just single install, this promise includes no need to install Apache or DB server
  3. It provides full RESTFul Web Service API (JSON and XML), Simple Plugin API and there are quite a few useful plugins available ( f.e. Ldap-, ActiveDirectory-, PAM-Authentication)
  4. Installation is very easy and so is management, you do not need to mess with any config files. The interface will let you configure everything. There is however marmite on top of this slice of bread, the interface is in Flash, so you will either love it or hate it.

Correction: I am a lazy guy for not checking above about Flash and making assumptions, the interface is built with pure HTML, CSS & extjs3 and Sebastian is a nice guy for mentioning it very politely.

I hope you are hyped up enough to give it a try, SCM Manager is hosted on BitBucket

GitLabHQ

Disclaimer: I have not tried this enough to give a fuller review as SCM Manager above, expect an update in next year.

This is an up and coming clone of GitHub, the idea and interface looks promising. The install is easy enough (albeit it runs on rails, I know few of you complained before about how difficult is to set the environment up). There is even a demo online for you to try GitLabHQ demo online

Start downloading GitLabHQ and give it a try:  

Project updates can be found from GitLabHQ twitter account

Filed under source control development svn git mercurial scm-manager gitlabhq