Collaborating using git: make merging less painful!

Hi, I’m Shafiul! Me along with Ibrahim & Sifat are working in a project which we maintain using git. We’ve decided to follow a simple protocol to merge our works effeciently in a painless way!

All of us will work in our own branches (learn first about branching if you’re not familiar with it). At the end of the day, the one who finishes his work after the rest of the team, should merge all of our works!

Say, after working all day long, I figured out Ibrahim was still working before I went to bed. So it became Ibrahim’s due responsibility to merge everyone’s work 🙂

The first step is: create a new branch for you, where only you will work, and no one else will touch.

Create a new Branch named “shafiul”:

git branch shafiul

To work in this branch, I need to check-out to work in this branch:

git checkout shafiul

While working, Commit any time:

git add -A
git commit -m "Message"

When you’re done, push your commits to the server:

git push origin shafiul:shafiul

Note the command: It pushes your commits made in local “shafiul” branch to origin’s (server’s) “shafiul” branch.

Like me, Ibrahim & Sifat has also crated their own branches named “ibrahim” & “sifat” and they’re working in their branches.


Merging everybody’s work

The one who will be merging has to do followings:
First, download everyone’s commits from origin (server) to his local machine:

git fetch origin shafiul:shafiul
git fetch origin ibrahim:ibrahim
git fetch origin sifat:sifat

Now time to merge. Check-out to master branch. With this branch, we will merge all other branches.

git checkout master

Now merge all other branches with master:

git merge shafiul
git merge ibrahim
git merge sifat

Cool! master is now merged with everyones code (Congratulations if no conflicts has occurred. But don’t get panicked if conflicts occur, to learn how to resolve conflicts, see the end of this article) – now Push your local “master” to origin (server):

git push origin master:master

Everyone’s duty: Update your branches…

The next day, before working, everyone should update their branches. First, everyone needs to pull updated “master” branch from origin (server) and merge it with your local copy of master branch:

git checkout master
git pull origin master:master

Now your local copy of master branch is updated. Finally, checkout to your own branch and merge it with updated master:

git checkout shafiul
git merge master

Source code of Android Tutorials from The New Boston

🙂

Get sources of tutorials of individual videos

I’m  just learning android from the awesome tutorials made by Travis (available for FREE at here) and decided to code them in hand. Just pushing them to this repo if anyone needs them.

One interesting point, I’ll make a commit after every tutorial! So you can browse the snapsot of each tutorial by selecting a commit from my Github

Cool, huh? (The initial commit begins with Tutorial 10, though).

Python MySQLdb equivalent for PHP’s mysql_insert_id()

What you’re looking for is lastrowid property of a cursor object.

Code:

import MySQLdb # MySQLdb module must be installed on the system
connection = MySQLdb.connect(...) # Details skipped
cursor = connection.cursor()
query = "INSERT INTO ... " # put query here
cursor.execute(query)
print cursor.lastrowid # BINGO! This will print the id (auto-increment column) of the last inserted row
# Other codes here

Thanks to this article on the Internet

Drupal: Write & Execute PHP code in blog post/forum content entry

This is a short but efficient trick that I found after making some stupid search queries 😦 In Drupal 6 & higher, you can type & execute PHP codes in your blog posts/ other contents. To do so, First enable the PHP Filter module from your Adminstration > Modules section:

(drupal-path/admin/build/modules)
php filter module

Enabling the PHP Filter module

Next, you can configure who must have access to execute PHP in their content. To grant only trusted users this permission, go to the Input Formats section (available under Administer » Site configuration)

(drupal-path/admin/settings/filters)

Next, click on “configure” link next to the php code box.

How to write php in your posts

When creating a new blog/other entry, click on the “Input Format” just below the text editor. From the available options, select php code. See the screenshot below:

php in drupal

Hope this will be helpful!

Auto Shorten dynamic URL by javascript

Live Demo

