This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Workaround script to copy from hdfs file system to NAS | |
# solving permission limitation at writing on NAS directly with hdfs command | |
# | |
# Usage: | |
# $ hdfs2Nas <full path> <destination directory> | |
SOURCE=$1 | |
DEST=$2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Recreate a user that was created previously | |
# TODO: this onworking script has the side effect of setting the ownership badly on user with | |
# previous same userid. Must be fixed. | |
# create user | |
username=$1 | |
adduser $username --home /data/users/$username |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def belongs_to(t, a, b): | |
"""Return True if t belongs to real number interval [a, b], False otherwise.""" | |
return t >= a and t <= b | |
def is_in_arc(t, a, b, m=365): | |
"""Return True if t is in the interval [a, b] modulo m, False otherwise""" | |
t, a, b = [x % m for x in (t, a, b)] # convert all the values to their values modulo m | |
if a < b: | |
return belongs_to(t, a, b) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
def describe_df(df, cols=None, max_distinct=10): | |
"""Describe columns of given dataframe. | |
Return a dataframe with column name, type, nb of distinct values and nb of missing values | |
Missing values are counted as one distinct value. | |
Issue: if a column contains integer and missing values, pandas cast it in float and add .0 to the value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
def describe_df(df, cols=None, max_distinct=10): | |
"""Describe columns of given dataframe. | |
Return a dataframe with column name, type, nb of distinct values and nb of missing values | |
Missing values are counted as one distinct value. | |
Issue: if a column contains integer and missing values, pandas cast it in float and add .0 to the value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dataframe_constructor(df): | |
return "df = pd.DataFrame(%s)" % (str(df.to_dict()).replace("nan"," float('nan')").replace('array', 'np.array')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
import numpy as np | |
def r_cut(x0: float, x1: float, r: float) -> (float, float): | |
"""Return y0, y1 such that y1/y0 = r, y0<x0, y1<x1 and y0+y1 is maximum. | |
Parameters | |
---------- | |
x0, x1 > 0 | |
r >= 0 and <= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd my_project #where Pipfile resides | |
$ pipenv install ipykernel | |
$ pipenv shell #if not already done before | |
(my-virtualenv-name) $ python -m ipykernel install --user --name=my-virtualenv-name | |
(my-virtualenv-name) $ jupyter lab #or jupyter notebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import boto3 | |
s3client = boto3.client('s3') | |
response = s3client.list_buckets() | |
for bucket in response['Buckets']: | |
print(f"""\'{bucket['Name']}\',""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# for listing and selecting the buckets you want to delete use list_s3_buckets.py gist | |
import boto3 | |
# list of the bucket names you want to delete | |
BUCKETS_TO_DELETE = [] | |
def delete_versioned_bucket(s3resource, bucket_name): |
OlderNewer