Skip to content

Instantly share code, notes, and snippets.

View vdparikh's full-sized avatar

Vishal Parikh vdparikh

View GitHub Profile
@vdparikh
vdparikh / gist:f23294ce64479b5f5981
Last active August 29, 2015 14:06
iOS - Using a different storyboard for each device type
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Whatever needs to happen before
UIStoryboard *storyboard;
BOOL isIphone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)? TRUE : FALSE;
if(isIphone) {
//iPhone Family
CGSize deviceScreenSize = [[UIScreen mainScreen] bounds].size;
@vdparikh
vdparikh / groupcache.go
Created November 7, 2016 18:45 — forked from fiorix/groupcache.go
Simple groupcache example
// Simple groupcache example: https://github.com/golang/groupcache
// Running 3 instances:
// go run groupcache.go -addr=:8080 -pool=http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082
// go run groupcache.go -addr=:8081 -pool=http://127.0.0.1:8081,http://127.0.0.1:8080,http://127.0.0.1:8082
// go run groupcache.go -addr=:8082 -pool=http://127.0.0.1:8082,http://127.0.0.1:8080,http://127.0.0.1:8081
// Testing:
// curl localhost:8080/color?name=red
package main
import (
@vdparikh
vdparikh / main.go
Created November 9, 2017 19:06
GoLang Verify/Generate JWT Token
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strings"
"time"
@vdparikh
vdparikh / install-redis.sh
Created February 13, 2018 00:26
Install REDIS on Amazon Linux
#!/bin/bash
###############################################
# To use:
# chmod +x install-redis.sh
# ./install-redis.sh
###############################################
version=4.0.8
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
@vdparikh
vdparikh / Dockerfile
Last active July 21, 2018 22:58
Golang small docker container < 10 MB
FROM alpine:latest as alpine
RUN apk --no-cache add tzdata zip ca-certificates
WORKDIR /usr/share/zoneinfo
# -0 means no compression. Needed because go's
# tz loader doesn't handle compressed data.
RUN zip -r -0 /zoneinfo.zip .
FROM scratch
ENV ZONEINFO /zoneinfo.zip
COPY --from=alpine /zoneinfo.zip /
@vdparikh
vdparikh / docker-cleanup.sh
Created May 11, 2018 18:29
Cleanup Docker Leftovers
#!/bin/bash
#
# chmod +x docker-cleanup
# cp docker-cleanup /usr/local/bin
# */10 * * * * /usr/local/bin/docker-cleanup
if [ ! $(command -v docker) ]; then
echo "Docker is not installed or not running."
exit 1
fi
@vdparikh
vdparikh / docker-compose.yml
Created May 11, 2018 18:31
Docker Compose with Go App, Postgres, Redis and MQ
version: '2'
services:
db:
image: postgres
environment:
GET_HOSTS_FROM: dns
POSTGRES_DB: dev
POSTGRES_USER: postgres-dev
POSTGRES_PASSWORD: password
ports:
@vdparikh
vdparikh / json2csv.py
Created June 21, 2018 17:55
convert json 2 csv
import sys
import json
import csv
##
# Convert to string keeping encoding in mind...
##
def to_string(s):
try:
return str(s)
package utils
import (
"bytes"
"encoding/json"
"io"
)
// data, err := generateMap(StreamToByte(resp.Body))
@vdparikh
vdparikh / README.md
Last active July 9, 2018 20:23
Presto On Mac

Installing Presto for Mac

Presto is a “Distributed SQL Query Engine for Big Data” that gives you the ability to join across data stores! 🎉

Server

The easiest way to install Presto is with Homebrew.

brew install presto