Skip to content

Instantly share code, notes, and snippets.

View vip3r011's full-sized avatar
🏠
Working from home

vip3r011

🏠
Working from home
  • ZA
View GitHub Profile
#!/bin/sh
#in your php.ini set session.gc_probability = 0
#this disables php GC
# put this script via cron
# or in /etc/cron.hourly
/usr/bin/php -d session.save_path=/var/lib/php/session -d session.gc_probability=1 -d session.gc_divisor=1 -d session.gc_maxlifetime=3600 -r "session_start(); session_destroy();"
SELECT l.metric, l.nr AS bytes
, CASE WHEN is_size THEN pg_size_pretty(nr) END AS bytes_pretty
, CASE WHEN is_size THEN nr / NULLIF(x.ct, 0) END AS bytes_per_row
FROM (
SELECT min(tableoid) AS tbl -- = 'public.tbl'::regclass::oid
, count(*) AS ct
, sum(length(t::text)) AS txt_len -- length in characters
FROM public.TABLE-NAME-HERE t -- provide table name *once*
) x
CROSS JOIN LATERAL (
@vip3r011
vip3r011 / calc.js
Created August 26, 2022 13:55
3reel slot calc.
/* 3 reel slot, no wilds, no scatter*/
function occur(array){
const occurrences = array.reduce(function (acc, curr) {
return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc
}, {});
return occurrences;
}
const reels = [
@vip3r011
vip3r011 / prng.js
Created January 23, 2023 22:19 — forked from lpinca/prng.js
Pseudorandom number generator based on crypto.randomBytes
var crypto = require('crypto')
, rrange = 4294967296;
/**
* Return an integer, pseudo-random number in the range [0, 2^32).
*/
var nextInt = function() {
return crypto.randomBytes(4).readUInt32BE(0);
};
@vip3r011
vip3r011 / random.js
Created February 4, 2023 19:54
secure random in nodejs
'use strict';
const crypto = require('crypto');
class RNG {
// Define a static method for generating a random float value in the range of 0 to 1
static random() {
try {
// Use the crypto module's randomBytes method to generate 4 random bytes
const randomBytes = crypto.randomBytes(4);
@vip3r011
vip3r011 / redis.js
Created April 16, 2023 12:54
redis experimental module
'use strict';
const { createClient } = require('redis');
const options = {
host: '127.0.0.1',
port: 6379,
db: 0,
enable_offline_queue: false,
socket_keepalive: true,
@vip3r011
vip3r011 / geolocation.js
Last active March 24, 2025 23:20
geolocation
var GEOLOCATION_ALLOW = true;
(() => {
try {
//geolocate: enable - true, disable - false
//get this setting from db
const geolocate = localStorage.getItem('geolocate');
if (geolocate !== null) {
GEOLOCATION_ALLOW = Boolean(geolocate);
}

Using PGBouncer with CockroachDB


PGBouncer is a lightweight connection pooler for PostgreSQL. CockroachDB is a cloud-native SQL database for building global, scalable cloud services that survive disasters.

CockroachDB is PostgreSQL wire compatible database, which means it aims to have tight compatibility with the PG ecosystem. Today, we're going to wire PGBouncer to work with CockroachDB. This article is meant to scratch the surface of possibilities unblocked by PGBouncer with CockroachDB and not meant to be an in-depth overview. We're currently researching this topic and will follow up with official docs on proper architecture and sizing of PGBouncer and CockroachDB.


@vip3r011
vip3r011 / blockvsnonblockloop.js
Last active April 27, 2023 15:46
nodejs blockvsnonblock loop
//dont know if this is correct, but leme try, feedback appreciated
//blocking:
let run = true
let count = 0;
while(run){
++count;
let n = Math.random();
if(n <= 0.01){
run = false;
@vip3r011
vip3r011 / memo.js
Created April 28, 2023 15:11
Memo_cache using a Map
const cache = new Map();
///
function memo() {
let deleteAfterUse = true; // enable cache deletion after use by default
let maxKeys = 32;
const memoFunc = function (value=null) {
const size = cache.size;
if (value) {