Skip to content

Instantly share code, notes, and snippets.

View paulo-raca's full-sized avatar

Paulo Costa paulo-raca

View GitHub Profile
@paulo-raca
paulo-raca / trace_parser.py
Last active February 14, 2020 02:17
Quick and dirty parser for Android traces
#!/usr/bin/env python3
"""
Parser for Android Traces.
Based on documentation from https://rhye.org/post/android-profiling-flamegraphs/
"""
from dataclasses import dataclass
from enum import Enum
@paulo-raca
paulo-raca / token_bucket.py
Last active November 8, 2019 22:05
TokenBucket in Python-Asyncio
import asyncio
import time
class Timer:
def now():
raise NotImplemented()
async def wait(time):
raise NotImplemented()
class WallTimer(Timer):
@paulo-raca
paulo-raca / Condition.kt
Last active November 29, 2024 17:27
Condition Variables for Kotlin Coroutines
package kotlinx.coroutines.sync
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.withTimeout
import java.util.function.Predicate
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.nanoseconds
@paulo-raca
paulo-raca / NetworkStateCallback.kt
Created July 30, 2021 12:08
Handy NetworkCallback implementation that merges the bunch of distinct callbacks in a single state
package com.crowdstrike.android.vpn.util
import android.net.ConnectivityManager
import android.net.LinkProperties
import android.net.Network
import android.net.NetworkCapabilities
import android.util.Log
/**
* NetworkCallback is quite inconvenient in that data is split between
@paulo-raca
paulo-raca / .gitconfig
Last active September 6, 2023 15:40
OS setup
[user]
email = Xxx Yzz
name = xxx
signingkey = /home/xxx/.ssh/id_rsa
[sendemail]
from = Xxx Yyy <xxx@gmail.com>
smtpuser = xxx@gmail.com
smtppass = xxx
smtpserver = smtp.googlemail.com
@paulo-raca
paulo-raca / README.md
Last active June 12, 2023 16:16
Support for `Forwarded`, `X-Forwarded` and `X-Real-IP` in Go ReverseProxy

This code ensures X-Forward (and friends) headers are updated correctly when using stacked proxies: the host, protocol and "for" should be inherited from the previous proxies.

Of course, there are 3 competing/similar ways to retrieve this information from the previous Proxy, so this tries to be compatible with them all:

  • Forwarded (new, nicer and standardized in rfc7239)
  • X-Forwarded-[For/Host/Proto], the legacy but de-facto standard
  • X-Real-IP, a less-common alternative to X-Forwarded-For[0].

Also, retrieving them from the incoming request requires caution: Malicious clients may try inject these headers, so these headers should only be used when we expect them.

@paulo-raca
paulo-raca / new_password.py
Created August 9, 2024 22:10
Generate secure random password
#!/usr/bin/env python3
import string
import secrets
n=16
charset = string.ascii_letters + string.digits + string.punctuation
print("".join([secrets.choice(charset) for i in range(n)]))