Skip to content

Instantly share code, notes, and snippets.

View sonus's full-sized avatar
☸️
Focusing

Sonus Sundar sonus

☸️
Focusing
View GitHub Profile
Feature Before (String Array for 212 Permissions) After (Bitmask for 212+ Permissions)
Permission Representation An array of strings: ["USER_CREATE", "USER_READ", ...] A compact numerical value (or values): e.g., 9223372036854775807
Payload Content Thousands of characters for permissions array content Around 20-80 characters (for 1-4 integers) for numerical mask(s)
Approximate Encoded JWT Size ~4.5 KB (4500 bytes) ~0.33 KB - ~0.6 KB (330-600 bytes)
HTTP Header Compatibility Often exceeds common 4KB/8KB limits, causing errors Easily stays well under 1KB, no issues
Role Binary Octal Symbolic
Owner 111 7 rwx
Group 101 5 r-x
Others 101 5 r-x
@sonus
sonus / jwt-size.md
Created July 27, 2025 06:29
Calculating JWT Size
Component Estimated JSON Characters/Bytes Notes
JWT Header (JSON String) ~40 characters Example: {"alg":"HS256","typ":"JWT"}
Fixed Payload Claims (JSON String) ~200 characters iss, exp, iat, userid, email, plus the permissions array structure {"permissions":[]}
Average Permission String Length 10 characters E.g., USER_CREATE
Overhead per Permission in Array ~3 characters For quotes ("") and comma (,) in JSON, i.e., "PERMISSION",
Effective Length per Permission in JSON Payload 13 characters
@sonus
sonus / doa.php
Created April 17, 2024 09:16
Depend on Abstractions, not Concretions (Framework)
<?php
abstract class Player {
public abstract function play();
}
class Human extends Player {
public function play() {
echo "Human player makes a move.\n";
}
@sonus
sonus / IntToRoman.php
Created April 4, 2022 05:07
Int To Roman
<?php
class Solution {
private $romans = [
'M' => 1000,
'CM'=> 900,
'D'=>500,
'CD'=>400,
'C'=>100,
'XC'=>90,
'L'=>50,
@sonus
sonus / RomanToInt.php
Created April 4, 2022 04:38
Roman To Int in PHP
<?php
class Solution {
private $romans = [
'I' => 1,
'V' => 5,
'X' => 10,
'L' => 50,
'C' => 100,
'D' => 500,
'M' => 1000
@sonus
sonus / rasp.py
Created October 24, 2020 04:46
rasp
import RPi.GPIO as GPIO
import time
servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization
try:
@sonus
sonus / ww
Created June 24, 2020 10:49
Bbau
sdfsdsd
@sonus
sonus / varnishlog-examples.sh
Created November 25, 2019 11:03 — forked from cupracer/varnishlog-examples.sh
varnishlog examples (version 4.x)
# filter by request host header
varnishlog -q 'ReqHeader ~ "Host: example.com"'
# filter by request url
varnishlog -q 'ReqURL ~ "^/some/path/"'
# filter by client ip (behind reverse proxy)
varnishlog -q 'ReqHeader ~ "X-Real-IP: .*123.123.123.123"'
# filter by request host header and show request url and referrer header
@sonus
sonus / varnishlog-examples.sh
Created November 25, 2019 11:03 — forked from cupracer/varnishlog-examples.sh
varnishlog examples (version 4.x)
# filter by request host header
varnishlog -q 'ReqHeader ~ "Host: example.com"'
# filter by request url
varnishlog -q 'ReqURL ~ "^/some/path/"'
# filter by client ip (behind reverse proxy)
varnishlog -q 'ReqHeader ~ "X-Real-IP: .*123.123.123.123"'
# filter by request host header and show request url and referrer header