Skip to content

Instantly share code, notes, and snippets.

View maxdanilov's full-sized avatar
🦉

Maxim Danilov maxdanilov

🦉
View GitHub Profile
@maxdanilov
maxdanilov / docker-compose.yml
Created January 14, 2018 18:35
docker-compose.yml for deluge
version: "2.3"
services:
deluge:
image: linuxserver/deluge
network_mode: host
container_name: deluge
restart: always
environment:
- UMASK_SET=022
- PGID=0
@maxdanilov
maxdanilov / package-locker.sh
Last active August 3, 2018 23:10
Lock versions in package.json from package-lock.json or npm-shrinkwrap.json
#!/bin/sh
set -e
PACKAGE_JSON="package.json"
PACKAGE_JSON_NEW="package.new.json"
PACKAGE_LOCK="package-lock.json" # default. when shrinkwrap used, is npm-shrinkwrap.json
function usage() {
echo "Usage: ${0} -d=<abs-path-to-dir-with-package.json> [-lf=<name-of-the-lock-file>]"
@maxdanilov
maxdanilov / bindparam.py
Created January 6, 2017 16:26
Operators applied to static values and not columns in SQLAlchemy
# Imagine Model has start_time field and you want to filter all events that
# fall into an intersection of two DateTimeRanges (tsrange in PostreSQL).
# Doing daterange intersections in Python is tedious, Postgresql is much better at it.
# That requires applying operators to a value (not a column) and that is not so
# straightforward:
query = DB.session.query(Model)
range1 = DateTimeRange(datetime(2017, 1, 5, 0), datetime(2017, 1, 5, 10, 5))
@maxdanilov
maxdanilov / docker_in_serverspec.rb
Last active May 8, 2017 01:49
[Serverspec] running tests inside a Docker container
require 'spec_helper'
# the root folder should contain Dockerfile so build_from_dir can work
describe "mycontainer" do
before(:all) do
image = Docker::Image.build_from_dir('.')
@container = image.run()
set :os, family: :debian
set :backend, :docker
@maxdanilov
maxdanilov / postgres_replication_lag.sql
Last active November 18, 2016 22:18
[PostgreSQL] Replication lag between primary and replica (in bytes)
SELECT client_addr, pg_xlog_location_diff(pg_stat_replication.sent_location, pg_stat_replication.replay_location) AS byte_lag FROM pg_stat_replication;
@maxdanilov
maxdanilov / datetime_to_epoch.py
Last active November 18, 2016 22:17
[Python] Datetime String to Epoch Time
import calendar, datetime
import pandas as pd
date_str = '2016-01-01T00:00:00+01:00'
date = pd.to_datetime(date_str).tz_localize('UTC')
print calendar.timegm(date.timetuple()) # 1451602800
# Using strftime('%s') is not recommended as it depends on the timezone of the machine
@maxdanilov
maxdanilov / mock_datetime.py
Last active November 18, 2016 22:17
[Python] Mocking datetime in unit tests
# Taken from https://solidgeargroup.com/mocking-the-time
# (unlike many answers on StackOverflow, this one actually works and is easy to use)
import datetime
import mock
def mock_datetime(target, datetime_module):
real_datetime_class = datetime.datetime