Skip to content

Instantly share code, notes, and snippets.

View stepankuzmin's full-sized avatar
🥡

Stepan Kuzmin stepankuzmin

🥡
View GitHub Profile
@stepankuzmin
stepankuzmin / st_invert.sql
Created June 26, 2015 13:14
PostGIS polygon inversion function — allows to invert polygon with 900913 SRID
create function st_invert(geometry) returns setof geometry as
'SELECT st_difference(st_geomfromtext(''POLYGON((-20037508.3427892 147730758.194568,
20037508.3427892 147730758.194568,
20037508.3427892 -147730762.669922,
-20037508.3427892 -147730762.669922,
-20037508.3427892 147730758.194568))'', 900913), $1)'
language sql;
@stepankuzmin
stepankuzmin / to_geojson.sh
Created July 6, 2015 10:47
Save PostGIS table to geojson file
psql -d pri -c 'select st_asgeojson(st_transform(st_union(geometry), 4326)) as geometry from osm_suburbs' | awk '/coordinates/ {print $1}' > result.geojson
@stepankuzmin
stepankuzmin / update-db.sh
Created August 10, 2015 10:02
Update OSM database
#!/bin/bash
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
for subject in 'AMU' 'CHU' 'KAM' 'KHA' 'MAG' 'PRI' 'SA' 'SAK' 'YEV'
do
filename="RU-$subject.osm.pbf"
url="http://be.gis-lab.info/data/osm_dump/dump/latest/$filename"
@stepankuzmin
stepankuzmin / tilemill-export.sh
Last active August 29, 2015 14:27
Export mbtiles using Tilemill
#!/bin/bash
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
# --- SET UP THIS ---
PROJECT=OSMBright
EXPORTNAME=osm-bright
@stepankuzmin
stepankuzmin / GOST_7.67-2003.R
Last active September 11, 2015 13:28
Перечень названий стран и их коды по ГОСТ 7.67-2003
library(XML)
library(httr)
GOST_7_67_2003 <- (function() {
url <- "https://ru.wikipedia.org/wiki/%D0%93%D0%9E%D0%A1%D0%A2_7.67"
content <- content(GET(url), as="text")
html <- htmlParse(content, asText=TRUE)
tables <- readHTMLTable(html)
table <- tables[[1]]
table[complete.cases(table),]
@stepankuzmin
stepankuzmin / transliterate.rb
Created October 5, 2015 10:49
Transliterate osm2pgsql openstreetmap data table to English using Ruby
#!/usr/bin/env ruby
require 'pg'
require 'colorize'
require 'translit'
# Output a table of current connections to the DB
conn = PG.connect( dbname: 'astrakhan' )
# conn.exec( "ALTER TABLE planet_osm_line ADD COLUMN name_en text;" )
#!/bin/bash
green=`tput setaf 2`
reset=`tput sgr0`
dt=`date '+%Y.%m.%d_%H-%M-%S'`
backup_path=$HOME/backup/$dt
db_backup=$backup_path/astrakhan_production.sql
uploads_backup=$backup_path/uploads.tar.bz2
@stepankuzmin
stepankuzmin / distance-matrix.js
Created February 2, 2016 17:12
OSRM distance matrix
// ./osrm-routed --max-table-size 1000000 moscow_russia.osrm
var turf = require('turf')
var request = require('request')
// var extent = [37.35,55.56,37.87,55.94], // moscow
var extent = [37.606,55.731,37.640,55.752],
cellWidth = 0.1,
units = 'kilometers',
url = 'http://127.0.0.1:5000/table?'
@stepankuzmin
stepankuzmin / start.bat
Last active February 19, 2016 14:02
Start bat file command with timeout
START cmd /k "npm start"
start cmd /k "TIMEOUT /T 15 /NOBREAK && "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk http://localhost:3333"
@stepankuzmin
stepankuzmin / formatInt.coffee
Created April 11, 2016 09:54
Format integer as string with spaces that separates thousands
formatInt = (str) ->
reducer = (acc, item, index) ->
acc.push(' ') if index % 3 == 0
acc.push(item)
acc
str.toString()
.split('')
.reverse()
.reduce(reducer, [])