Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 17, 2024 13:10
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@kristerkari
kristerkari / lazyeval.html
Last active February 6, 2020 04:00
Lazy evaluating Javascript code
<html>
<body>
<!-- ----------------------------------------------- -->
<!-- inline script block with commented code inside: -->
<!-- ----------------------------------------------- -->
<script id="myjscode">
/*
(function(h,v){function q(b){if(""===m)return b;
@prwhite
prwhite / Makefile
Last active October 2, 2024 03:13
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
@komamitsu
komamitsu / gist:c2a5c46a22d765df5aa2
Created February 11, 2015 08:01
Fibonacci number with "with recursive" in PostgreSQL
with recursive r(a, b) as (
select 0::int, 1::int
union all
select b, a + b from r where b < 1000
)
select a from r;
a
-----
0
@mbarkhau
mbarkhau / getarg.py
Last active April 1, 2022 14:24
mimimal arg parsing
import sys
def getarg(argname, args=sys.argv[1:]):
long_arg = '--' + argname
short_arg = '-' + argname[:1]
for idx, arg in enumerate(args):
if arg.startswith(long_arg):
if arg == long_arg:
# check for parameter
@peterjwest
peterjwest / git-cleanup.sh
Last active July 7, 2023 15:42
Git aliases
#!/usr/bin/env bash
set -euo pipefail
for BRANCH in $(git branch | grep -E -v "^(\* | (develop|master|main)$)"); do
if [[ -z $(git --no-pager log develop..$BRANCH --author=$(git config user.email)) ]]; then
git branch -D $BRANCH
fi
done
@mrliptontea
mrliptontea / sublime-text-3-windows-shortcuts.md
Last active November 5, 2024 13:15 — forked from TheShrike/gist:6111200
Sublime Text 3 - Useful Shortcuts (Windows)

Sublime Text 3 - Useful Shortcuts (Windows)

General

Shortcut Description
Ctrl+Shift+P command prompt
Ctrl+Alt+P switch project
Ctrl+P go to file
Ctrl+G go to line
@iconara
iconara / queries.sql
Last active November 13, 2023 22:26
Low level Redshift cheat sheet
-- Table information like sortkeys, unsorted percentage
-- see http://docs.aws.amazon.com/redshift/latest/dg/r_SVV_TABLE_INFO.html
SELECT * FROM svv_table_info;
-- Table sizes in GB
SELECT t.name, COUNT(tbl) / 1000.0 AS gb
FROM (
SELECT DISTINCT datname, id, name
FROM stv_tbl_perm
JOIN pg_database ON pg_database.oid = db_id
@mrtns
mrtns / README.md
Last active September 26, 2024 18:38
Markdown-based Literate Programming

R Ecosystem

  • R Markdown

    Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL.

Python Ecosystem

  • Pweave

    Pweave is a scientific report generator and a literate programming tool for Python. It can capture the results and plots from data analysis and works well with numpy, scipy and matplotlib.

  • podoc