Skip to content

Instantly share code, notes, and snippets.

View nchaly's full-sized avatar
🦊
Yeah-yeah..

Mikalai Chaly nchaly

🦊
Yeah-yeah..
View GitHub Profile
def import_submodules(module: ModuleType, level: int = 1, modules_only: bool = True) -> List[str]:
"""Import all submodules of a module, recursively.
Args:
modules_only: If set to True, only modules are imported. If False, packages are
imported as well.
module: Module/package which sub-modules should be imported.
level: Limit import depth. Set to zero or negative to import all level.
For example the following structure is present:
.. code-block::
@nchaly
nchaly / date_range_overlap.py
Created February 9, 2022 09:27
Find pandas date range overlap
import pandas as pd
import numpy as np
days = pd.date_range('2021-01-01', '2021-12-31', freq='d')
# items
items = []
item_ids = range(100)
@nchaly
nchaly / parameterize.py
Created September 27, 2019 10:53
How to pass arguments to jupyter notebook (via papermill), run it (using nbconvert), and then write output to html file.
import nbformat
import os
from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
from nbconvert import HTMLExporter
from nbconvert.writers import FilesWriter
import papermill.parameterize
def prepare_metadata(nb):
if not hasattr(nb.metadata, 'papermill'):
@nchaly
nchaly / yammer-mark-all-as-read.user.js
Last active August 29, 2015 14:26
A script to mark all yammer inbox items as read
// ==UserScript==
// @name Mark All Read
// @namespace Yammer
// @description Marks all incoming messages as read
// @include https://www.yammer.com/*
// @version 1
// @grant none
// ==/UserScript==
var limit = 300;
@nchaly
nchaly / SolrUnityModule.cs
Created March 28, 2014 06:24
PostSolrConnection registration with Unity
public class SolrUnityModule
{
public static void RegisterSolrOperations(UnityContainer container, bool registerPostOperations)
{
//register regular implementation
var solrConfig = (SolrConfigurationSection)ConfigurationManager.GetSection("solr");
new SolrNetContainerConfiguration().ConfigureContainer(solrConfig.SolrServers, container);
//PostConnection registration
if (registerPostOperations)