Skip to content

Instantly share code, notes, and snippets.

View Nikasa1889's full-sized avatar

DANG HA THE HIEN Nikasa1889

View GitHub Profile
@Nikasa1889
Nikasa1889 / run_jupyter.sh
Last active October 3, 2018 08:13
Run an Adhoc Jupyter service for datascience
# Run the following command to start jupyter with custom password
## The current directory will be mapped to the /home/jovyan in the docker
## User is granted root access
## New password can be set using its hash, hash of password can be obtained by:
### from IPython.lib import passwd
### passwd("this_is_a_password") #Output: 'sha1:9743a64265c5:5775f49cb5577d50234260a661cb520b1dc07ed3'
docker run -p 8888:8888 --user root -e NB_GID=100 -e GRANT_SUDO=yes -v "$PWD":/home/jovyan jupyter/scipy-notebook:hoangmt start-notebook.sh --NotebookApp.password='sha1:9743a64265c5:5775f49cb5577d50234260a661cb520b1dc07ed3' -d
# Save changes to the running container by commiting its image
# get hash of the container to be commited
docker ls
import attr
from datetime import datetime
from attr import fields
@attr.s(slots=True)
class Small:
a = attr.ib(type=float, metadata={'JSON':'A'})
@attr.s(slots=True)
class TestField:
@Nikasa1889
Nikasa1889 / bisect_sort.py
Last active July 26, 2020 03:35
Test performance of python's bisect and best data struture to work with it
import timeit
setup='''
import random, bisect
from collections import deque
random.seed('slartibartfast')
s = [random.random() for i in range(1000)]
timsort = sorted
from datetime import datetime as dt
from multiprocessing import Pool
from tqdm import tqdm
from features import *
from sklearn.metrics import mean_squared_error
import sys
def cv_model(args):
'''Cross validate a predefined model with a given time series
Note: receive one args so that it can be call by worker pool easily'''
url = "%s/timeseries/%s/typeClass/%d/resolution/%d/" \
% (endpoint, asset_id, type_class, resolution_id)
params = {'from': from_date, 'to': to_date}
url = url + "?" + urllib.urlencode(params)
# b64Val = base64.b64encode(username+":"+password)
# response.headers['Authorization'] = "Basic %s" %b64Val
resp = requests.get(url, params, auth=(username, password)).json()
DATA_DIR = "appleoutput40"
SC_DATA_DIR = "split_appleoutput40"
VAL_PERCENTAGE = 0.2
from os.path import normpath, basename
from shutil import copyfile
import random
import os
subdir_imgs = [(subdir, files) for subdir, dirs, files in os.walk(DATA_DIR) if len(files)>50]
@Nikasa1889
Nikasa1889 / ConsumptionMeasurement.cs
Created July 14, 2017 07:46
Influx Data Model in C#
[InfluxMeasurement("consumption")]
public class ConsumptionMeasurement:InfluxMeasurementBase
{
[InfluxTimestamp]
public override DateTime Timestamp { get; set; }
[InfluxTag("assetguid")]
public Guid AssetGuid { get; set; }
[InfluxTag("consumptiontype")]
# [filter size, stride, padding]
#Assume the two dimensions are the same
#Each kernel requires the following parameters:
# - k_i: kernel size
# - s_i: stride
# - p_i: padding (if padding is uneven, right padding will higher than left padding; "SAME" option in tensorflow)
#
#Each layer i requires the following parameters to be fully represented:
# - n_i: number of feature (data layer has n_1 = imagesize )
# - j_i: distance (projected to image pixel distance) between center of two adjacent features
@Nikasa1889
Nikasa1889 / execBashDocker.sh
Created March 6, 2017 15:14
Bash script to open bash shell on a running docker
#!/bin/bash
#List current running docker images
echo "Select one of the following running images:"
echo -e "Number \t Name"
echo $(docker ps | tail -n +2| awk -F ' ' '{printf("%7d %s\n", NR, $2)}')
read -p "Enter the process number:" selectedID
selectedID=$(($selectedID + 1))
#Get Docker process ID of the specified docker image name
DOCKER_ID=$(docker ps | tail -n +$selectedID | head -1 | awk '{print $1}')
docker exec -it $DOCKER_ID /bin/bash