Skip to content

Instantly share code, notes, and snippets.

View ammario's full-sized avatar
🌐

Ammar Bandukwala ammario

🌐
View GitHub Profile
@ammario
ammario / google_connect.go
Last active August 21, 2016 22:47
Connect to Google Cloud with logging
package main
import (
"github.com/stratexio/gclog"
"golang.org/x/net/context"
"google.golang.org/cloud"
"google.golang.org/cloud/storage"
)
@ammario
ammario / install_go.sh
Last active September 17, 2019 21:47
Install golang
#!/bin/bash
set -euf -o pipefail
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
rm -rf /usr/local/go || true
rm /usr/local/bin/go || true
@ammario
ammario / ipint.go
Last active April 20, 2024 12:51
Golang IP <-> int conversion
func ip2int(ip net.IP) uint32 {
if len(ip) == 16 {
return binary.BigEndian.Uint32(ip[12:16])
}
return binary.BigEndian.Uint32(ip)
}
func int2ip(nn uint32) net.IP {
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, nn)
@ammario
ammario / keybase.md
Created May 12, 2016 20:05
Keybase Proof

Keybase proof

I hereby claim:

  • I am ammario on github.
  • I am ammar (https://keybase.io/ammar) on keybase.
  • I have a public key ASCHuUmMssaRVYYIHqKdvCGN7rrhbz5qlq3vzZJF3ZU0EAo

To claim this, I am signing this object:

@ammario
ammario / connect_mysql.go
Last active October 15, 2016 19:12
Golang connect to MySQL
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
mysqlConn, err := sql.Open("mysql", os.Getenv("MYSQL_USER")+":"+os.Getenv("MYSQL_PASS")+"@("+os.Getenv("MYSQL_HOST")+")/"+os.Getenv("MYSQL_DB") + "?parseTime=true")
if err != nil {
@ammario
ammario / gin_error.go
Created May 2, 2016 18:44
Gin JSON API error
func cError(c *gin.Context, err interface{}) {
switch err.(type) {
case error:
c.JSON(200, gin.H{
"error": err.(error).Error(),
})
case string:
c.JSON(200, gin.H{
"error": err.(string),
})
@ammario
ammario / temporary.go
Last active July 4, 2016 03:56
Golang Temporary Struct
//Removed in favor of https://github.com/ammario/temp

Keybase proof

I hereby claim:

  • I am ammarpw on github.
  • I am ammar (https://keybase.io/ammar) on keybase.
  • I have a public key whose fingerprint is ADF9 EF5C AF59 5200 DC76 B4FF 1C0F 6A4C 777E 4FE4

To claim this, I am signing this object: