Skip to content

Instantly share code, notes, and snippets.

@nuno-andre
nuno-andre / tld_url_parse.py
Created Feb 22, 2021
Retrieve a URL's eTLD (effective top-level domain) and its operator from the Public Suffix List
View tld_url_parse.py
"""
Retrieve a URL's eTLD (effective top-level domain) and its operator
from the Public Suffix List
https://wiki.mozilla.org/Public_Suffix_List
"""
from functools import cached_property
from urllib.parse import urlparse
from typing import Optional
from io import StringIO
View code_workspace.py
#!/usr/bin/env python3
"""
.code-workspace generator
https://github.com/microsoft/vscode/issues/45177#issuecomment-528254048
"""
from pathlib import Path
import json
import os
# not project dirs, they only belong to the metarepo
@nuno-andre
nuno-andre / heidi_decode.py
Created Sep 29, 2019
Decode HeidiSQL hashed passwords
View heidi_decode.py
def heidi_decode(enc):
enc, shift = enc[:-1], int(enc[-1])
return ''.join(chr(int(enc[i:i+2], 16) - shift)
for i in range(0, len(enc), 2))
@nuno-andre
nuno-andre / export.ps1
Last active Jun 26, 2020
Import scoop applications
View export.ps1
# export applications
scoop export | sls '([A-Za-z0-9\-\_]+)' |% {
$_.matches.groups[1].value } > apps.txt
# export used buckets
$buckets = scoop export | sls '\[([A-Za-z0-9\-\_]+)\]' |% {
$_.matches.groups[1].value } | select -unique
<# or all installed buckets
$buckets = scoop bucket list
View extract_comments.py
"""
Extract block and inline comments, docstrings and
no-op'd string literals from Python code.
"""
from tokenize import tok_name, tokenize, TokenInfo
import itertools
import ast
TokenInfo.is_type = lambda t, tok_type: tok_name[t.type] == tok_type
View keybase.md

Keybase proof

I hereby claim:

  • I am nuno-andre on github.
  • I am nunoandre (https://keybase.io/nunoandre) on keybase.
  • I have a public key ASBIskuCwqylesTbmSO0LQw7_SEE34onVHbpQGoCMzV9uAo

To claim this, I am signing this object:

@nuno-andre
nuno-andre / Identifier.cs
Last active Nov 17, 2018 — forked from FabienDehopre/Identifier.cs
Validate C# identifier name
View Identifier.cs
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class IdentifierExtensions
{
// definition of a valid C# identifier: http://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx
private const string FORMATTING_CHARACTER = @"\p{Cf}";
private const string CONNECTING_CHARACTER = @"\p{Pc}";
private const string DECIMAL_DIGIT_CHARACTER = @"\p{Nd}";
@nuno-andre
nuno-andre / client.py
Created Nov 16, 2017
Sanic + MessagePack
View client.py
import requests
from json import dumps, loads
from msgpack import packb, unpackb
data = {'say': 'hello, world!'}
headers_msgpack = {'Content-Type': 'application/msgpack'}
headers_json = {'Content-Type': 'application/json'}
r = requests.post('http://localhost:8000/', data=packb(data), headers=headers_msgpack)
print(unpackb(r.content))