Skip to content

Instantly share code, notes, and snippets.

@acanalesg
acanalesg / get_logs_from_az_logs
Last active February 10, 2022 07:34
Logs from LogAnalytics
# Get last hour logs from container instance
az monitor log-analytics query -w 58ca4766-72b7-4610-8d1c-4b6a88a49a01 \
--analytics-query "ContainerInstanceLog_CL | where ContainerGroup_s == 'ds-tr-retail-price-engine-training-dev-process' | project Message" \
-t P0DT1H --output tsv | sed 's/PrimaryResult//'
@acanalesg
acanalesg / itemAtIndexInASplitString
Created January 29, 2022 11:15 — forked from klimaye/itemAtIndexInASplitString
sql scaler function to return an item at a specific index in a split string. Was useful to me in a select clause parsing a value like Age_0_14
CREATE FUNCTION dbo.itemAtIndexInASplitString( @stringToSplit VARCHAR(MAX), @delimiter VARCHAR(5), @indexToReturn int)
RETURNS
varchar(max)
AS
BEGIN
DECLARE @returnList TABLE ([ID] int, [Name] [nvarchar] (500))
DECLARE @name NVARCHAR(255)
DECLARE @pos INT
DECLARE @index INT
DECLARE @return_value varchar(max)
@acanalesg
acanalesg / nginx.conf
Created October 15, 2021 06:40
Nginx reverse proxy CORS fix
#
# Run in the foreground locally
# nginx -p . -c nginx.conf
#
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
@acanalesg
acanalesg / hadoop-streaming.sh
Last active September 14, 2023 12:26
hadoop streaming compression
yarn jar /usr/lib/hadoop-mapreduce/hadoop-streaming.jar -Dmapred.output.compress=true -D mapred.output.compression.codec=org.apache.hadoop.io.compress.BZip2Codec -input s3://acg-tests/dwell_plus/20161001 -output s3://acg-tests/bzip/dwell_plus/20161001/ -mapper /bin/cat -numReduceTasks 0
@acanalesg
acanalesg / geobrow_mock.py
Last active January 4, 2016 02:59
Quick Mock-up for the back-end. Only requires web.py (pip install web.py), to use it just start: ``` python geobrow_mock.py ``` And then you can call the api: ``` http://localhost:8080/cells?lat=40.12&lon=-3.687994&dist=5000 http://localhost:8080/cats?lat=40.12&lon=-3.687994&dist=5000 http://localhost:8080/domains?lat=40.12&lon=-3.687994&dist=50…
import web
import random
import json
import time
urls = (
'/cells(.*)', 'CellFinder',
'/domains(.*)', 'DomainFinder',
'/cats(.*)', 'CategoryFinder',
@acanalesg
acanalesg / gist:7599509
Created November 22, 2013 13:02
Python color scale category
colors16 = [ [51, 102, 255, 0xff],
[102, 51, 255, 0xff],
[204, 51, 255, 0xff],
[255, 51, 204, 0xff],
[255, 51, 102, 0xff],
[255, 102, 51, 0xff],
[255, 204, 51, 0xff],
[204, 255, 51, 0xff],
[102, 255, 51, 0xff],
[51, 255, 102, 0xff],
@acanalesg
acanalesg / points_in_polygons_or_near.py
Created November 21, 2013 20:18
points_in_polygons_or_near.py
import shapefile
import pandas as pd
from shapely.geometry import Polygon, Point
provinces = shapefile.Reader("/data/geobrowsing/spain_gis/SHP_WGS84_PROVINCIAS_SIMPLE/PROVINCIAS_SIMPLE_OK.shp")
provs = list()
for sr in provinces.shapeRecords():
provs.append(sr.record + [Polygon(sr.shape.points),] )
#print sr.record
@acanalesg
acanalesg / points_in_polygons2.py
Created November 21, 2013 17:42
Back to the problem of determining in which polygon from a set of polygons is a list of points (see points_in_polygons1.py). Now we use shapely ... it is amazingly faster than the other approach
import pandas as pd
from shapely.geometry import Polygon, Point
# Read polygons from shapefile
provinces = shapefile.Reader("/data/geobrowsing/spain_gis/SHP_WGS84_PROVINCIAS_SIMPLE/PROVINCIAS_SIMPLE_OK.shp")
# Store as shapely Polygons along with the data for each of them
provs = list()
for sr in provinces.shapeRecords():
provs.append(sr.record + [Polygon(sr.shape.points),] )
@acanalesg
acanalesg / points_in_polygons1.py
Last active December 29, 2015 00:09
Read a shapefile of polygons and a list of points, and return for each point the polygon that contains it. Attemp 1, works but takes almost 1/2 second to calculate each point. Next step: Find a library to do this :-)
import shapefile
import pandas as pd
# Point in polygon
def pip(point,poly):
x = point[0]
y = point[1]
n = len(poly)
inside = False