Skip to content

Instantly share code, notes, and snippets.

@dvdotsenko
dvdotsenko / gist:1010740
Last active August 16, 2017 21:57
Git tune up script - Windows
git config --global alias.co checkout
git config --global alias.cm commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.cp cherry-pick
git config --global alias.ll log --pretty=format:"%C(yellow)%h\\ %Creset%s%Cblue\\ [%cn]\\%Cred%d" --decorate --numstat
git config --global alias.diverged log --left-right --graph --cherry-pick --oneline $1...origin/$1
git config --global core.autocrlf false
git config --global core.filemode false
@dvdotsenko
dvdotsenko / .gitignore
Created June 6, 2011 18:18
Git tune up - gitignore - Windows
#ignore thumbnails created by windows
Thumbs.db
#Ignore files build by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
@dvdotsenko
dvdotsenko / gist:3870302
Created October 11, 2012 05:09
Tornado server AppTomatic - web app manufacturing same process, different threads
# Copyright 2009 Daniel Dotsenko [email protected]
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@dvdotsenko
dvdotsenko / gist:6362254
Last active December 21, 2015 20:38
Python execution timer to be used over `with` statement.
import datetime as datetime_module
import time
class Timer:
def __init__(self, label=None):
self.label = '%s : ' % (label or 'no label provided')
return
def __enter__(self):
self.start = datetime_module.datetime.utcnow()
self.start_cpu = time.clock()
return self

Keybase proof

I hereby claim:

  • I am dvdotsenko on github.
  • I am ddotsenkobn (https://keybase.io/ddotsenkobn) on keybase.
  • I have a public key whose fingerprint is FE81 F530 498A A2C9 E253 FF7B 05D3 C7D6 E7B4 5A4B

To claim this, I am signing this object:

@dvdotsenko
dvdotsenko / apply_env_vars.py
Created September 3, 2017 05:11
Python env vars apply to config
def apply_env_vars(module_name, env_var_prefix='productname', remove_module_prefix='config.'):
import os
import sys
env_var_prefix = '_'.join(
env_var_prefix.upper().split('.') +
module_name[len(remove_module_prefix):].upper().split('.')
) + '__'
module = sys.modules[module_name]
prefix_len = len(env_var_prefix)
@dvdotsenko
dvdotsenko / tztools.py
Last active August 31, 2021 19:45
Timezone-aware datetime time zone conversions in Python
"""
Copyright 2017 Daniel Dotsenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@dvdotsenko
dvdotsenko / TestIdFactory.jsx
Last active July 15, 2019 04:00
React + Hooks + Context = easier way to scope TestID tree for elements
import React from 'react'
export function TestIdFactory(separator='-') {
const TestIdContext = React.createContext('')
function TestId({add, set, children}) {
if (!add && !set) {
throw(new Error('Either "set" or "add" prop must be set'))
}
@dvdotsenko
dvdotsenko / dataclass_recursive_deserialize.py
Created November 25, 2020 04:02
Python Recursive / Nested `dataclass` instances deserialization worker. Simple.
"""
Code that creates nested `dataclass` instances tree from JSON data.
Somewhat similar to what Pydantic, Schematics do out of the box,
but native Python dataclasses don't do automatically.
See discussion here for context
https://stackoverflow.com/questions/51564841/creating-nested-dataclass-objects-in-python
See tests on the bottom of this file usage examples.
Tested on Python 3.9
@dvdotsenko
dvdotsenko / aio_map.py
Last active May 13, 2022 08:50
python asyncio map() and filter() Like Gevent imap_unordered Can chain / wrap one into another.
import asyncio
from collections import deque
from typing import Any, Callable, Collection, AsyncIterator, Iterator, Union
async def _next(gg):
# repackaging non-asyncio next() as async-like anext()
try:
return next(gg)
except StopIteration: