Skip to content

Instantly share code, notes, and snippets.

@ctsrc
ctsrc / README.md
Last active April 29, 2024 19:18 — forked from niw/README.en.md
Guide: Run FreeBSD 13.1-RELEASE for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc) with HVF acceleration (Hypervisor.framework)
@benkehoe
benkehoe / aws-profile-for-bashrc.sh
Last active April 2, 2024 10:41
AWS_PROFILE env var management
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
(function() {
const xhrProto = XMLHttpRequest.prototype,
origOpen = xhrProto.open,
origSend = xhrProto.send;
const typingUrlRegex = /https:\/\/discord.com\/api\/v6\/channels\/[0-9]+\/typing/;
xhrProto.open = function (method, url) {
this._url = url;
return origOpen.apply(this, arguments);
anonymous
anonymous / GAME_MASTER_v0_1.protobuf
Created July 16, 2016 16:31
Pokemon Go decoded GAME_MASTER protobuf file v0.1
Result: 1
Items {
TemplateId: "BADGE_BATTLE_ATTACK_WON"
Badge {
BadgeType: BADGE_BATTLE_ATTACK_WON
BadgeRanks: 4
Targets: "\nd\350\007"
}
}
Items {
# only supply or default logfile path when none is given explicitly in
# postgresql.conf
my @options = ($pg_ctl, 'start', '-D', $info{'pgdata'});
my $logsize = 0;
if ($info{'logfile'}) {
push @options, ('-l', $info{'logfile'});
# remember current size of the log
$logsize = (stat $info{'logfile'})[7] || 0; # ignore stat errors
}
@jberkus
jberkus / gist:43a74b63921aa58f90c8
Last active September 4, 2015 05:10
Simple stupid function to do python-style dict string replacement.
-- function for doing dictionary-style replacement of varaibles
-- in a SQL string. variables are marked in the text with ${var}
-- and replaced using a json dictionary
create or replace function replace_vars ( somestring text,
vars JSON )
returns text
language plpgsql
immutable
as
@jfrost
jfrost / gist:e36a4fdd2812b64c3ac9
Created November 5, 2014 21:12
pgbouncer simple benchmark results
So, I did a quick test with pgbouncer running on the local host and talking to a remote postgresql backend. I had the script open a connection, run a quick almost instantaneous query (SELECT now() ), collect the results and close the connection. It looped over this 50,000 times.
Connecting to the bouncer over local unix socket, it took 31s to perform all the queries.
Connecting to the bouncer over localhost, it took 45s to perform all the queries.
Connecting to the bouncer running on the remote server, it took 1m6s
Without using pgbouncer, it took 3m34s
WITH btree_index_atts AS (
SELECT nspname, relname, reltuples, relpages, indrelid, relam,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
FROM pg_index
JOIN pg_class ON pg_class.oid=pg_index.indexrelid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN pg_am ON pg_class.relam = pg_am.oid
WHERE pg_am.amname = 'btree'
),
@jfrost
jfrost / gist:6584871
Created September 16, 2013 18:53
PostgreSQL query: completely unused indexes
-- Completely unused indexes:
SELECT relid::regclass as table, indexrelid::regclass as index
, pg_size_pretty(pg_relation_size(indexrelid))
FROM pg_stat_user_indexes
JOIN pg_index
USING (indexrelid)
WHERE idx_scan = 0
AND indisunique IS FALSE order by pg_relation_size(indexrelid);
@revmischa
revmischa / ResultSet.pm
Last active December 19, 2015 17:38
DBIx::Class generic resultset method to take the current query and estimate a count of the rows returned. Use `->estimate_count` in place of `->count` to get a fast, approximate count of complex queries.
Add the following to your base ResultSet class:
# fast row estimation function for postgres
# similar to ->count, but may be much faster for Pg < 9.2
# uses query planner row count estimation, accuracy depends on when
# ANALYZE/autovacuum was last performed on the table
# more info: http://wiki.postgresql.org/wiki/Count_estimate
sub estimate_count {
my ($self) = @_;