Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import argparse
import sys
enabled = []
disabled = []
class MethodWrapper():
def __init__(self):
@ajithbh
ajithbh / log_redirect.cpp
Last active July 2, 2018 03:45
Qt - Redirect qDebug output to file
#include <fstream>
using namespace std;
ofstream logfile;
void LogToFile(QtMsgType type, const char *msg) {
QString datetime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
switch (type) {
case QtDebugMsg:
logfile << datetime.toString().toAscii().data() << " [Debug] " << msg << "\n";
@ajithbh
ajithbh / cmd_line_opt.sh
Last active August 29, 2015 13:57
Bash - Utility functions
while getopts ae:f:h:qs: option
do
case "${option} in
a) AFLAG="TRUE" ;;
e) EOPTION=${OPTARG} ;;
f) FILE=${OPTARG} ;;
q) QUIET="TRUE" ;;
s) SERVER=${OPTARG} ;;
h|\?) usage && exit 1 ;;
esac
@ajithbh
ajithbh / mem_avail.c
Last active March 19, 2025 08:39
Available memory using C
void mem_avail(void)
{
char *cmd = "awk '{ if (NR == 2) { print $4 }}' /proc/meminfo";
FILE *cmdfile = popen(cmd, "r");
char result[256] = { 0 };
while (fgets(result, sizeof(result), cmdfile) != NULL) {
printf("%s\n", result);
}
@ajithbh
ajithbh / has_device.c
Last active January 1, 2016 13:49
Has Device in C
#include <sys/stat.h>
// 0: No Such Device, 1: Found Device
int has_device(char *path)
{
struct stat buf;
if (stat(path, &buf) < 0) {
return 0;
}
@ajithbh
ajithbh / sudo_vim.txt
Last active January 1, 2016 13:49
If you forgot "sudo vim"
If you forgot "sudo vim" and get error "Can't open file for writing"
:w !sudo tee %
http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work
@ajithbh
ajithbh / pppoe.txt
Last active December 20, 2015 08:39
Gist of PPPoE
PPPoE
provides the ability to connect a network of hosts over a simple bridging access device to a remote access concentrator.
Each PPP session must learn the ethernet address of the remote per, as well as establish a unique session identifier.
2 Stages -
1. Discovery stage
2. PPP session stage
Discovery is a client-server relationship
PPP defines a peer-to-peer relationship
@ajithbh
ajithbh / ppp.md
Last active December 20, 2015 08:39
Gist of PPP

Point-to-Point Protocol (PPP)

  • provides a standard method for transporting multiprotocol datagrams over point-to-point links.
  • Comprised of 3 main components
    1. A method for 'encapsulating' multi-protocol datagrams
    2. A Link Control Protocol (LCP) for establishing, configuring and testing the data-link connection
    3. A family of Network Control Protocols (NCPs) for establishing and configuring different network layer protocols

Encapsulation

PPP encapsulation provides for multiplexing of different network-layer protocols simultaneously over the same link. Only 8 additional octets are necessary to form the encapsulation when used within the default framing which is similar to High-level Data Link Control (HDLC) framing.

@ajithbh
ajithbh / IPSec.txt
Last active December 20, 2015 07:59
Notes on IPSec
IPSec framework of open standards define the essentials of network security
- Data Origin Authentication
- Data Integrity
- Data Confidentiality
- Anti-replay
IPSec provides security based on the negotiated Security Association (SA)
A Security Association Database (SADB) is a repository of SA's, which can be added dynamically by means of Internet Key Exchange (IKE) or manually.