Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# some useful commands to collect system infomation.
# Reference:
# http://www.tecmint.com/commands-to-collect-system-and-hardware-information-in-linux/
# http://www.binarytides.com/linux-commands-hardware-info/
# Check kernel,OS,CPU
uname -a
@ictlyh
ictlyh / curl-get.c
Created November 30, 2016 09:32
Demo of getting page via lib curl
/*
* Demo of getting page via lib curl
* Build: gcc curl-get.c -o curl-get -lcurl
* Run: ./curl-get
*/
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ictlyh
ictlyh / curl-post.c
Created November 30, 2016 09:34
Demo of posting data to webpage via lib curl.
/*
* Demo of posting data to webpage via lib curl.
* Build: gcc curl-post.c -o curl-post -lcurl
* Run: ./curl-post
*/
#include <curl/curl.h>
#include <stdio.h>
int main(void) {
@ictlyh
ictlyh / gethostname.c
Created November 30, 2016 09:37
Demo of getting host name and domain name
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
@ictlyh
ictlyh / libpq-demo.cc
Last active December 28, 2023 14:35
libpq examples.
/*
* Demo of libpq.
* Build: g++ libpq-demo.cc -o libpq-demo -lpq
* Run: ./libpq-demo
*/
#include <arpa/inet.h>
#include <iostream>
#include <libpq-fe.h>
#include <sstream>
@ictlyh
ictlyh / list-dir.c
Created November 30, 2016 09:49
List directory recursively on Linux system.
/*
* List directory recursively on Linux system.
* Build: gcc list-dir.c -o list-dir.out
* Run: ./list-dir.out
*/
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
@ictlyh
ictlyh / print-bits.c
Created November 30, 2016 09:51
Demo of print bytes in binary
/*
* Demo of print bytes in binary.
* Build: gcc print-bits.c -o print-bits
* Run: ./print-bits
*/
#include<stdio.h>
#include<stdlib.h>
void printBits(void const * const ptr, size_t size) {
@ictlyh
ictlyh / socket-demo.c
Created November 30, 2016 09:57
Socket demo.
// server.c
/*
* Demo of socket server.
* Build: gcc server.c -o server
* Run: ./server
*/
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
@ictlyh
ictlyh / test-argp.c
Created November 30, 2016 10:01
Demo of parsing program options with Argp
/*
* Demo of parsing program options with Argp
* Build: gcc test-argp.c -o test-argp
* Run: ./test-argp
*/
#include <argp.h>
#include <stdlib.h>
/* Program documentation. */
@ictlyh
ictlyh / test-zombie.c
Created November 30, 2016 10:07
Demo of creating zombie process.
/*
* Demo of creating zombie process.
* Build: gcc test-zombie.c -o test-zombie
* Run: ./test-zombie
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>