Skip to content

Instantly share code, notes, and snippets.

@viet-wego
viet-wego / s3-get-folder-size.py
Last active February 15, 2019 06:25
List all folder and size within a s3 bucket
import boto3
import sys
import decimal
def main():
bucket = sys.argv[1]
client = boto3.client('s3')
result = client.list_objects_v2(Bucket=bucket, Delimiter='/')
for o in result.get('CommonPrefixes'):
@viet-wego
viet-wego / create-new-disk.md
Last active September 10, 2018 06:09
Create and format new disk on Google Cloud Platform

1. Create new disk:

gcloud compute disks create dev-postgres-master --size=500GB --type=pd-standard

2. Create new instance:

gcloud compute instances create viet-temp

3. Attach new disk to new instance:

@viet-wego
viet-wego / gcr_clean_up.sh
Last active September 7, 2018 10:36
Bash script to clean up Google Container Registry by keeping recently images
#!/bin/bash
project=your-awesome-project-id
main() {
for image in $(gcloud container images list --repository=gcr.io/$project); do
if [[ $image != 'NAME' ]]; then
# clean up dummy tags
clean_up_image $image "NOT tags:dev* AND NOT tags:staging* AND NOT tags:production* AND NOT tags:latest" 0
@viet-wego
viet-wego / Jenkinsfile
Created June 14, 2018 02:52
Declarative Jenkins pipeline file sample
#!/usr/bin/env groovy
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import hudson.model.Actionable;
pipeline {
agent { label 'golang' }
options {
ansiColor('xterm')
@viet-wego
viet-wego / config
Created April 10, 2018 03:38
SSH config file ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/viet_zm_mac
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/viet_zm_mac
Host bitbucket.org
HostName bitbucket.org
@viet-wego
viet-wego / unzip.java
Created February 12, 2018 13:40
Unzip a file with java 8
public static List<String> unzip(String zipFilePath) {
try {
File zipFile = new File(zipFilePath);
try (ZipInputStream inputStream = new ZipInputStream(new FileInputStream(zipFile))) {
List<String> fileList = new ArrayList<>();
ZipEntry entry = inputStream.getNextEntry();
while (entry != null) {
File newFile = new File(zipFile.getParent() + File.separator + entry.getName());
new File(newFile.getParent()).mkdirs();
if (!entry.isDirectory()) {
@viet-wego
viet-wego / func_get_distance.sql
Last active December 4, 2017 16:15
MySQLfunction get distance between 2 points in km
use `your_schema`;
drop function if exists `get_distance`;
delimiter $$
use `your_schema`$$
create function `get_distance` (lat1 decimal(9,6), lng1 decimal(9,6), lat2 decimal(9,6), lng2 decimal(9,6)) returns decimal(10,3)
begin
declare R decimal(30,15);
declare rlat1 decimal(30,15);
declare rlat2 decimal(30,15);
@viet-wego
viet-wego / download.js
Created July 9, 2017 08:42
Pluralsight video download
//1
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
//2
jQuery.noConflict();
@viet-wego
viet-wego / SwapCreating
Last active June 20, 2017 10:25
Create swap for linux
sudo dd if=/dev/zero of=/swapfile count=2048 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
@viet-wego
viet-wego / Unziper.java
Created December 21, 2016 16:19
Sample java code to unzip a file to current directory.
package com.github.viettd.how.to;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;