Skip to content

Instantly share code, notes, and snippets.

View akhy's full-sized avatar
☁️
Working from cloud

Akhyar Amarullah akhy

☁️
Working from cloud
View GitHub Profile
@akhy
akhy / graceful.go
Created December 12, 2018 06:58 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
@akhy
akhy / about:config.md
Created January 13, 2018 05:33 — forked from haasn/about:config.md
Firefox bullshit removal via about:config

Firefox bullshit removal

Due to the incessant swarm of complete and utter nonsense that has been forcing its way into Firefox over time, I've decided to start collecting my personal list of “must-have” about:config tweaks required to turn Firefox into a functional brower.

NOTE: Unfortunately this is somewhat out of date. The comments link to some resources that may be more up-to-date. Patches welcome.

WebSockets

These can be used for nefarious purposes and to bypass access restrictions.

@akhy
akhy / keybase.md
Created August 28, 2017 05:17
keybase.md

Keybase proof

I hereby claim:

  • I am akhy on github.
  • I am akhy (https://keybase.io/akhy) on keybase.
  • I have a public key ASAuLFMP1bKJSRzHLNcuvBpH2k6s36AZMXrzgddwuLgzhQo

To claim this, I am signing this object:

@akhy
akhy / gunicorn.py
Created July 20, 2017 09:15
gunicorn workers config based on physical cpu
from sys import platform
if platform == "linux" or platform == "linux2":
from sh import grep, wc, cat
# cat /proc/cpuinfo | grep 'core id' | wc -l
cpu_count = wc(grep(cat('/proc/cpuinfo'), 'core id'), '-l')
elif platform == "darwin":
from sh import grep, sysctl, awk
# sysctl -a | grep machdep.cpu.core_count | awk '{print $2}'
cpu_count = awk(grep(sysctl('-a'), 'machdep.cpu.core_count'), '{print $2}')
@akhy
akhy / Jenkins auto-shudown-slaves job
Created February 16, 2017 17:01 — forked from fotinakis/Jenkins auto-shudown-slaves job
Auto-managed Jenkins slaves on Google Compute Engine
#!/bin/bash
# Have to redirect stderr to stdout here because slave.py uses stderr for output.
~/bin/slave.py list 2>&1 >/dev/null | grep beaker-slave- | while read slave; do
echo
echo "Checking status of $slave..."
# First, check if we can SSH into the host. If we can, then check the process and maybe shut down.
# This makes sure that we don't consider an SSH failure to be reason to shut down the node.
if ssh $slave echo < /dev/null; then
@akhy
akhy / rancherw
Last active November 15, 2016 04:59
rancher-compose wrapper
#!/bin/bash
# Notes:
# - RANCHER_URL, RANCHER_ACCESS_KEY, RANCHER_SECRET_KEY must be set
# - jq is required (brew install jq) // TODO: remove this dependency
# - cache is located at $HOME/.rancher-compose/cache.txt
# - usage is the same as rancher-compose, it's just a wrapper
if [ `uname` == "Darwin" ]; then
ARCH="darwin-amd64"
@akhy
akhy / kompas.py
Created September 13, 2016 03:19
My own solution to Kompas coding test http://bit.ly/2cnvywQ
#!/usr/bin/python
maxw=25 # largest width
minw=1 # smallest width
pad=1 # left-right padding per step
incr=pad*2 #
# assumptions
assert maxw >= minw + 2 # max width must be equals or greater than minw+2
assert minw > 0
@akhy
akhy / jenkins-git-backup.sh
Created September 2, 2016 07:24 — forked from abayer/jenkins-git-backup.sh
Example of a script for backing up Jenkins config in git.
#!/bin/bash
#
# Copies certain kinds of known files and directories from a given Jenkins master directory
# into a git repo, removing any old ones, adds 'em, commits 'em, pushes 'em.
#
set -ex
if [ $# -ne 2 ]; then
echo usage: $0 root_dir jenkins_master
#!/usr/bin/env perl
# Copyright (c) 2015 Sergey Lyubka
# All rights reserved
use Encode;
my $dir = "/Users/$ENV{USER}/.Trash";
sub read_file($) { local $/; open FD, $_[0] or die $_[0]; binmode FD; <FD>; }
@akhy
akhy / shell.sh
Last active June 30, 2016 03:03
Shell Cheatsheet
# looping over array
for i in "${arrayName[@]}"; do
# do whatever on $i
done
# Switch-case
case ${ENV} in
"development")
;;
"staging")