Instantly share code, notes, and snippets.

☄️
Lucid

Roger Qiu CMCDragonkai

View GitHub Profile
View conftest.py
import pytest
from pathlib import Path
@pytest.fixture(scope='session')
def project_root(pytestconfig):
return Path(pytestconfig.rootdir)
View pop_var_from_subpop_var.py
import numpy as np
# you can calculate the variance of the population based variance of each subpopulation
# the population variance is the sum of the "between group variance" and the "within group variance"
# divided by the total number of samples
groups = [np.array([1,2,3,4]), np.array([5,6])]
pop_mean = (1 + 2 + 3 + 4 + 5 + 6) / 6
pop_var = (
sum([group.size * ((group.mean() - pop_mean)**2) for group in groups]) + \
View mnist_prep_norm_z_score_cnn.py
import os
import itertools
import numpy as np
import keras.utils as utils
from pathlib import Path
from mnist import MNIST
def chunk_gen(size, iterable):
it = iter(iterable)
View open_graphviz.sh
#!/usr/bin/env sh
dot ./graph.gv -Tpng | feh -
View download_stream_hash.py
import hashlib
from urllib.request import urlopen
from urllib.error import HTTPError
file_url = 'https://somefile'
file_path = 'somefile'
sha256_hash = '751baea102ae63f0990607883ff819cfe18276d5116605673c5ff7e42e34e945'
hash = hashlib.sha256()
response = urlopen(file_url)
View conftest.py
import pytest
@pytest.fixture(scope='session')
def api_client(api_environment):
from YOURFLASKMODULE import app
# switch on testing mode to propagate exceptions from within the app
app.testing = True
# this is needed when testing to allow url_for URL generation
app.config['SERVER_NAME'] = 'localhost'
View using_gpg_agent.md

Using GPG Agent

Try running echo UPDATESTARTUPTTY | gpg-connect-agent.

View install_fonts_on_linux.md

Install fonts on Linux

Copy font files like .otf and .ttf into ~/.local/share/fonts.

Run:

fc-cache
fc-list -v | grep FONTNAME
View embedded_databases_database_libraries.md

Embedded Databases or Database Libraries

  1. SQLite
  2. TileDB
  3. Irmin
  4. RocksDB
  5. LMDB

What about a blockchain DB library that

View stream_shuffling.py
import random
# stream shuffling can be done if the output stream has random read/write
# we use the fisher yates shuffling algorithm
input_list = [1,2,3,4,5]
output_list = []
for (i, v) in enumerate(input_list):