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 / force-delete-all-s3-buckets.sh
Created July 17, 2019 15:47
Force delete all S3 buckets
aws s3 ls | awk '{print $3}' | while read -r bucket; do aws s3 rb "s3://$bucket" --force ; done
@tianchu
tianchu / delete_snapshots.py
Created July 14, 2017 03:59 — forked from kjoconnor/delete_snapshots.py
boto script to delete snapshots matching a filter and older than X days
import sys
from boto.ec2 import connect_to_region
from datetime import datetime, timedelta
try:
days = int(sys.argv[1])
except IndexError:
days = 7
@tianchu
tianchu / tmux-cheatsheet.markdown
Created November 29, 2015 16:26 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@tianchu
tianchu / elasticsearch-basics.md
Last active August 29, 2015 14:21
Elasticsearch Basics

Elasticsearch Basics

Definition

Elasticsearch is an open-source search engine built on top of Apache Lucene™, a full-text search-engine library in Java.

JSON Document

Elasticsearch stores data as JSON documents, making it easy to be used together with MongoDB or CouchBase.

@tianchu
tianchu / AutoLayoutScrollView.swift
Last active August 29, 2015 14:17
ScrollView + AutoLayout using Swift and PureLayout
class MyViewController: UIViewController {
var scrollView = UIScrollView.newAutoLayoutView()
var contentView = UIView.newAutoLayoutView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
scrollView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
@tianchu
tianchu / AppDelegate.swift
Last active July 9, 2018 22:04
Create an Empty Tab-based iOS App in Swift programmatically
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
@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": {