Skip to content

Instantly share code, notes, and snippets.

View lykhvar's full-sized avatar

Artem lykhvar

  • Everywhere, Ukraine
View GitHub Profile
@lykhvar
lykhvar / walg-pitr.md
Created September 7, 2020 07:51 — forked from pohzipohzi/walg-pitr.md
PostgreSQL Point-In-Time-Recovery (PITR) with WAL-G

WAL-G PITR

This gist summarises a way to simulate point-in-time recovery (PITR) using WAL-G. Most of the material is adapted from Creston's tutorial.

Setup

First we initialize a database cluster

pg_ctl init -D cluster
@lykhvar
lykhvar / postgres_queries_and_commands.sql
Created December 11, 2018 06:36 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@lykhvar
lykhvar / rounding_decimals.md
Created May 26, 2018 08:45 — forked from jackiekazil/rounding_decimals.md
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value

@lykhvar
lykhvar / useful_pandas_snippets.py
Created November 16, 2017 20:44 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@lykhvar
lykhvar / arr-stat.js
Created November 4, 2017 02:41 — forked from Daniel-Hug/arr-stat.js
JavaScript statistical functions for arrays: max, min, range, midrange, sum, mean / average, median, modes, variance, standard deviation, mean absolute deviation, z scores
var arr = {
max: function(array) {
return Math.max.apply(null, array);
},
min: function(array) {
return Math.min.apply(null, array);
},
range: function(array) {
@lykhvar
lykhvar / curl.md
Created October 4, 2017 11:13 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@lykhvar
lykhvar / gist:02c0bbeda017d56694f134fc92811a72
Created October 31, 2016 09:18 — forked from jpetazzo/gist:6127116
Debian/Ubuntu containers protips, thanks to @spahl
# this forces dpkg not to call sync() after package extraction and speeds up install
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup
# we don't need and apt cache in a container
RUN echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache
@lykhvar
lykhvar / gist:bdb3e89d0794925632340add693379fa
Created September 26, 2016 19:53 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@lykhvar
lykhvar / osm_to_shapefile.py
Created March 21, 2016 04:15 — forked from robintw/osm_to_shapefile.py
Code to convert OSM XML files with waypoints defining polygons into a shapefile with those polygons in it
import xml.etree.cElementTree as ET
from shapely.geometry import mapping, Polygon
import fiona
import os
input_filename = "villages.osm"
output_filename = "villages.shp"
# Parse the XML from the OSM file
tree = ET.ElementTree(file=input_filename)