Quick Premier on migration to Curl for a socket programmer

I have been thinking of putting this out for quite some time. In future this will find its home on stackoverflow (libcurl documentation) which still is in proposal state. This is very high level and only provides the basic guideline. There are many options and cases that are better documented on libcurl website.

Check https://curl.haxx.se/libcurl/c/libcurl-tutorial.html which provides many examples. Documentation for libcurl also provides small code snippets to use for each API. For some they even provide high level steps just like I mentioned below. Continue reading

Create Post Excerpt Intelligently in Jekyll

meta-descriptions or OpenGraph Descriptions are the short descriptions that Search Engines/Facebook display on result pages. They provide a brief introduction to the content and grab user attention. So when possible, try to use keywords in meta description that describes in short what that page is about. Ensure to limit meta description length to 160 characters which seems to be a norm for SEO now-a-days.

Jekyll by default supports post.excerpt which would automatically take the value of excerpt from Front Matter (if present). Otherwise it will fall-back to post content from beginning till excerpt_separator or end of post. Whatever separator you choose, have it defined as excerpt_separator in _config.yaml. With this done you can use {% raw %}{{ post.excerpt | strip_html }}{% endraw %} wherever you need to show it (e.g. meta-description/og-description). I use strip_html to remove any html which will cause issues with description tags.

I personally like to show a bigger teaser on my main page to entice user attention. And on other pages (like search results, Category/Tag index) show a brief description. Here is how I do it.

  1. Define meta-description tag in Front Matter of the post and describe in few words what the post is about. Then use {% raw %}{{ post.meta-description }}{% endraw %} during publishing HTTP headers for the post and on Category/Tag index pages. And on main page OR index.html use {% raw %}{{ post.excerpt }}{% endraw %} which is auto-generated by Jekyll based on Front Matter or excerpt_separator. I personally stopped defining excerpt in Front Matter to avoid namespace collision with Jekyll.
    Continue reading

xming : Client 4 rejected from IP

If you are getting following error in xming log:

Xming.exe: client 4 rejected from IP XXX.XXX.XXX.XXX

Here are two solutions.

  1. Secure method: Edit: X0.hosts (in the installation directory) and add the ip you want allow. e.g.
    localhost
    XXX.XXX.XXX.XXX
    

    Restart Xming.

  2. Insecure method: Add the “-ac” option to the Xming desktop shortcut. Modify the Desktop Xming shortcut to include the arguments: “:0 -clipboard -multiwindow -ac”. The ac option accepts client requests and quells the error above. Start Xming using the shortcut you just created. Warning: This is same as “xhost +” which will grant anyone access. So only use Xming option -ac or “xhost +” on trusted networks, never on public ones. OR use the solution 1 of additing IP address of known systems on which you will be running X applications..

snmp : find network information of a system centrally

Anyone can login to a system and run ifconfig or netstat or other similar commands to find the network information of a system. But what will be even better? Do it remotely without logging in to each and every system. How? Using snmpwalk one can retrieve all this information provided that subject has both snmpd running, snmpd supporting network information and the querying host is allowed to make SNMP queries. Lets see how.

Interface table is covered by basic SNMP (just like system information, udp, tcp  socket information, address translation and snmp stats etc). Here is how to query the interface table to get the IP address and Subnet mask information.

unixite@sanbox:~/ > snmpwalk -v1 -c public sandboxS:161 1.3.6.1.2.1.4.20.1.1
iso.3.6.1.2.1.4.20.1.1.1.2.3.4 = IpAddress: 1.2.3.4
iso.3.6.1.2.1.4.20.1.1.127.0.0.1 = IpAddress: 127.0.0.1
iso.3.6.1.2.1.4.20.1.1.192.168.1.10 = IpAddress: 192.168.1.10
iso.3.6.1.2.1.4.20.1.1.10.0.0.2 = IpAddress: 10.0.0.2
unixite@sanbox:~/ > snmpwalk -v1 -c public sandboxS:161 1.3.6.1.2.1.4.20.1.3
iso.3.6.1.2.1.4.20.1.3.1.2.3.4 = IpAddress: 255.0.0.0
iso.3.6.1.2.1.4.20.1.3.127.0.0.1 = IpAddress: 255.0.0.0
iso.3.6.1.2.1.4.20.1.3.192.168.1.10 = IpAddress: 255.255.255.0
iso.3.6.1.2.1.4.20.1.3.10.0.0.2 = IpAddress: 255.255.0.0

First one here retrieves the IP addresses on the system while second one get the subnet masks. -c public has to be changed to right community string and also the version if your supports a different one. My system name here is sandboxS and snmpd is listening on default port 161. If not then you can change the port to match yours.

Configure Apache to run PHP on Windows

Just rebuilt my Windows laptop and had to reload Apache, MySQL and PHP. Some may suggest WAMP or XAMPP projects to simplify things, but those are my last resorts. I like to have full control of the situation. So I downloaded the latest versions of each from respective site and installed them. And then the problem happened.

PHP installed successfully but had an error that it could not access httpd.conf so PHP files could not be executed. To get the short answer, I turned to Google. It took me about 10 minutes and sorting of 20 webpages to get to the right configuration. Only if I had gone directly to Apache it would be better. But here is what configuration in Apache has to be done to get PHP files recognized and run by Apache.

Modify httpd.conf file to have following.

# Tell Apache where to pick PHP Module from
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"

# Tell Apache that it should treat index.php just like index.html
DirectoryIndex index.html index.php

# Add type for PHP file handler
AddType application/x-httpd-php .php
# This is optional but allows user to access php source file (php files with extension  renamed) with full syntax highlighting
AddType application/x-httpd-php-source .phps