Skip to content

Instantly share code, notes, and snippets.

View pavlov99's full-sized avatar
:shipit:
Coding mode

Kirill Pavlov pavlov99

:shipit:
Coding mode
View GitHub Profile

Keybase proof

I hereby claim:

  • I am pavlov99 on github.
  • I am p99 (https://keybase.io/p99) on keybase.
  • I have a public key whose fingerprint is 247B E451 E71C 8AAD 6AF2 7842 5849 1A6C A92B 0F59

To claim this, I am signing this object:

@pavlov99
pavlov99 / crossjoin.py
Last active September 12, 2019 10:19
Pandas cross-join
from functools import reduce
def crossjoin(*dfs, **kwargs):
"""Calculate a cartesian product of given dataframes.
Subsequently join each dataframe using a temporary constant key and then remove it.
Also set a MultiIndex - cartesian product of the indices of the input dataframes.
See: https://github.com/pydata/pandas/issues/5401
Args:
@pavlov99
pavlov99 / javascript-dependencies.sh
Created August 24, 2018 03:27
Visualize JavaScript dependencies
# Install madge (https://github.com/pahen/madge) and graphviz first
madge --dot --layout neato --include-npm src/ | dot -Tpng > dependencies.png
@pavlov99
pavlov99 / test-javascript.sh
Created August 24, 2018 01:40
Find all *.spec.js testing files in src/ folder and execute with node.js
# This command line executes all test files with NodeJS.
# Test files are located in ./src folder and have *.spec.js
# In order to use ES6 import/export syntax, reify is required: https://github.com/benjamn/reify
# `find` command generates a "test file" which require() every actual test.
# If the output is TAP-compatible, one could pipe it to ./node_modules/.bin/tap-mocha-reporter spec
node --require reify -e "$(find ./src -name '*\.spec\.js' -type f -exec echo "require('{}');" \; | paste -s -d' ' -)"
@pavlov99
pavlov99 / update-photo-metadata.sh
Created July 22, 2018 06:40
Update incorrectly set image metadata in batch. Set geo location (latitude, longitude) and time.
#!/usr/bin/env bash
# Update photo information: time and location.
# After photo editing by agency, all of the meta tags were changed. This script fixes it.
# Photos are ordered by filename, e.g. 001.jpg, 002.jpg, etc. The whole event happened
# between 16:30 and 21:00 Moscow time on 30th June. Set time to every picture as if they were
# taken uniformly during the event.
#
# See also:
# exiftool https://www.sno.phy.queensu.ca/~phil/exiftool/ (allows batch editing as well).
# https://www.latlong.net/ to find your location and get latitude and longitude info.
@pavlov99
pavlov99 / enum.py
Created June 6, 2018 09:55
Python helpers
class Choices(object):
""" Choices."""
def __init__(self, *choices):
self._choices = []
self._choice_dict = {}
for choice in choices:
if isinstance(choice, (list, tuple)):
@pavlov99
pavlov99 / combine-pdfs.sh
Created May 19, 2018 08:30
Combine multiple PDF files into one with dockerized PDFtk
docker run -v "$(pwd)":/work mnuessler/pdftk *.pdf cat output combined.pdf
# Install linux pipe viewer and optional dialog
sudo apt-get install dialog
# Archive:
tar cf - /folder-with-big-files -P | pv -s $(du -sb /folder-with-big-files | awk '{print $1}') | gzip > big-files.tar.gz
# OSX:
tar cf - /folder-with-big-files -P | pv -s $(($(du -sk /folder-with-big-files | awk '{print $1}') * 1024)) | gzip > big-files.tar.gz
# Unarchive:
pv file.tgz | tar xzf - -C target_directory
@pavlov99
pavlov99 / GPG-keys.sh
Created April 2, 2017 16:40
GnuPG key management
# Add gpg key: https://help.ubuntu.com/community/GnuPrivacyGuardHowto
# Install GnuPG from https://www.gnupg.org/download/index.html
gpg2 --full-generate-key
# Delete gpg key
gpg --delete-secret-key "User Name"
gpg --delete-key "User Name"
@pavlov99
pavlov99 / ansible-galaxy-find-role-id.sh
Created March 27, 2017 07:11
Find your role's id in ansible-galaxy
$ ansible-galaxy info YourUser.RoleName | grep -E 'id: [0-9]' | awk {'print $2'}