Skip to content

Instantly share code, notes, and snippets.

Avatar
😐

Matt Keranen kmatt

😐
  • Central FL US
View GitHub Profile
@kmatt
kmatt / homebrew-gnubin.md
Created Nov 30, 2020 — forked from skyzyx/homebrew-gnubin.md
Using GNU command line tools in macOS instead of FreeBSD tools
View homebrew-gnubin.md

macOS is a Unix, and not built on Linux.

I think most of us realize that macOS isn't a Linux OS, but what that also means is that instead of shipping with the GNU flavor of command line tools, it ships with the FreeBSD flavor. As such, writing shell scripts which can work across both platforms can sometimes be challenging.

Homebrew

Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with "g" by default.

All commands have been installed with the prefix "g". If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc.

@kmatt
kmatt / rank.txt
Created Nov 12, 2020 — forked from alexey-milovidov/rank.txt
Example of emulation of rank function with arrayEnumerateUniq.
View rank.txt
milovidov@milovidov-xenial:~$ clickhouse-client
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
:-] ) ENGINE = Memory;
@kmatt
kmatt / vd.py
Created Nov 9, 2020
Visidata as a terminal Pandas dataframe viewer
View vd.py
import pandas as pd
import visidata as vd
df=pd.read_csv('file.csv')
vd.view_pandas(df)
@kmatt
kmatt / slugify.postgres.sql
Last active Oct 23, 2020 — forked from abn/slugify.postgres.sql
A slugify function for postgres
View slugify.postgres.sql
-- original source: https://medium.com/adhawk-engineering/using-postgresql-to-generate-slugs-5ec9dd759e88
-- https://www.postgresql.org/docs/9.6/unaccent.html
CREATE EXTENSION IF NOT EXISTS unaccent;
CREATE OR REPLACE FUNCTION public.slugify(v TEXT) RETURNS TEXT
LANGUAGE plpgsql
STRICT IMMUTABLE AS
$function$
BEGIN
@kmatt
kmatt / pg_flatten_json.sql
Created Sep 30, 2020 — forked from imamdigmi/pg_flatten_json.sql
Flattening json data in PostgreSQL
View pg_flatten_json.sql
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
@kmatt
kmatt / gist:af459f7cf3e43db1de63a87940432673
Created Jul 31, 2020
PostgreSQL JDBC: SSL client key format
View gist:af459f7cf3e43db1de63a87940432673
openssl pkcs8 -nocrypt -topk8 -inform PEM -outform DER -in client-key.pem -out client-key.pk8
@kmatt
kmatt / simplenamespace.py
Created Jul 28, 2020
Python JSON to SimpleNamespace Object
View simplenamespace.py
obj = json.loads(json.dumps(js), object_hook=lambda x: Namespace(**x))
js = vars(obj) # obj.__dict__
@kmatt
kmatt / what-is-my-ip-tcpdump
Last active Jun 17, 2020
What is my IP tcpdump
View what-is-my-ip-tcpdump
# Host
$ tcpdump -i ${iface} -nn port 5555
# Client
$ telnet ${hostip} 5555
View gist:c1d2d41075d6df1d5ab9e9c2d6b3280a
# https://github.com/docker/for-linux/issues/123#issuecomment-346546953
ip link add name docker0 type bridge
ip addr add dev docker0 172.17.0.1/16
@kmatt
kmatt / colors
Created Jun 14, 2020 — forked from bohoomil/colors
show Xresources colours
View colors
#!/bin/sh
colors=($(xrdb -query | sed -n 's/.*color\([0-9]\)/\1/p' | sort -nu | cut -f2))
echo -e "\e[1;37m
Black Red Green Yellow Blue Magenta Cyan White
───────────────────────────────────────────────────────────────────────────────────────\e[0m"
for i in {0..7}; do echo -en "\e[$((30+$i))m █ ${colors[i]} \e[0m"; done
echo
for i in {8..15}; do echo -en "\e[1;$((22+$i))m █ ${colors[i]} \e[0m"; done
You can’t perform that action at this time.