Skip to content

Instantly share code, notes, and snippets.

View beatak's full-sized avatar
🍄
Mushroom

Takashi M beatak

🍄
Mushroom
  • San Francisco, CA
View GitHub Profile
@beatak
beatak / admin.rs
Created February 2, 2024 23:29
snipers from pgcat (e1e4929d)
match query_parts[0].to_ascii_uppercase().as_str() {
"BAN" => {
trace!("BAN");
ban(stream, query_parts).await
}
"UNBAN" => {
trace!("UNBAN");
unban(stream, query_parts).await
}
"RELOAD" => {
#!/bin/sh
set -e
if [ -f /usr/local/bin/mo.sh ]; then
echo "mo.sh already installed"
else
apt-get update
apt-get install -yqq --no-install-recommends ca-certificates curl
curl -sSL https://raw.githubusercontent.com/tests-always-included/mo/master/mo -o mo.sh
chmod a+x mo.sh
@beatak
beatak / tmux-save-scrollback.sh
Created December 8, 2023 23:42
USAGE: tmux-save-scrollback.sh 2 200
#!/bin/bash
declare -r ES_BOLD=$(tput bold)
declare -r ES_NORM=$(tput sgr0)
declare -r DEFAULT_SCROLLBACK=9999
declare -r MIL_TIME_NOW=$(date +'%Y-%m-%d-%H-%M-%S')
declare -r TARGET_PANE=$1
declare -r SCROLLBACK_COUNT=$2
function main {
@beatak
beatak / wal_lsn_to_int.js
Last active September 27, 2023 00:07
Convert PostgreSQL's WAL_LSN to bytes (int, possibly 64-bit width?)
/**
* Logic is from:
* https://stackoverflow.com/questions/66797767/lsn-external-representation
* You may also look at:
* https://www.crunchydata.com/blog/postgres-wal-files-and-sequuence-numbers
*/
function lsn2int (str) {
return parseInt(
str.split('/').map((n) => n.padStart(8, '0')).join(''),
@beatak
beatak / regex-to-remove-ansi-escape-code.rb
Created September 21, 2022 00:18
you know, for all silly terminal apps spits color code even not tty
%r{
\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])
}
/**
* Runs funcs in serial, and returns each result
*
* @param {arr<Function(onFullFilled, onRejected)>} funcs - function to be executed
*/
Promise.execSerial = function (funcs) {
return new Promise(async function (res, rej) {
const result = [];
for (let i = 0, len = funcs.length; i < len; ++i) {
try {
{
"Amsterdam (AMS)": "amsterdam-nl",
"Copenhagen (CPH)": "cph-copenhagen-dk",
"Dublin (DUB)": "dub-dublin-ie",
"Frankfurt (FRA)": "frankfurt-de",
"Frankfurt": "hhn-frankfurt-de",
"Helsinki (HEL)": "hel-helsinki-fi",
"London (LCY)": "london_city-uk",
"London (LON)": "lon-london-uk",
"London": "london-uk",
<script>
import Controller from './game/Controller.svelte';
function handleGlobal (ev) {
console.log('handleGlobal on App!');
console.log(ev);
}
</script>
<h1>Hello!</h1>
amounts = [];
thetable = document.getElementsByTagName('tbody').item(0)
for (item of thetable.getElementsByTagName('tr')) {
const mytd = item.getElementsByTagName('td').item(3);
const mysize = parseFloat(mytd.textContent.split(' ')[0]);
amounts.push(mysize);
}
amounts.reduce((accum, cur) => { return accum + cur; }, 0)
'use strict';
const quickSort = function (items, left, right) {
let index;
if (left === undefined) {
left = 0;
}
if (right === undefined) {
right = items.length - 1;
}