Skip to content

Instantly share code, notes, and snippets.

View tianchu's full-sized avatar

Tian Chu tianchu

  • Datadog Inc.
  • New York
View GitHub Profile
@tianchu
tianchu / useful_regex.py
Last active August 29, 2015 14:13
Useful Python regular expressions
URL_REGEX = re.compile(r"^(http|https)://.+$")
IP_ADDRESS_V4_REGEX = re.compile(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"
r"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
US_ZIP_REGEX = re.compile(r"\d{5}(\-\d{4})?$")
UK_ZIP_REGEX = re.compile(r"^((GIR ?0AA)|((([A-PR-UWYZ][A-HK-Y]?[0-9][0-9]?)"
r"|(([A-PR-UWYZ][0-9][A-HJKSTUW])"
r"|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y]))) ?"
@tianchu
tianchu / django_auth.js
Last active June 1, 2023 21:44
How to authenticate Django users in node.js
/*
* Authenticate Django users in node.js.
*
* Django is great for many projects, while node.js does some fantastic
* jobs that Django couldn't. For example, you may have a Django app
* managing your user accounts and another real-time service or application
* running on Node, then you probably will need to read Django user session
* to authenticate users in the Node project.
*
* This gist is not production ready yet, but it demonstrates how could it
@tianchu
tianchu / remove_empty_fields.py
Last active October 13, 2021 01:24
Remove empty fields from a nested dict
def remove_empty_fields(data_):
"""
Recursively remove all empty fields from a nested
dict structure. Note, a non-empty field could turn
into an empty one after its children deleted.
E.g,
{
"location": {