Skip to content

Instantly share code, notes, and snippets.

View dkapitan's full-sized avatar

Daniel Kapitan dkapitan

View GitHub Profile
@dkapitan
dkapitan / example_xml_path
Created August 14, 2014 15:17
Parse values into string using XML PATH
DECLARE @column_list nvarchar(2000) = (
SELECT
substring(
(
SELECT ', ' + column_name
FROM dbo.get_columns_types(@database, @schema, @table)
FOR XML PATH ('')
), 2, 2000)
)
@dkapitan
dkapitan / shapefiles.py
Last active March 2, 2021 05:20
Working with shapefiles in Python and SQL Server
"""
SQL Server supports Geometry datatypes for GIS analytics. GIS data is often stored in ESRI .shp format
The GDAL/ogr library provides ample tools to work with shapefiles, and export them in wkt for importing in SQL Server
See:
http://gdal.org/python/
http://en.wikipedia.org/wiki/Well-known_text
http://en.wikibooks.org/wiki/Geospatial_Data_in_SQL_Server#Import_Functions
"""
@dkapitan
dkapitan / gist:14fdc088a39d07b538ca
Created April 24, 2015 09:55
template T-SQL stored procedure export to .csv
-- let op: system accounts medinova\shannon_mssql en medinova\Shannon_SQLAgent moeten toegang hebben tot de directory waar naar toe wordt geschreven
declare @sql varchar(8000)
select @sql = 'bcp "select * from clinics01.dbo.DIM_DAG" queryout D:\etl\exports\valuecare\conversie\test.csv -c -t, -T -S' + @@servername
exec master..xp_cmdshell @sql
@dkapitan
dkapitan / regex_quotes
Created May 14, 2015 20:13
regex finding strings between quotes
import re
text = '"this is my string between quotes";column1;"bs";col2'
print(re.findall(r'"(.*?)"', text))
## --> ['this is my string between quotes', 'bs']
@dkapitan
dkapitan / another_OSX_setup_for_data_science.md
Last active October 4, 2015 13:53
OSX voor data science

Aim: A manageble and transparent OSX setup for all things data at NL Healthcare. This OSX configuration also aims to mimic the server environment (CentOS 7) as much as possible, for maximum portability of the data analytics stack.

Main stack:

  1. OSX (Yosemite at time of writing, El Capitan has just been released)
  2. Python 3.4 via conda package manager. Anaconda distribution by Continuum Analytics is our standard base-Python stack. jupyter notebook is our preferred analytics environment for interactive computing in various languages
  3. PostgreSQL 9.3, using MacPorts as the preferred package manager. In case an app is not available in MacPorts, we will use homebrew as a fall-back package manager
  4. Optional interactive computing languages: R, julia or any of the [supported languages](ht
-- use EXECUTE .. USING for dynamic SQL
-- NB: DbVis needs --/ and / around do-block
do $$
begin
execute 'drop table if exists tmp';
execute
'create temporary table tmp as
select * from vektis_agb.fagbx20_s01
where zorgverlenersnummer = $1'
using '000004';
@dkapitan
dkapitan / convert_camelcase.py
Created October 12, 2015 08:24
Python data munging
import re
first_cap_re = re.compile('(.)([A-Z][a-z]+)')
all_cap_re = re.compile('([a-z0-9])([A-Z])')
def convert(name):
s1 = first_cap_re.sub(r'\1_\2', name)
return all_cap_re.sub(r'\1_\2', s1).lower()
@dkapitan
dkapitan / blockchain.id
Created January 8, 2016 19:21
Onename.com
Verifying that +daniel_kapitan is my blockchain ID. https://onename.com/daniel_kapitan
@dkapitan
dkapitan / bsnproef.py
Created April 18, 2016 12:05
BSN 11-proef
def bsnproef(nummer):
"""
Checks validity of Dutch Social Security (BSN) based on '11-proef'
:param nummer: number to be checked, can be string or int
:return: True if passed BSN proef, False otherwise
"""
bsnfactoren = [9, 8, 7, 6, 5, 4, 3, 2, -1]
try:
check = sum([int(a)*b for a, b in zip(str(nummer), bsnfactoren)]) % 11
if check == 0:
@dkapitan
dkapitan / backup_dannas.sh
Created December 8, 2016 09:34
rsync backup script voor NAS
#!/bin/sh
rsync -avP --exclude '.@__thumb' -e ssh admin@dannas:/share/HiFi/ /Volumes/Seagate\ Backup\ Plus\ Drive/HiFi/
rsync -avP --exclude '.@__thumb' -e ssh admin@dannas:/share/Videos/ /Volumes/Seagate\ Backup\ Plus\ Drive/Videos/