Skip to content

Instantly share code, notes, and snippets.

View kevinadi's full-sized avatar

Kevin Adistambha kevinadi

  • MongoDB
  • Sydney, Australia
View GitHub Profile
@kevinadi
kevinadi / external-ip.sh
Created June 9, 2016 14:01
What is my external IP address?
curl -s http://ipinfo.io/ip
@kevinadi
kevinadi / hanoi.py
Last active December 21, 2016 06:51
Tower of Hanoi
import sys
import unittest
import copy
class HanoiTest(unittest.TestCase):
def test_number_of_steps_3(self):
''' number of steps should be 2^n-1 (3 disks) '''
h = Hanoi(3).solve()
self.assertEqual(len(h), 2**3)
@kevinadi
kevinadi / MongoJavaDriver.java
Created January 4, 2017 23:50
Small example of using MongoDB Java Driver (v3.4.1)
import java.util.Arrays;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
@kevinadi
kevinadi / MongoDotnetDriver.cs
Created January 5, 2017 22:37
Small example of using MongoDB dotnet driver (dotnet-core, MongoDB.Driver 2.4.1)
using System;
using System.Linq;
using MongoDB.Bson;
using MongoDB.Driver;
namespace ConsoleApplication
{
public class Person {
public ObjectId Id { get; set; }
@kevinadi
kevinadi / mongodb-ssl.sh
Last active March 24, 2025 10:32
Script to create self-signed CA certificates, server certificates, and client certificates for testing MongoDB with SSL
#!/bin/sh
# Generate self signed root CA cert
openssl req -nodes -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -subj "/C=AU/ST=NSW/L=Sydney/O=MongoDB/OU=root/CN=`hostname -f`/[email protected]"
# Generate server cert to be signed
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=AU/ST=NSW/L=Sydney/O=MongoDB/OU=server/CN=`hostname -f`/[email protected]"
# Sign the server cert
@kevinadi
kevinadi / mgo-ssl.go
Last active January 5, 2024 16:02
Small example of using MongoDB go driver (mgo) to connect using SSL with client certificate
package main
import (
"fmt"
"log"
"net"
"crypto/tls"
"crypto/x509"
@kevinadi
kevinadi / guitarscales.py
Last active June 27, 2017 21:54
Shows guitar scales & chords
#!/usr/bin/python
'''
Print guitar scales to stdout
'''
import argparse
import textwrap
MAXFRET = 16
NOTES_FLAT = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
NOTES_SHARP = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
@kevinadi
kevinadi / google-music-current-playlist.js
Last active June 15, 2017 00:43
Print Google Play Music current playlist to console
document.querySelectorAll('.song-row').forEach(function(el) {
var title = el.querySelector('td[data-col="title"]')
var artist = el.querySelector('td[data-col="artist"]')
if(title) console.log(title.textContent.trim() + ' - ' + artist.textContent.trim())
})
@kevinadi
kevinadi / .bash_profile
Created September 13, 2017 23:23
Git-aware bash prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
@kevinadi
kevinadi / mlogsum.py
Last active March 25, 2018 22:00
MongoDB log file summarizer
#!/usr/bin/env python
import argparse
import re
import json
import os
from dateutil import parser as timeparser
from pprint import pprint