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 / async_await_setTimeout.js
Created June 27, 2019 05:48
Promisifying and awaiting setTimeout
function sleep(ms) {
return new Promise((resolve, reject) => {
console.log(`Sleeping for ${ms} ms...`)
setTimeout(() => resolve('Done sleeping'), ms)
})
}
const run = async function() {
console.log('Run start')
const res = await sleep(2000)
@kevinadi
kevinadi / Makefile
Created June 27, 2019 01:42
Makefile for Go to automatically stamp Git info and build date
version=$(shell git describe --always --long --dirty)
date=$(shell date -j "+(%b %Y)")
all:
@go build -v -ldflags '-X "main.version=${version}" -X "main.date=${date}"'
install:
@go install -v -ldflags '-X "main.version=${version}" -X "main.date=${date}"'
@kevinadi
kevinadi / init.el
Last active October 17, 2021 23:55
Reasonable init.el using builtins only
(require 'package)
;;; Code:
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
@kevinadi
kevinadi / build.gradle
Created August 13, 2018 01:33
Basic build.gradle with fat jar capability
plugins {
id 'java'
id 'application'
}
mainClassName = 'App'
dependencies {
testCompile 'junit:junit:4.12'
}
@kevinadi
kevinadi / mgeneratejs.template.json
Created May 22, 2018 04:25
mgeneratejs template
{
"numbers": {
"integer": "$integer",
"float": "$floating"
},
"array": {
"$array": {
"of": {
"$country": {
"full": true
@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
@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 / 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 / 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 / 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"