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)
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 {
@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.
#
@revmischa
revmischa / pglisten.c
Last active February 23, 2023 19:52
Example postgresql asynchronous connection with LISTEN handler
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
// channel to LISTEN on
const char *listenChannel = "foo";
(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);
@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);
@jberkus
jberkus / xlog_numeric_location.sql
Last active February 20, 2016 20:30
Determine Most Caught-up Standby
-- For documentation on these functions, please see blog post at:
-- http://www.databasesoup.com/2012/10/determining-furthest-ahead-replica.html
-- determines current xlog location as a monotonically increasing numeric.
CREATE OR REPLACE FUNCTION xlog_location_numeric(vcloc text default NULL)
RETURNS numeric
LANGUAGE plpgsql
as $f$
DECLARE cloc text;
floc text[];
@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) = @_;