Skip to main content

Posts

Showing posts from 2017

Build system comparison for C shared library: Manual vs. Makefile vs. Bazel

Here is a simple code for shared library (.so) and an executable that uses it: Library Source files (libhello.c and libhello.h): Source for the executable that uses the above library (main.c): There are many ways to build and execute these sources. Lets look at three of them. The first one is a collection of manual commands that you need to execute in a particular order. The other two uses some form of build system. Before you proceed, make sure to have the C compiler installed on your Ubuntu PC. To do this, execute the following at the command prompt: sudo apt-get install build-essential git Manual build: (Reference: http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html ) Place the three source files in the same directory. Open the command prompt, switch to the same directory and execute the following commands to compile, execute and clean: Compilation Compiling the library sources into object files with Position Independent Code: gcc -c -Wal

My favourite alias in .bashrc on Ubuntu

Colorizing and handling system/kernel logs alias logread='cat /var/log/syslog | ccze -A' alias logclear='sudo truncate -s 0 /var/log/syslog' alias logsave='cat /var/log/syslog | ccze -h > ~/log.html' alias dmesgread='dmesg | ccze -A' alias dmesgclear='sudo dmesg -c' alias dmesgsave='dmesg | ccze -h > ~/log.html' You will have to install ccze (sudo apt-get install ccze)

Replacing batteries in Black and Decker DP240 2.4V Direct-Plug Rechargeable Screwdriver

I have owned a Black and Decker DP240 Cordless Electric Screwdriver for 5 years now. Its battery had started losing its capacity to hold charge, so I looked online to see if it was possible to change its batteries. I couldn't find any blog/DIY guide on which batteries to replace the internal ones with and how to go about pry open the screwdriver and putting it back. So here are some photos outlining how I changed the batteries in mine and turned it into new. To open the screwdrive, you will need a set of "Torx Pin 6 lobe" screwdriver set. You cant use regular torx screwdriver bits. You need ones with holes in the center of the bits so that the center pin on the screw can fit into those holes. You can buy just a set of just the bits here. Torx pin 6 lobe Screwdrivers to open the shell Screwdriver with the shell opened It seems that the screwdriver comes with two AA size 1.2V NiCd 800 mAh cells installed I replaced the 800mAh batteries with 2550 mAh

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.

Classroom Timer V1

If you have ever been a teacher at any point in your life, you would have realized the importance of keeping your students engaged and on task at all times during the short period every day that you get to spend time teaching them. If you have just 30 minutes per day, you want to maximize the learning by having a structured lesson plan that moves smoothly from Introduction to New Material to Guided Practice and into Independent Practice. And if you have planned for the lecture properly, you would know how much time you want to spend at each stage doing each activity with the kids to ensure that the lesson is completed on time and doesn't spill over onto the next lecture. You may have a clock in your class, but having a countdown timer makes more sense in competitive and group activities. When the kids see the time ticking down, and they rush to try to finish the activity on time, it can give them an adrenalin rush and bring excitement to the activity. I am an engineer by prof

tweet.sh on LinkIt Smart 7688 Duo (OpenWrt)

Temboo-less tweeting from the shell LinkIt 7688 Duo is a cheaper ($15.9 vs $74.95) and breadboardable version of Arduino Yun . Arduino Yun comes preloaded with Temboo whereas LinkIt does not have that preloaded. Temboo is a great go between service that allows your IoT project to talk to existing services like google drive, twitter or dropbox - but to do anything long term and meaningful with it, you have to upgrade from a free temboo plan to a paid plan - Arduino Yun is already expensive and this makes it even moire expensive. I used Arduino Yun and Temboo to make a shimmering lamp that reacts to tweets from your sweetheart - But now it was time to move on to better yet cheaper builds. A Raspberry Pi running Node Red can achieve a lot  but here I want to focus on LinkIt because I am using it as a part of a larger "art" project. Since LinkIt has an AVR microcontroller (Arduino programmable over WiFi and Arduino Bridge), it allows for greater flexibility in interfacing

Dealing with WiFi IP Cameras and .264 files

On a recent visit to China, I purchased a cheap IP camera which looks like a robot: You can get one online from amazon  for twice the amount that you might pay for it when you buy it from one of the shops in ShenZhen (I got it for around 150 CNY or 1500 INR). The camera is supposed to be installed in your house where you can configure it to connect to your home's WiFi router. That way you can connect to the camera from anywhere in the world (using your web browser or smart phone app) and watch and hear what ever the camera picks up. Here are some of the features of this camera: Tech Specs (you can find these on the amazon page as well, although the model might say something else) Model: The packaging for my camera said "Mini Robot Wireless Camera H811 IP Camera" Power: DC Input 5V 2Amps (via microUSB connector) Image quality: 960P 1.3Megapixel WiFi: Out of the box, the camera defaults to WiFi master mode (i.e. wifi hotspot) . This is so that you can use th