Skip to content

Instantly share code, notes, and snippets.

View TanAlex's full-sized avatar

Tingli Tan TanAlex

View GitHub Profile
@TanAlex
TanAlex / bash_aws_jq_cheatsheet.sh
Created July 31, 2019 20:12 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Create an S3 bucket and configure it for s3-website hosting
Create a record in a pre-existing Route53 HostedZone and point at the newly created bucket
Parameters:
HostedZoneID:
Description: The Hosted Zone ID in which to create the website DNS record
Type: AWS::Route53::HostedZone::Id
WebsiteAddress:
Description: >
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Launch a static website backed by an S3 bucket and served via https through cloudfront.
Assumes you have the following available already
* An address in mind (e.g. blog.example.com)
* An existing Route53 Hosted Zone for the domain
* A validated AWS ACM certificate arn for the desired web address which must be in eu-west-1
Parameters:
HostedZoneID:
Description: >
@TanAlex
TanAlex / get_url.yml
Created June 15, 2019 21:59
[ansible note]Ansible Notes #ansible
- name: Download files
get_url:
url: "{{item.url}}"
dest: "/var/www/html/{{item.dest}}"
with_items: [{"url": "https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz", "dest": "server1.tar.gz"},
{"url": "https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.1-bin.zip", "dest": "server2.zip"}]
@TanAlex
TanAlex / debounce.js
Last active June 9, 2019 04:54
[Javascript Utils]Javascript Utilities #utils
// Credit David Walsh (https://davidwalsh.name/javascript-debounce-function)
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
var called = false;
// This is the function that is actually executed when
@TanAlex
TanAlex / console_log.js
Created June 7, 2019 00:58
[js console.log tricks]console.log #console #tricks
console.log('%cAn error occured', 'background: red; color: white; padding: 4px; border-radius: 4px;font-weight: bold;')
console.log("%cStr1" + "%cStr2", "Css-for-str1", "Css-for-str2")
@TanAlex
TanAlex / beforeEach.js
Created June 7, 2019 00:35
[vue router snippet]vue router related #vue #vue_router
/*
* to.matched is array for all the route it matches, use m.meta to get flags
* remember to use next() at the end !
* next({name: 'new-route'}) to redirect
*/
router.beforeEach(async (to, from, next) => {
if (to.matched.some(m => m.meta.needProject)) {
const result = await apolloClient.query({
query: PROJECT_CURRENT,
@TanAlex
TanAlex / bus.js
Created June 7, 2019 00:18
[vue plugin sample]Create vm.$responsive to capture windows size #vue
//https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-ui/src/util/bus.js
import Vue from 'vue'
const bus = new Vue()
export default {
install (Vue) {
Vue.prototype.$bus = (type, ...args) => {
bus.$emit(type, ...args)
}
@TanAlex
TanAlex / chunked_request.go
Last active June 2, 2019 16:32
[chunked_request go client]chunked_request #http
package main
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"github.com/benburkert/http"
//"net/http"
@TanAlex
TanAlex / request_structures.py
Created May 31, 2019 06:21
[LookupDict, CaseInsensitiveDict]Different kinds of dictionaries like CaseInsensitiveDicts #dictionary
"""
requests.structures
~~~~~~~~~~~~~~~~~~~
Data structures that power Requests.
"""
from .compat import OrderedDict, Mapping, MutableMapping
class CaseInsensitiveDict(MutableMapping):