Skip to content

Instantly share code, notes, and snippets.

View gabrielbarros's full-sized avatar

Gabriel Barros gabrielbarros

  • Rio de Janeiro, Brasil
  • 13:20 (UTC -03:00)
View GitHub Profile
@gabrielbarros
gabrielbarros / python-vs-php-which-is-easier.md
Created August 6, 2025 00:09
Python vs. PHP - Which is easier?

Python vs. PHP - Which is easier?

Python date and time

# timestamp now
import time
now = int(time.time())
print(now)

# timestamp to date and time
@gabrielbarros
gabrielbarros / html-entities.txt
Last active June 18, 2025 00:44
Full named html entities
# https://html.spec.whatwg.org/multipage/named-characters.html
\t = 	 = 	
\n = 
 = 

! = ! = !
" = " = " = "
# = # = #
$ = $ = $
% = % = %
& = & = & = &
@gabrielbarros
gabrielbarros / nextdns-purge-denylist
Last active June 7, 2025 17:37
NextDNS purge denylist
#!/usr/bin/env bash
API_KEY=xxx # Get it from https://my.nextdns.io/account
PROFILE_ID=xxxxxx # Get it from https://my.nextdns.io
url=https://api.nextdns.io/profiles/$PROFILE_ID/denylist
curl -s -H "X-Api-Key: $API_KEY" $url | jq -r '.data[] | select(.active == true) | .id' | while read -r domain; do
echo "Deleting $domain..."
curl -X DELETE -H "X-Api-Key: $API_KEY" $url/$domain
@gabrielbarros
gabrielbarros / nextdns-export-denylist
Last active April 23, 2025 21:08
NextDNS export denylist
#!/usr/bin/env bash
API_KEY=xxx # Get it from https://my.nextdns.io/account
PROFILE_ID=xxxxxx # Get it from https://my.nextdns.io
url=https://api.nextdns.io/profiles/$PROFILE_ID/denylist
curl -s -H "X-Api-Key: $API_KEY" $url | jq -r '.data[] | select(.active == true) | .id'
@gabrielbarros
gabrielbarros / nextdns-import-denylist
Last active April 23, 2025 21:09
NextDNS import denylist
#!/usr/bin/env bash
API_KEY=xxx # Get it from https://my.nextdns.io/account
PROFILE_ID=xxxxxx # Get it from https://my.nextdns.io
url=https://api.nextdns.io/profiles/$PROFILE_ID/denylist
tac denylist.txt | while read -r domain; do
echo "Adding $domain..."
curl -d $"{\"id\": \"$domain\"}" \
@gabrielbarros
gabrielbarros / replace-date-time-mktime-with-datetime-class.php
Created March 19, 2024 20:48
Replace date, gmdate, time, mktime, gmmktime with DateTime class
<?php
// date
echo "date\n";
echo date('Y-m-d H:i:s'), "\n";
$dt = new DateTime();
echo $dt->format('Y-m-d H:i:s'), "\n\n";
// gmdate (UTC date)
echo "gmdate\n";
@gabrielbarros
gabrielbarros / list-bytes-and-codepoints.php
Last active March 11, 2024 17:06
List bytes and codepoints in PHP
<?php
/*
* Heart emoji: ❤️
* UTF-8 bytes: E2 9D A4 EF B8 8F
* Code points: U+2764 U+FE0F
*/
header('Content-Type: text/plain');
@gabrielbarros
gabrielbarros / latin1-utf8.php
Created March 8, 2024 14:10
Convert from ISO-8859-1 to UTF-8 and vice-versa; test if it's valid UTF-8
<?php
// ISO-8859-1 → UTF-8
function latin1ToUtf8(string $str): string
{
return iconv('ISO-8859-1', 'UTF-8', $str);
}
// UTF-8 → ISO-8859-1
function utf8ToLatin1(string $str): string
@gabrielbarros
gabrielbarros / unicode-and-byte-notation.md
Last active August 5, 2025 22:35
Unicode and byte notation in various places and programming languages

Unicode and byte notation

Letter: A
Code points: U+0041
UTF-8 bytes: 41
UTF-16BE bytes: 00 41

Pound sign: £
Code points: U+00A3
@gabrielbarros
gabrielbarros / counting-utf8-bytes-code-points-and-grapheme-clusters.md
Last active August 5, 2025 22:39
Counting UTF-8 bytes, code points and grapheme clusters in various programming languages

Counting UTF-8 bytes, code points and grapheme clusters

Strings to test:

• Star emoji
⭐

- UTF-8 bytes: 3
- code points: 1