Thinking of using bit.ly Url Shortening service in your site? You can use a simple javascript code in any page of your site, specially if it is a dynamic page. For example, look at a dynamic page of my online code compiling site:

The link of a dynamic page is somewhat this: http://shafiul.progmaatic.com/hostcode/compiled.php?i=wRZWM&c=252&ext=11

The link is too long. So, I automatically shortened the links, and gifted it to the viewers! 😉

how to use bit.ly in your site

How to use bit.ly service in your site

First, you need an account on http://bit.ly. To create one, go to the site and register.

Once you’ve registered, login and go to your Account page. There, you will find your API key.

Now, we’ve all the resources. Let’s go to the code section

The Code

Between the <HEAD> and </HEAD> tag of your page, place the following code:

	
  • <script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=******&apiKey=*****************"></script>
  • Replace the first ***** by your bit.ly username and second ************** by your bit.ly API key!

    Now, place the following code anywhere of your page. It is nothing but a text-input field, where shortened link will be placed. You can use anything instead of a text area, perhaps a <div>tag to display the shortened link!

    <h3>Link to this page</h3><br>
    Use this link to tell others about this page! <input onclick = "this.select()" type = 'text' id = "qlink" style = "width:100%;">
    
    <br><br>
    
    

    Now, the final task. Place the following code just before </BODY> the tag of you page:

    <script>
    	// Bit.ly API
    	BitlyCB.shortenResponse = function(data) {
    			var sss = '';
    			var first_result;
    			// Results are keyed by longUrl, so we need to grab the first one.
    			for     (var r in data.results) {
    					first_result = data.results[r]; break;
    			}
    			sss = first_result["shortUrl"].toString();
    			document.getElementById("qlink").value = sss;
    	}
    	BitlyClient.shorten(window.location, 'BitlyCB.shortenResponse');
    </script>
    
    

    Yeah, you’re done! Now anyone entering the page with any query string, the link of the page with the query string will be automatically shortened 😀

    PHP Auto Sitemap Submit Script for Google Bing Yahoo or Other Search Engines

    Sitemaps are useful to tell search engines about different pages of your website. Once you submit a sitemap to a search engine, they can crawl all the links which you provided in your sitemap. So generating a sitemap for your website is very important. If you don’t have a sitemap for your site, create one by Google Codes or manually create one by Learning how to create a sitemap (it’s nothing but a simple XML file!)

    Now, there are two ways for making a scheduled update for your sitemap:

    Automatic: By PHP & Cron Job

    Download this PHP file. Give it a name, like “sitemap_updater.php”. Edit it to type in it the correct location of your sitemap. Now upload it to your server, suppose in /public_html/cron_jobs/ directory. Give the file a name, for example, sitemap_updater.php

    Now, go to Cron job section of your server from the Control Panel/Admin account of your hosting. If you’ve acces to Cpanel, you may click cron jobs like following:

    Next, click a option that suits you most. If you’re new, click standard

    Cron job - how to select method

    Cron job – how to select method

    Next we’re on the main panel. Select your schedule – how often you want to run the code. Then in the command to run box, type the following command:

    php -f /home/your-username/public_html/cron_jobs/sitemap_updater.php
    
    

    Look at the URL: /home/your-username/public_html/ replace it with appropritae location of your root directory.

    If you have a different location for the sitemap_updater.php file, type it accordingly. The following screen-shot might be helpful (ignore the command given in the image)!

    Cpanel how to execute PHP file as a Cron job

    More details on Cron jobs here

    Download the Sitemap_Updater.php file


    Manually Updating Site-maps

    Well, if you don’t have access to PHP/Cron jobs, you can manually update sitemaps. The trick is, we will create a HTML file, save it in our local disk, and run the file manually whenever we need to update the sitemap!

    1. Download this HTML file
    2. Rename it like something.html
    3. Open the file for editing, edit line # 5, give here your sitemap address. Save it
    4. Now whenever you need to update your sitemap, just open the HTML file in your brower! 🙂

    Well, that’s all. Rock with your sitemaps 😀