Skip to content

Instantly share code, notes, and snippets.

@ebongzzang
ebongzzang / date.sh
Last active Feb 5, 2020
print all dates string between startdate and enddate in mac os
View date.sh
#!/bin/bash
startdate=$1
enddate=$2
function print_formatted() {
res=`date -j -f %Y-%m-%d $1 +%Y-%m-%d`
echo $res
}
View main.py
from itertools import chain
import numpy as np
from collections import Counter
from multiprocessing import cpu_count, Pool
def a(weights):
w_sum = np.sum(weights)
value = np.random.randint(w_sum, size=1)[0]
View admin.py
# Register your models here.
import inspect
import sys
from cytoolz import *
from django.contrib import admin
from guardian.admin import GuardedModelAdmin
from .models import *
@ebongzzang
ebongzzang / ecr-cronjob.yaml
Created Feb 22, 2019
kubernetes ecr token refresh script (all namespace)
View ecr-cronjob.yaml
# before apply below script, run command
# kubectl create clusterrolebinding ecr-cluster-rule --clusterrole=cluster-admin --serviceaccount=default:default
apiVersion: batch/v1beta1
kind: CronJob # Tell kuber' that this is a cronjob
metadata:
name: ecr-puller # Name of the job ,can be anything
namespace: default
spec:
concurrencyPolicy: Allow
@ebongzzang
ebongzzang / boto3_list.py
Last active Nov 5, 2019
get_object_list_from_bucket using boto3
View boto3_list.py
import json
import re
from io import BytesIO, StringIO
from typing import List
import requests
import bs4
import boto3
s3 = boto3.client('s3')
@ebongzzang
ebongzzang / plasma.py
Created Dec 12, 2018
pyarrow insert_df_to_plasma
View plasma.py
import numpy as np
import pandas as pd
import pyarrow as pa
from pyarrow import plasma
def insert_df_to_plasma(client, df: pd.DataFrame, key=plasma.ObjectID(np.random.bytes(20))) -> plasma.ObjectID:
record_batch = pa.RecordBatch.from_pandas(df)
object_id = key
View create_year.py
def create_yearmonth_list(start_year:int, end_year: int):
start_at = start_year * 100
end_at = end_year - start_year
for year in range(0,end_at+1):
year_acc = year*100
start = start_at + year_acc
for month in range(1,13):
yyyymm = start+month
@ebongzzang
ebongzzang / lsyncd.lua
Last active Oct 29, 2018
lsync example on mac os x
View lsyncd.lua
settings {
logfile = "/tmp/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
nodaemon = true
}
sync {
default.rsyncssh,
source="/path/to/source",
host="target-ip-address",
targetdir = "/path/to/target",
@ebongzzang
ebongzzang / list.py
Created Oct 4, 2018
nested list comprehesion, flatten and create dict from tuple list
View list.py
subland_dict = {
'hi':['hi1','hi2','hi3'],
'hello': ['hello1', 'hello2', 'hello3']
}
res = [[(y,k) for y in v] for k, v in subland_dict.items()]
# [[('hi1', 'hi'), ('hi2', 'hi'), ('hi3', 'hi')], [('hello1', 'hello'), ('hello2', 'hello'), ('hello3', 'hello')]]
merged = dict(list(itertools.chain.from_iterable(res)))
# {'hi1': 'hi', 'hi2': 'hi', 'hi3': 'hi', 'hello1': 'hello', 'hello2': 'hello', 'hello3': 'hello'}
@ebongzzang
ebongzzang / README-Template.md
Created Aug 9, 2018 — forked from PurpleBooth/README-Template.md
A template to make good README.md
View README-Template.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites