Skip to content

Instantly share code, notes, and snippets.

View zapstar's full-sized avatar

Thirumal Venkat zapstar

View GitHub Profile
@zapstar
zapstar / stock_options_calculator.py
Last active October 10, 2020 16:34
Stock Options Calculator (For a startup's employee)
#!/usr/bin/env python3
"""
Stock Options Calculator
Helps you get a fair idea of the costs involved and profits that can be gained in the future.
Example Usage:
# --option-grant 10000,0.25 10000,0.5 --exercise-fmv 1.25 --income-tax-rate 0.3 --exercise-exch-rate 73 --sale-fmv 2.5 --capital-gain-rate 0.2 --sale-exch-rate 75 --indexation-ratio 1.075
"""
@zapstar
zapstar / ssl_nb_read_write.cpp
Created December 9, 2019 07:30
OpenSSL non-blocking read/write example with select
// Reformatted the code available at https://github.com/Andersbakken/openssl-examples/blob/master/read_write.c
// The code is hopefully easier to understand now
#include <fcntl.h>
#include <openssl/ssl.h>
#include <unistd.h>
void err_exit(const char *s)
{
/* TODO: Implement an exit function */
@zapstar
zapstar / client.py
Created June 8, 2018 09:01
Python Asyncio SSL client and server examples
#!/usr/bin/env python3
import asyncio
import ssl
@asyncio.coroutine
async def echo_client(data, loop):
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_ctx.options |= ssl.OP_NO_TLSv1
@zapstar
zapstar / vimtutor_summaries
Created June 3, 2018 10:16
Summaries from the `vimtutor` program.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1 SUMMARY
1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left) j (down) k (up) l (right)
2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
@zapstar
zapstar / Makefile
Created March 11, 2018 14:34
Makefile to generate separate binaries for each source file
CXX=clang++
CXXFLAGS=-Wall -Werror -std=c++11
all: $(patsubst %.cpp, %.out, $(wildcard *.cpp))
%.out: %.cpp Makefile
$(CXX) $(CXXFLAGS) $< -o $(@:.out=)
clean: $(patsubst %.cpp, %.clean, $(wildcard *.cpp))
@zapstar
zapstar / cs161_renamer.py
Created September 18, 2017 06:18
Rename the videos downloaded from CS161 - Tim Roughgarden
#!/usr/bin/env python
# CS 161 - Design and Analysis of Algorithms - Tim Roughgarden
#
# Script to rename FLV files using their XML containing metadata.
# I personally prefer the blackboard videos, so wrote a script to rename the
# videos to have proper titles.
#
# This is a script that gets job done, not something you'd want to integrate
# into some production code, so use it at your own risk.
@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 \
@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 / 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 / openssl_2way_auth.sh
Last active March 20, 2024 21:07
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.