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
# If you come from bash you might have to change your $PATH. | |
export PATH=/usr/local/bin:/usr/local/sbin:$PATH | |
# Path to your oh-my-zsh installation. | |
export ZSH="/Users/fanchenbao/.oh-my-zsh" | |
# Set default editor | |
export EDITOR='nano' | |
# Set name of the theme to load --- if set to "random", it will |
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
# ggrep is the GNU grep. On macOS, it is installed via `brew install grep` | |
# Using perl regex for lookahead and lookbehind | |
# This example greps the EXACT match between quotation marks | |
aws lambda publish-version --function-name foo --profile bar | ggrep -Po '(?<=")\d+(?=")' | |
# This example counts the number of occurrences of "prod" that is wedged bewteen string literals | |
# '"Name": "' and '"' | |
aws lambda list-aliases --function-name foo --profile bar | ggrep -Pc '(?<="Name":\s")prod(?=")' |
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
" Set absolute line number for the current line and the rest is relative number | |
set number | |
set relativenumber | |
" Enable monokai theme | |
syntax enable | |
set background=dark | |
colorscheme monokai | |
" I do not remember what these do |
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
from multiprocessing.queues import Queue | |
import multiprocessing | |
# The following implementation of custom MyQueue to avoid NotImplementedError | |
# when calling queue.qsize() in MacOS X comes almost entirely from this github | |
# discussion: https://github.com/keras-team/autokeras/issues/368 | |
# Necessary modification is made to make the code compatible with Python3. | |
class SharedCounter(object): |
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 grouped_barplot( | |
ax, | |
df, | |
xlabel: str = '', | |
ylabel: str = '', | |
title: str = '', | |
width: float = 0.6, | |
loc: str = '', | |
bbox_to_anchor: List = [], | |
): |
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 timeit | |
setup = """ | |
import pandas as pd | |
from dateutil import parser | |
from datetime import datetime | |
def test_datetime(timestamp): | |
try: |
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
from argparse import ArgumentParser, RawDescriptionHelpFormatter | |
ef get_argument_parser() -> ArgumentParser: | |
"""Acquire command line arguments | |
:return: The argument parser | |
:rtype: ArgumentParser | |
""" | |
parser = ArgumentParser( |
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 unittest | |
from unittest.mock import MagicMock, patch | |
class TestFoo(unittest.TestCase): | |
"""blablabla | |
To run all the tests in TestFoo, run command | |
python3 -m unittest tests.test_foo.TestFoo |
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 chunk_read(f_obj: TextIOBase, sentinel: str, max_sentinel: int): | |
"""Read a file object in chunks | |
Read the file object line by line. Each time a sentinel is detected, we increment | |
a count. Once the count reaches max_sentinel, we have gatherered the required | |
chunk and yield it. | |
The function is inspired by this SO answer: | |
https://stackoverflow.com/a/42964612/9723036 |
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 re | |
from typing import List | |
""" | |
This scripts accumulates the 'total' column of vnstat output in this format: | |
wlan0 / hourly | |
hour rx | tx | total | avg. rate |
NewerOlder