Category Archives: Coding

All kinds of Programming.

40+ Useful Php tips for beginners – Part 3

By | April 7, 2012

Part 2 26. Avoid direct SQL query , abstract it $query = "INSERT INTO users(name , email , address , phone) VALUES('$name' , '$email' , '$address' , '$phone')"; $db->query($query); //call to mysqli_query() The above is the simplest way way of writing sql queries and interacting with databases for operations like INSERT, UPDATE, DELETE etc. But… Read More »

Php get list of locales installed on system

By | March 26, 2012

On linux , the list of locales installed on the system can be fetched through the terminal command locale -a : $ locale -a C C.UTF-8 en_AG en_AG.utf8 en_AU.utf8 en_BW.utf8 en_CA.utf8 en_DK.utf8 en_GB.utf8 en_HK.utf8 en_IE.utf8 en_IN en_IN.utf8 en_NG en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 en_ZA.utf8 en_ZM en_ZM.utf8 en_ZW.utf8 es_AR.utf8 es_BO.utf8 es_CL.utf8 es_CO.utf8 es_CR.utf8 es_DO.utf8 es_EC.utf8 es_ES.utf8… Read More »

Get time difference in microtime in C

By | March 9, 2012

The function gettimeofday can be used to retrieve the total number of seconds and balance microseconds elapsed since EPOCH. Structure timeval looks like this : struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ }; On Linux it can be done like this : /** * Get time difference in microseconds… Read More »

How to Get IP Whois Data in C with Sockets on Linux – Code Example

By | August 7, 2020

Theory The whois information of an ip address provides various details like its network, range, isp etc. This information is maintained by various regional registry servers. Read the wikipedia article on regional internet registries for more information. There are a total of 5 regional registries spanning various geographical regions of the world. For example if… Read More »

Winsock tutorial – Socket programming in C on windows

By | July 25, 2020

Socket programming with winsock This is a quick guide/tutorial to learning socket programming in C language on Windows. “Windows” because the code snippets shown over here will work only on Windows. The windows api to socket programming is called winsock. Sockets are the fundamental “things” behind any kind of network communications done by your computer…. Read More »

str_replace for C

By | December 22, 2011

Php has a useful function called str_replace which can search and replace a certain string in another big string. However there is no such function in C. So I wrote up one for myself. Here is the code. /* * Search and replace a string with another string , in a string * */ char… Read More »