Posts tagged interviewstreet-dev
Vim tutorials
0
VIM is an awesome editor, but comes with a big big learning curve. These are the the top 3 Vim tutorials from where I learnt to use Vim.
1. http://www.vi-improved.org/tutorial.php
2. http://vim.runpaint.org/toc/
3. http://www.swaroopch.com/notes/Vim_en:Table_of_Contents
If you want to learn more, checkout http://thomer.com/vi/vi.html#manuals
Git reflog and git force push
0
Git reflog saves you from all screw-ups you do while using git.
Here is a sample output of git reflog.
hari@hari-desktop:/var/www/recruit$ git reflog
e458f54 HEAD@{0}: checkout: moving from test1 to e458f54fe99202c82c2690be4fa2fe2d7aa7be32^0
a3281d1 HEAD@{1}: checkout: moving from master to test1
f265802 HEAD@{2}: checkout: moving from test1 to master
ef08492 HEAD@{3}: ORIG_HEAD: updating HEAD
e458f54 HEAD@{4}: commit: Implement phpunit testcase.
1ecf2c3 HEAD@{5}: commit: Bug#1 : MCQ Choices displayed in questions.
f265802 HEAD@{6}: checkout: moving from test1 to f265802d1d65a9ac92bf9f6414d8f468444cce66^0
ec280c6 HEAD@{7}: checkout: moving from release to test1
f265802 HEAD@{8}: merge master: Fast-forward
ccec6c4 HEAD@{9}: checkout: moving from master to release
All your commits, checkouts, pull, merges are logged in here. To, reset the git to any point in there, we use the following command.
git reset --hard <commit-id>
But if you push this to the git, you will find that the commit is rejected now. To forcefully push your new HEAD to server, we use the following command.
git push origin +<branch_name>
+ before the branch name forcefully pushes the branch (even if your current branch is behind the origin).
NOTE: Please be careful when you use the command above. You might lose all the changes made by others (temporarily) if you use it. Of course, using reflog + reset, you can get back the changes.
Compare branches in git
0
Want to check if all changes in your new branch is merged to main branch before you delete the new branch.
git log feature1 ^master
The above command displays all commits which are present in feature1 and not present in master.
Note 1: You can also try “git branch -d feature1″. If the new branch is not totally merged, git won’t delete the new branch.
Note 2: You can also try “git branch –contains feature1″, but I’m not sure how that works. I guess I’m happy with git log for now.
To read more about this, checkout http://stackoverflow.com/questions/1710894/using-git-show-all-commits-that-are-in-one-branch-but-not-the-others
Delete a remote branch in git
2
We use Git here at interviewstreet. Using Git, branching, testing and reverting is so easy.
Almost all commands are simple and easy to remember in Git, except for deleting a remote branch.
The command to delete a remote branch “feature1″ is
git push origin :feature1
Just wanted to note this down.
Query String in URL using Codeigniter
0CodeIgniter by default won’t allow you to use query strings in the URL.
This is how you enable query string in url in codeigniter.
1. Set $config['uri_protocol'] = “PATH_INFO” in config.php
2. Set $config['enable_query_strings'] = TRUE in config.php
3. Make you sure you have QSA in your .htaccess. For example,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|includes)
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
Note: If you make these changes, the pagination module is affected. So, if you had implemented any pagination before changing these settings, you might want to check them again.
Importing Contacts from Google Mail using OAuth
3This is my second post in the fetch contacts from email account series. In this post, we are going to fetch contacts from a Google account. This isn’t a detailed tutorial, but a quick 2 minute how-to.
$this->config->item(‘google_return_url’) is the url of the page to which user is returned after a login attempt.
1. Add the following code where the user has to select Google Mail to import contacts.
<a href="https://www.google.com/accounts/AuthSubRequest?next=<?php echo $this->config->item('google_return_url').'?data=abc'; ?>&scope=http://www.google.com/m8/feeds/contacts/default/thin&secure=0&session=1">Fetch Google Contacts</a>
2. Include these 2 functions in your PHP code.
function make_api_call($url, $token)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlheader[0] = sprintf("Authorization: AuthSub token=\"%s\"/n", $token);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlheader);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function get_session_token($onetimetoken)
{
$output = make_api_call("https://www.google.com/accounts/AuthSubSessionToken", $onetimetoken);
if (preg_match("/Token=(.*)/", $output, $matches))
{
$sessiontoken = $matches[1];
} else {
echo "Error authenticating with Google.";
exit;
}
return $sessiontoken;
}
3. Add the following code to the return url file.
$sessiontoken = get_session_token($_GET['token']);
$contacts = make_api_call("http://www.google.com/m8/feeds/contacts/default/thin?alt=json&max-results=1000", $sessiontoken);
$contacts = json_decode($contacts, TRUE);
foreach ($contacts['feed']['entry'] as $contact)
{
$emails[] = $contact['gd$email'][0]['address'];
}
//$emails array has the email addresses of all the contacts.
4. That’s it folks. It is that simple.
Further reading :
1. http://code.google.com/apis/contacts/
2. http://code.google.com/apis/contacts/docs/3.0/reference.html












