Skip to content

Instantly share code, notes, and snippets.

View khan-rizwan's full-sized avatar

Rizwan Khan khan-rizwan

View GitHub Profile
#!/bin/sh
# The install script is licensed under the MIT license Glide itself is under.
# See https://github.com/Masterminds/glide/blob/master/LICENSE for more details.
# To run this script execute:
# `curl https://glide.sh/get | sh`
PROJECT_NAME="glide"
@khan-rizwan
khan-rizwan / nginx-gitbook.conf
Created June 27, 2020 15:38
nginx location block for hosting gitbooks on your domain custom path
location /docs/ {
proxy_pass http://{author}.gitbook.io/{book}/;
sub_filter_once off;
sub_filter_types *;
sub_filter "/{book}/" "/docs/";
}
@khan-rizwan
khan-rizwan / nearby-coordinates.sql
Created November 29, 2018 16:57 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@khan-rizwan
khan-rizwan / timezone.js
Last active November 29, 2018 16:33
Get difference between two timezones
console.log(getTZDiff('UTC+5:30','UTC+8:00'));
function getTZDiff(currentTz, otherTz) {
var selectedTz = new Date('January 1, 1970 00:00:00 ' + currentTz);
var targetTz = new Date('January 1, 1970 00:00:00 ' + otherTz);
var difference = selectedTz.getTime() - targetTz.getTime();
var hours = (difference / 3600000);
if (hours < 0) return Math.abs(hours) + " hours behind";
return Math.abs(hours) + " hours ahead";
}
@khan-rizwan
khan-rizwan / install-go.sh
Last active July 18, 2018 23:22
install-go.sh
#!/bin/bash
export GO_VERSION=1.10
export GO_DOWNLOAD_URL=https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz
export GOPATH=/root/local/lib/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
mkdir ${GOPATH}
chown ${USER} -R ${GOPATH}
@khan-rizwan
khan-rizwan / wsl-go-install.sh
Created July 17, 2018 21:24
Script to install Go 1.8.3 on Linux and WSL (Windows Subsystem for Linux)
#!/bin/bash
set -e
GVERSION="1.8.3"
GFILE="go$GVERSION.linux-amd64.tar.gz"
GOPATH="$HOME/projects/go"
GOROOT="/usr/local/go"
if [ -d $GOROOT ]; then
echo "Installation directories already exist $GOROOT"
@khan-rizwan
khan-rizwan / ubuntudocker.sh
Last active July 17, 2018 14:03 — forked from fredhsu/ubuntudocker.sh
Shell script to install Docker CE on ubuntu and post-install user configuration
#!/bin/bash
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
@khan-rizwan
khan-rizwan / main.go
Created January 3, 2018 15:36
How to pass a slice as a variadic input?
package main
import (
"fmt"
)
func echo(strings []int) []interface{} {
ids := []interface{}{}
for _, s := range strings {
ids = append(ids, s)