Skip to content

Instantly share code, notes, and snippets.

View agarman's full-sized avatar

Andrew Garman agarman

View GitHub Profile
@agarman
agarman / rand_rows.sql
Created July 7, 2022 17:10
MySQL SELECT RAND() rows FAST
SELECT
*
FROM {{db}}.{{nm}}
WHERE
rand() < 0.1
AND UPDATED_TIMESTAMP BETWEEN CURRENT_DATE() - 7 AND DATE_SUB(CURRENT_TIME(), INTERVAL 2 HOUR)
LIMIT 10;
LOAD A0 // byte
ns Registers
*2 L1 Cache (Kb) loads at min width / [A0 - A32]
*5 L2 Cache (Mb) " " / [A0 - A32]
*50 L3 Cache (Mbx10) " " / [A0 - A32]
@agarman
agarman / spring-annotations.101
Created June 2, 2022 13:23
Spring Annotations & Interfaces 101
Spring Annotations & Interfaces 101
@Configuration
- a singleton bean that is used to configure an application
- can be used as a component/bean itself
- can have 0 or more methods that register additional beans
- constructor can take parameters as long as these parameters can be resolved to already registered beans
@Component
- a singleton bean that provides functionality to application
package main
import (
"fmt"
)
func main() {
fmt.Printf("%#v\n", Identity('a'))
fmt.Printf("%#v\n", Identity(Box('a')))
fmt.Printf("%#v\n", Identity(Unbox(Box('a'))))
@agarman
agarman / bitbucket.ps1
Last active September 14, 2020 14:33
Lists all repos in project in bitbucket
#!/usr/bin/env pwsh -File
param(
[switch] [Parameter(ParameterSetName = "teams")] $teams,
[switch] [Parameter(ParameterSetName = "projects")] $projects,
[switch] [Parameter(ParameterSetName = "repos")] $repos,
[switch] [Parameter(ParameterSetName = "prs")] $prs,
# Parameters specified by switch command
[Parameter(Mandatory = $true, ParameterSetName = "projects")]
[Parameter(Mandatory = $true, ParameterSetName = "repos")]
#!/bin/bash
# Authentication variables
USER=${BITBUCKET_USER:-`cat .user`}
SECRET=${BITBUCET_SECRET:-`cat .secret`}
ORG=${BITBUCKET_ORG:-`cat .org`}
# Setup Initial URI
PAGELEN_QS="pagelen=${PAGELEN:-100}"
FIELDS_QS="fields=${FIELDS:-next,values.full_name,values.updated_on,values.language}"
@agarman
agarman / pg_stats.sql
Created August 16, 2019 17:33
Return useful arrangement of stats from PostgreSQL
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size,
live_tuples,
dead_tuples,
(case
when ((live_tuples + dead_tuples) > 0)
then 100.0 * ((1.0 * dead_tuples) / (live_tuples + dead_tuples))
@agarman
agarman / pg_df.sql
Created August 1, 2019 18:03
PostgreSQL df
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size,
live_tuples,
dead_tuples,
(case
when ((live_tuples + dead_tuples) > 0)
then 100.0 * ((1.0 * dead_tuples) / (live_tuples + dead_tuples))
@agarman
agarman / pg.sh
Created April 5, 2019 16:55
PostgreSQL + Docker Windows
docker volume create PostgreSQLData
docker run -p 5432:5432 --name <<cntr_name>> -e POSTGRES_PASSWORD=<<pwd>> -d -v PostgreSQLData:/var/lib/postgresql/data postgres
docker logs <<cntr_name>>
@agarman
agarman / .emacs
Last active October 21, 2018 16:24
Dumped spacemacs for my own .emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; https://gist.github.com/agarman/e0eed5ff2989f938ef2cf81be9b448bd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup packages
(package-initialize)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)