Skip to content

Instantly share code, notes, and snippets.

View kmatt's full-sized avatar
😐

Matt Keranen kmatt

😐
  • SE US
View GitHub Profile
@kmatt
kmatt / mssql_insert_json.py
Created January 17, 2023 02:37 — forked from gordthompson/mssql_insert_json.py
Alternative to_sql() *method* for mssql+pyodbc
# Alternative to_sql() *method* for mssql+pyodbc or mssql+pymssql
#
# adapted from https://pandas.pydata.org/docs/user_guide/io.html#io-sql-method
import json
import pandas as pd
import sqlalchemy as sa
def mssql_insert_json(table, conn, keys, data_iter):
@kmatt
kmatt / mssql_df_upsert.py
Created January 12, 2023 20:20 — forked from gordthompson/mssql_df_upsert.py
Build a T-SQL MERGE statement and upsert a DataFrame
# version 1.2 - 2022-11-01
import pandas as pd
import sqlalchemy as sa
def df_upsert(data_frame, table_name, engine, schema=None, match_columns=None):
"""
Perform an "upsert" on a SQL Server table from a DataFrame.
Constructs a T-SQL MERGE statement, uploads the DataFrame to a
@kmatt
kmatt / MacOSLogoutHook.txt
Last active November 23, 2022 19:19 — forked from RxDx/MacOSLogoutHook.txt
MacOS: Run script before shutdown
Create a file:
$ vim /Users/Shared/logoutHook.sh
File content:
#!/bin/bash
say 'Hasta la vista baby!'
Set execution permission:
$ sudo chmod +x /Users/Shared/logoutHook.sh
# brew install unixodbc
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/2.3.9_1/include"
export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/2.3.9_1/lib -liodbc -liodbcinst"
export PKG_CONFIG_PATH="/opt/homebrew/Cellar/unixodbc/2.3.9_1/lib/pkgconfig $PKG_CONFIG_PATH"
pip install --no-binary pyodbc pyodbc
@kmatt
kmatt / .zshrc
Created February 18, 2022 04:18 — forked from aiqc/.zshrc
zsh_prompt.txt
# ========= PROMPT =========
# Version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats ' %b '
# Render the prompt
setopt PROMPT_SUBST
" Maintainer: Lars Nielsen (dengmao@gmail.com)
" Last Change: January 22 2007
" https://dengmao.wordpress.com/2007/01/22/vim-color-scheme-wombat/
set background=dark
hi clear
if exists("syntax_on")
syntax reset
@kmatt
kmatt / Clickhouse-ranking.sql
Last active February 10, 2021 21:10 — forked from alexey-milovidov/rank.txt
Example of emulation of rank function with arrayEnumerateUniq.
/*
ClickHouse client version 1.1.53996.
Connecting to localhost:9000.
Connected to ClickHouse server version 1.1.53996.
*/
:) CREATE TABLE IF NOT EXISTS `employee` (
:-] `empid` Int32,
:-] `deptid` Int32,
:-] `salary` Int64
@kmatt
kmatt / LearnGoIn5mins.md
Created January 6, 2021 04:41 — forked from prologic/LearnGoIn5mins.md
Learn Go in ~5mins
@kmatt
kmatt / vd.py
Created November 9, 2020 18:31
Visidata as a terminal Pandas dataframe viewer
import pandas as pd
import visidata as vd
df=pd.read_csv('file.csv')
vd.view_pandas(df)
@kmatt
kmatt / pg_flatten_json.sql
Created September 30, 2020 01:29 — forked from imamdigmi/pg_flatten_json.sql
Flattening json data in PostgreSQL
create or replace function create_jsonb_flat_view
(table_name text, regular_columns text, json_column text)
returns text language plpgsql as $$
declare
cols text;
begin
execute format ($ex$
select string_agg(format('%2$s->>%%1$L "%%1$s"', key), ', ')
from (
select distinct key