Skip to content

Instantly share code, notes, and snippets.

View zapstar's full-sized avatar

Thirumal Venkat zapstar

View GitHub Profile
@zapstar
zapstar / run_spark_job.sh
Created April 7, 2015 07:15
Run Spark Job by looking at the build File
#!/bin/sh
# NOTE: Make sure we have $SPARK_HOME set...
# Identify the build file
BUILD_FILE=`ls *.sbt`
# Find out the required variable from the build file
PROJECT_NAME=`grep name $BUILD_FILE | cut -d" " -f 3- | sed -e 's/ /-/g' | awk '{ gsub(/"/, "", $0); print tolower($0) }'`
SCALA_VERSION=`grep scalaVersion $BUILD_FILE | awk '{ gsub(/"/, "", $3); print $3 }' | rev | cut -d '.' -f 2- | rev`
@zapstar
zapstar / cfglog_tutorial.sh
Created September 23, 2015 08:52
AIX cfglog tutorial - Useful to debug disk stuff
# Set cfglog environment variable
# cmd = trace commands
# meth = trace methods
# lib = trace libraries
# verbosity:xx (0-9) verbosity
export CFGLOG="cmd,meth,lib,verbosity:9"
# File where this gets logged: /var/adm/ras/cfglog
# Read cfglog entries:
@zapstar
zapstar / bst2dll.cpp
Created October 12, 2015 12:10
Convert a binary search tree into a doubly linked list (left acts as prev, right acts as next)
#include <stdexcept>
#include <iostream>
using namespace std;
struct node {
int val;
struct node *left;
struct node *right;
};
@zapstar
zapstar / Makefile
Created February 12, 2016 06:50
Create individual binaries per C file
############################################################################
# 'A Generic Makefile for Building Multiple main() Targets in $PWD'
# Author: Robert A. Nader (2012)
# Email: naderra at some g
# Web: xiberix
############################################################################
# The purpose of this makefile is to compile to executable all C source
# files in CWD, where each .c file has a main() function, and each object
# links with a common LDFLAG.
#
@zapstar
zapstar / show-256-colors.pl
Created March 3, 2016 07:24
Show all possible colors on the terminal via a perl script.
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $
# use the resources for colors 0-15 - usually more-or-less a
# reproduction of the standard ANSI colors, but possibly more
# pleasing shades
# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
@zapstar
zapstar / VirtualBox Guest Settings.md
Created April 13, 2016 07:41
My Dnsmasq configuration on OSX. This acts as both DNS & DHCP server for my VirtualBox host-only network
  • First create a host-only network if not already done so. Use the IP Address 192.168.56.1 with the netmask 255.255.255.0. Don't enable DHCP server (next tab), it should be unchecked.

  • Make sure two network interfaces are assigned to the VM. The first being a NAT interface (note: NOT NAT Network). The second being a Host-Only Adapter.

  • In the Ubuntu guest the /etc/network/interfaces file should look something similar to below.

# This file describes the network interfaces available on your system
@zapstar
zapstar / openssl_2way_auth.sh
Last active June 25, 2025 13:33
Steps to create CA, server and client keys + certificates for SSL 2-way authentication
# Move to root directory...
cd /
mkdir keys
cd keys
# Generate a self signed certificate for the CA along with a key.
mkdir -p ca/private
chmod 700 ca/private
# NOTE: I'm using -nodes, this means that once anybody gets
# their hands on this particular key, they can become this CA.
@zapstar
zapstar / bit_hacks.cpp
Last active May 21, 2016 16:58
Bit Hacks
/**
* Bit hacks
*
* Not as extensive as https://graphics.stanford.edu/~seander/bithacks.html
* but I want a quick reference for myself
*/
// multiply x by 2^n
int mul_pow2(int x, int n) {
return x << n;
@zapstar
zapstar / get_parent_ptr.c
Created December 8, 2016 14:15
Get the outer structure's pointer from the inner structure in C.
#include <stddef.h>
typedef struct inner {
int i_a;
int i_b;
int i_c;
} inner_t;
typedef struct outer {
int o_a;
@zapstar
zapstar / ca_gen.sh
Created July 28, 2017 10:35
Tools to generate, test and play around with SSL keys, certificates and chains
#!/usr/bin/env bash
# Generate the root CA certificate
# Generate a self signed certificate for the CA along with a key.
mkdir -p ca/private
mkdir -p ca/newcerts
chmod 700 ca/private
# NOTE: I'm using -nodes, this means that once anybody gets
# their hands on this particular certificate they can become this CA.
openssl req \