Skip to main content

Posts

Showing posts from May, 2017

Come C tricks

Swapping the values of two variables with out using a third!! x = x ^ y; y = x ^ y; x = x ^ y; All hail the XOR operation Reference: https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/xor.html int c; c &= (c-1); check if c == 0 This allows you to check if C is a power of 2 (i.e. 0,1,2,4,8...) Reading sentences (including spaces) from stdin: scanf("%s",str); can't read spaces in input string. To do that, you have to: scanf(" %[^\n]s",str); Note the space before % within the quotes. Reference:  https://gpraveenkumar.wordpress.com/2009/06/10/how-to-use-scanf-to-read-string-with-space/

Set Elon's latest tweet as your desktop wallpaper

If you have an Ubuntu box, you can use a script to to set your wallpaper's to Elon's Latest Tweet. Here is how you setup: Install required packages. Download tweet.sh - an OAuth based twitter client implemented completely as a bash script. Get Token keys for from your Twitter account and save it in the config file. You need this for OAuth that twee.sh uses. Get a free account on  http://www.page2images.com/ and fetch your API keys. This service allows you to generate screenshot of any supplied URL - you can use this service to to fetch PNGs's of Elon's tweets. We do screenshots because aren't just interested in tweet's text but also any images that Elon chooses to attach with his tweets. In the batch script (elon_tweet.sh) appended below, configure the pages2images API key Setup the batch script (elon_tweet.sh) as a cron job which runs once every minute. You can set this script up on a Raspberry Pi running Raspbian connected to your TV as well.