Skip to content

Instantly share code, notes, and snippets.

@wanghq
wanghq / env.sh
Created February 11, 2021 19:57
Use Alibaba Cloud OSS as pulumi state backend
#!/bin/sh
pulumi login "s3://mybucket/pstate?endpoint=oss-cn-hangzhou.aliyuncs.com&disableSSL=true&&s3ForcePathStyle=false"
export AWS_ACCESS_KEY_ID=alicloud_ak
export AWS_SECRET_ACCESS_KEY=alicloud_sk
export ALICLOUD_ACCESS_KEY=alicloud_ak
export ALICLOUD_SECRET_KEY=alicloud_sk
@wanghq
wanghq / index.py
Created November 8, 2019 18:48
演示如何使用logger输出结构化的日志,并且保留RequestId
# -*- coding: utf-8 -*-
import json
import os
import logging
import re
# 演示如何使用logger输出结构化的日志,并且保留RequestId
# Sample output
# FunctionCompute python3 runtime inited.
# FC Invoke Start RequestId: a567f45b-cf83-4436-96a5-bafad61e1c28
@wanghq
wanghq / index.py
Last active April 17, 2019 05:48
Use sqlite in Function Compute
# -*- coding: utf-8 -*-
import logging
import os
import sqlite3
os.chdir('/tmp')
# code is copied from https://www.tutorialspoint.com/sqlite/sqlite_python.htm
conn = sqlite3.connect('test.db')
print "Opened database successfully";
conn.execute('''CREATE TABLE COMPANY
@wanghq
wanghq / dag.py
Created January 29, 2019 21:17
DAG demonstrating task dependencies
"""
Code that goes along with the Airflow tutorial located at:
https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/tutorial.py
"""
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
default_args = {
@wanghq
wanghq / DefaultFcClient
Created May 2, 2017 17:11
Client to call FC
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
<h1>Header</h1>
Thread ID: 70329309547740
Fiber ID: 70329342767160
Total: 0.004892
Sort by: self_time
%self total self wait child calls name
7.87 0.001 0.000 0.000 0.001 57 RubyLex#getc
5.05 0.001 0.000 0.000 0.001 5 RubyLex#identify_identifier
3.99 0.000 0.000 0.000 0.000 12 Hash#each
3.74 0.002 0.000 0.000 0.002 24 Proc#call
Thread ID: 70329309547740
Fiber ID: 70329342767160
Total: 0.341898
Sort by: self_time
%self total self wait child calls name
20.34 0.332 0.070 0.000 0.262 83 *Kernel#require
12.06 0.139 0.041 0.000 0.098 1632 MIME::Type#initialize
5.46 0.019 0.019 0.000 0.000 6528 Regexp#match
4.13 0.030 0.014 0.000 0.016 1632 <Class::MIME::Type>#simplified
@wanghq
wanghq / sign in popup
Created November 14, 2012 05:11
invitations/create.js.erb
<% if @invitaion.valid? %>
window.location.replace("<%= signin_url %>")
<% else %>
var modal = "<%= render(:partial => 'invitations/form', :locals => {:invitation => @invitation) %>";
$('#signin-modal').html($(modal));
<% end %>
@wanghq
wanghq / usernames-to-reserve
Created October 2, 2012 05:29
usernames to reserve
# compiled from http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
about
account
activate
add
admin
administrator
api
app
apps