Skip to content

Instantly share code, notes, and snippets.

View sorokine's full-sized avatar

Alexandre Sorokine sorokine

  • ORNL
  • Tennessee
  • 14:05 (UTC -04:00)
  • X @sorokine
View GitHub Profile
id,name,amount
109,"building",1456894
164,"house",1383613
7,"Shopping and services",839415
17,"store / shop",831628
203,"school",676869
4,"dining and leisure",671035
74,"restaurant",385073
194,"park",283545
163,"sport venue",274433

finding xpath from element text in python 2.7

import lxml.html
myfile = open('index.html', 'r')
data=myfile.read()
h=lxml.html.fromstring(data)
from lxml import etree
tree=etree.ElementTree(h)
ft=tree.xpath(u"//text()[contains(., '')]")

git for data and history

data

major problem issues

  • diffs
  • none-file based data

approaches

@sorokine
sorokine / gist:a6c509f343a8be12ba2a2421483d69cb
Last active November 9, 2019 19:15
du on Directories with Spaces

#du on Directories with Spaces

To get the sizes of all subdirectories including the hiddsn ones I typically use the command:

du -sh $(ls -A)

However, this command does not work well if you have directory names with spaces. Here is how you can do it:

@sorokine
sorokine / GeoVizDisplayWall.md
Last active November 9, 2019 19:15
How to Build a Display Wall for GeoViz

How to Build a Display Wall for GeoViz

What is a display wal?

Display walls (compound flat monitors with a very large number of pixels) is a very useful tool for geovizualization because of their unique ability to display multiple geographic scales at once. My paper on the topic:

Sorokine, Alexandre. “Implementation of a Parallel High-Performance Visualization Technique in GRASS GIS.” Computers & Geosciences 33, no. 5 (2007): 685–95. doi:http://dx.doi.org/10.1016/j.cageo.2006.09.008.

Also display walls have a very strong Wow! factor if you are interested in that.

Keybase proof

I hereby claim:

  • I am sorokine on github.
  • I am sorokine (https://keybase.io/sorokine) on keybase.
  • I have a public key whose fingerprint is 32FB CE7C D47C 3C10 3785 561F 207E 07E9 A4D3 4B70

To claim this, I am signing this object:

@sorokine
sorokine / gist:7790185
Last active December 30, 2015 06:38
Random point in polygon in PostGIS

Random point in polygon in PostGIS

Existing function for generating of random point in polygon in PostGIS may take a very long time in narrow and long polygons because the functions have to test lots of points that fall within bounding rectangle but outside actual polygon. Examples are here and here.

The idea is to use a function to subdivide bounding rectangle recursively and process only tiles that overlap with the polygon:

  1. subdivide the bounding rectangle into smaller rectangles (2, 4, or more, whichever is easier)
  2. randomly pick a rectangle
  3. create an intersection of the rectangle with the original polygon, return to the previous step if intersection is empty
  4. check if the ratio between the areas of the rectangle and intersection is big enough
#!/bin/bash
convert_dir=$1
output_dir=$2
bitrate=$3
# Ensure require params are passed in
if [ -z $convert_dir ] || [ -z $output_dir ];
then
echo "Usage: flac2mp3 rip_dir output_dir [bitrate]"
exit