Compiling and Running C files on Ubuntu
Create a c file, for example, “Hello.c” save it somewhere. Now, start the terminal and compile this file first like so
gcc hello.c -o hellooo
This command will basically compile the hello.c file and create an output file (using the -o) which is executable called as hellooo. In order to run this executable file, you need to type
./hellooo
That’s it.
Install all in 1
Find yourself writing too many terminal commands after every time you re-install your linux. Install necessary stuff.
sudo apt-get install php5 php5-curl vim mysql-server phpmyadmin mercurial vlc vlc-plugin-pulse mozilla-plugin-vlc
Just save this as installMe.sh and run it.
Take Advantage of Social Connections. Adam D’angelo, Quora
SQL for max value without using MAX
Assume the table myTable and the column myNumber containing numbers from which you need to find the max value.
SELECT mt1.myNumber FROM myTable mt1 WHERE NOT EXISTS ( SELECT mt2.myNumber FROM myTable mt2 WHERE mt2.myNumber > mt1.myNumber )
Try it :)
A Great Way To Augment built-in functions to write your own.
Let us try to reverse a given string. Now, within, Javascript, the Array object as the reverse method.
String.prototype.reverse = function() {
return Array.prototype.reverse.apply(this.split('')).join('');
}
var myString = "Amazing!";
console.log(myString.reverse());
The prototype is a property that allows us to define a new property or a function to the object. So, when I wrote String.prototype.reverse = function() {} I created a function named “reverse” adding to the existing Javascript Object called String
That’s it. Amazing!
Select All Columns from a Table, but 1 column as Unique/Distinct
Let’s you have a table named posts in your DB with the following columns/fields.
- post_id
- post_title
- post_content
- post_type
- author
- post_date
Here, in this table, I can have more than posts with the same post_title. But for each post_title, the post_id would be unique even though both might have the same title. In this case, I want to retrieve all the columns/fields but post_title to be unique (not to be repeated) where post_type='myPostType'. The SQL would be as follows (as on MySQL)
SELECT * FROM posts WHERE post_type='myPostType' GROUP BY post_title ORDER BY post_title
In case you are using any other DB other than MySQL, your query would surely vary. You can check this post out too.
First Python Program
Here is my fresh skills. I just started off with Python. This is a program that prints Fibonacci series until the number provided as a parameter.
def fib(n):
a, b = 0, 1
while(b < n):
print b
a, b = b, a+b
fib(1000)
Save this as fib.py and run on the terminal using the command python fib.py
Interview with Mr. Rohit Ghatol & Lokik Purohit @TechNext: REST & Web Security
Last Week, at TechNext, I had the opportunity to have a talk with Mr. Rohit Ghatol. Rohit is the founder of TechNext, an Architect Engineer at Quick Office and a former Googler. The event was hosted at Synerzip Softech in Pune. The talks at TechNext were related to
- REST
- XSS
- Web Security Hacks
It was a good 3 - 4 hours of talk combied with discussions related to the same. REST (Representational State Transfer) was talked about by Mr. Lokit, a lead Engineer at Quick Office. Mr. Lokik descriped the functionalities of REST and it’s usage in Web Services using Java. You can read this wonderful article by Mr. Dhananjay Nene on Why REST? here, which explains REST conceptually.
I had the opportunity to talk a discussion as to brief everyone who couldn’t be present at the event. This video would be up on PuneTech.com as well soon. We are looking for contributers, in Pune who could contribute talks/discussions/interviews in the form of Videos. Kindly contact me or punetech for that matter.
Displaying your Photos using Flickr API in PHP
This code basically gets all the photos from the sets you have created and displays it under the appropriate Set Title. I achieved this by making use of PhpFlickr, you can download it from here. Once you download it, copy it to your web directory inside a folder called phpflickr. Now you need to login to Flickr and generate yourself an
- API Key
- Secret
You can get the following from here. You can either for a commercial or a non-commercial. For this example, I used a non-commercial one.
Once you have done that, outside the folder, create another file, say index.php and enter the following.
<?php
require_once('phpflickr/phpFlickr.php');
//Enter the key that was generated for you
$f = new phpFlickr("[your key]");
//Enter your User ID here. Looks something like this
//xxxxxxxx@Nxx
//You can go to your own profile and see the URL containing such an ID, paste that here
$user = "[your user ID]";
$ph_sets = $f->photosets_getList($user);
#print_r($ph_sets);
foreach($ph_sets['photoset'] as $photoSet) {
echo "<h2>".$photoSet['title']."</h2>";
$photos = $f->photosets_getPhotos($photoSet['id']);
foreach($photos['photoset']['photo'] as $photo) {
?>
<img src="<?php echo $f->buildPhotoURL($photo, 'medium'); ?>" />
<?php
}
}
The functions are quite self explanatory. That’s it, you are done. View the page on the browser. Voila.
Install Curl on Ubuntu
Type the following command in your terminal
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Once it’s installed restart your apache server by doing so
sudo service apache2 restart
That’s it in order to test curl, let’s send a request/response to google.com like so
curl -v google.com
All requests are preceded by > and all responses are preceded by a <

