Skip to content

Instantly share code, notes, and snippets.

View nirbhayc's full-sized avatar

Nirbhay Choubey nirbhayc

  • Bloomberg LP
  • New York
View GitHub Profile
@nirbhayc
nirbhayc / producer_consumer.c
Created June 20, 2017 21:36
(Blog) Producer/Consumer demo
/**
@file producer_consumer.c
@info A sample program to demonstrate the classic consumer/producer problem
using pthreads.
*/
#include <stdio.h>
#include <pthread.h>
@nirbhayc
nirbhayc / CLASSNOTFOUNDEXCEPTION_demo.java
Last active June 20, 2017 21:33
(Blog) CLASSNOTFOUNDEXCEPTION in MySQL
/**
Get server version.
*/
import java.sql.*;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.*;
@nirbhayc
nirbhayc / compile_time_assert.snip
Created June 20, 2017 21:29
(Blog) Compile-time assertion
#define compile_time_assert(expr) \
do \
{ \
typedef char compile_time_assert[(expr) ? 1 : -1] __attribute__((unused)); \
} while(0)
@nirbhayc
nirbhayc / enum_type_demo.go
Created June 20, 2017 21:26
(Blog) Enum type in Go
package main
import "fmt"
type myColor string
const (
RED myColor = "red"
GREEN myColor = "green"
BLUE myColor = "blue"
@nirbhayc
nirbhayc / split-brain.log
Created June 20, 2017 21:15
(Blog) Galera split brain logs
50217 15:49:02 [Note] WSREP: (dc9e817d-b6e5-11e4-a36f-8fe330cf395b, 'tcp://0.0.0.0:4010') turning message relay requesting on, nonlive peers: tcp://192.168.0.8:4030 tcp://192.168.0.8:4040
150217 15:49:03 [Note] WSREP: (dc9e817d-b6e5-11e4-a36f-8fe330cf395b, 'tcp://0.0.0.0:4010') reconnecting to 370a81b6-b6e6-11e4-b985-beb180620fd9 (tcp://192.168.0.8:4030), attempt 0
150217 15:49:03 [Note] WSREP: (dc9e817d-b6e5-11e4-a36f-8fe330cf395b, 'tcp://0.0.0.0:4010') reconnecting to 4ba33092-b6e6-11e4-93a4-ba232dff3484 (tcp://192.168.0.8:4040), attempt 0
150217 15:49:04 [Note] WSREP: evs::proto(dc9e817d-b6e5-11e4-a36f-8fe330cf395b, GATHER, view_id(REG,370a81b6-b6e6-11e4-b985-beb180620fd9,4)) suspecting node: 370a81b6-b6e6-11e4-b985-beb180620fd9
150217 15:49:04 [Note] WSREP: evs::proto(dc9e817d-b6e5-11e4-a36f-8fe330cf395b, GATHER, view_id(REG,370a81b6-b6e6-11e4-b985-beb180620fd9,4)) suspecting node: 4ba33092-b6e6-11e4-93a4-ba232dff3484
...
...
150217 15:49:14 [Note] WSREP: evs::proto(dc9e817d-b6e5-11e4-a36f-8fe330cf395b, G
@nirbhayc
nirbhayc / cracklib-check-demo
Created June 20, 2017 21:12
(Blog) cracklib-check demo
$ echo "nirbhay" | cracklib-check
nirbhay: it is based on your username
$ echo "password" | cracklib-check
password: it is based on a dictionary word
$ echo "qwerty" | cracklib-check
qwerty: it is based on a dictionary word
$ echo "123" | cracklib-check
123: it is WAY too short
$ echo "123456" | cracklib-check
123456: it is too simplistic/systematic
@nirbhayc
nirbhayc / cracklib_password_check
Created June 20, 2017 21:11
(Blog) cracklib_password_check plugin
MariaDB [test]> INSTALL SONAME 'cracklib_password_check';
Query OK, 0 rows affected (0.05 sec)
MariaDB [test]> SELECT VARIABLE_NAME, DEFAULT_VALUE, VARIABLE_COMMENT FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'CRACKLIB_PASSWORD%'\G
*************************** 1. row ***************************
VARIABLE_NAME: CRACKLIB_PASSWORD_CHECK_DICTIONARY
DEFAULT_VALUE: /var/cache/cracklib/cracklib_dict
VARIABLE_COMMENT: Path to a cracklib dictionary
1 row in set (0.00 sec)
@nirbhayc
nirbhayc / simple_password_check
Created June 20, 2017 21:10
(Blog) simple_password_check plugin
MariaDB [test]> INSTALL SONAME 'simple_password_check';
Query OK, 0 rows affected (0.04 sec)
MariaDB [test]> SELECT VARIABLE_NAME, DEFAULT_VALUE, VARIABLE_COMMENT FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'SIMPLE_PASSWORD%'\G
*************************** 1. row ***************************
VARIABLE_NAME: SIMPLE_PASSWORD_CHECK_DIGITS
DEFAULT_VALUE: 1
VARIABLE_COMMENT: Minimal required number of digits
*************************** 2. row ***************************
VARIABLE_NAME: SIMPLE_PASSWORD_CHECK_LETTERS_SAME_CASE
@nirbhayc
nirbhayc / packet_capture.out
Created June 20, 2017 21:07
(Blog) MySQL packet capture
$sudo ngrep -x -q -d lo port 16001
# where,
# -x : Dump packet contents as hexadecimal
# -q : Be quiet, do not print '#' for every packet received
# -d <dev> : Listen to 'dev' interface only
# port <port> : Print packets with this source or destination port only
interface: lo (127.0.0.0/255.0.0.0)
filter: (ip or ip6) and ( port 16001 )
@nirbhayc
nirbhayc / largest_event.go
Created June 20, 2017 21:04
(Blog) Find the largest event in a binary log file
/*
@File : largest_event.go
@Description : Find the largest event in a binary log file.
@Usage : ./largest_event.go -file=<binary log file>
*/
package main
import (
"flag"