Skip to content

Instantly share code, notes, and snippets.

View 1c7's full-sized avatar

ZhengCheng 1c7

View GitHub Profile
@1c7
1c7 / decodeAudioData Example.js
Created May 31, 2020 04:57
decodeAudioData Example
var init = function (url) {
var audioCtx, fail, request, source, success;
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
success = function (e) {
console.log("success", e);
};
fail = function (e) {
console.log("fail", e);
};
source = audioCtx.createBufferSource();
@1c7
1c7 / ruby_upload_to_aws_s3.rb
Created May 4, 2020 10:48
Ruby Upload File to AWS S3
require 'aws-sdk-s3' # v2 version use: require 'aws-sdk'
Aws.config.update({
credentials: Aws::Credentials.new('x', 'x')
})
s3 = Aws::S3::Resource.new(region: 'cn-north-1')
# Beijing: cn-north-1
# Ningxia: cn-northwest-1
file = './test_file_to_s3_bucket.txt'
@1c7
1c7 / generateAccountSASQueryParameters_demo.js
Created April 22, 2020 13:43
Azure generateAccountSASQueryParameters example (Node.js demo) (Node v12.11.0) (package.json "@azure/storage-blob": "12.1.1")
module.exports.azure_sas = function () {
var accountName = '<storage account name>'
var accountKey = '<account key like: xxxTAujFeBxdic/6a1SgEaoeByhqQeUpRdWaQ8Y7kRJ1rhwbXEoW8WAg036B4jkzTE9AYmtKnFu03dt6g1jJyA==>'
var sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey)
var last_day_of_this_year = new Date(new Date().getFullYear(), 11, 31)
var resource_types = new AccountSASResourceTypes()
resource_types.container = true
resource_types.object = true
@1c7
1c7 / buildspec.yml
Created February 17, 2020 07:30
AWS Codebuild buildspec.yml
version: 0.2
# Docker caching:
# https://github.com/aws/aws-codebuild-docker-images/issues/26#issuecomment-370177343
phases:
install:
runtime-versions:
docker: 18
pre_build:
@1c7
1c7 / read_blob_url_content.js
Last active January 28, 2020 03:18
Read blob URL content
// Read blob url like this one:
// blob:http://localhost:8080/611963a8-1e5a-4de3-9fa2-3fa39a82a2a2
// This blob url come from URL.createObjectURL(File);
function turn_blob_to_file(blob_url) {
var xhr = new XMLHttpRequest();
xhr.responseType = "blob";
xhr.onload = function() {
var blob = xhr.response;
@1c7
1c7 / docker-swarm-deploy.sh
Created February 14, 2019 13:25
Buddy ssh script
cd /var/www/
export TAG=${BUDDY_EXECUTION_REVISION_SHORT}
envsubst < docker-stack.yml > file.tmp
sudo docker stack deploy --with-registry-auth --compose-file file.tmp buddy-cd-app
@1c7
1c7 / git-command.sh
Created February 10, 2019 10:15
Gitlab remote to Github remote & vice versa
## to Gitlab
cd existing_repo
git remote rename origin old-origin
git remote add origin [email protected]:1c7/empty.git
git push -u origin --all
git push -u origin --tags
## Gitlab back to Github
cd existing_repo
git remote rm origin
@1c7
1c7 / .gitlab-ci.yml
Created February 2, 2019 08:44
.gitlab-ci.yml example
image: gitlab/dind
stages:
- build_and_publish_image
b_and_p:
stage: build_and_publish_image
script:
- docker login -u [username] -p [password] registry.gitlab.com
- docker build -t registry.gitlab.com/1c7/ccb .
@1c7
1c7 / job.rb
Created January 23, 2019 10:42
Slack webhook example curl->Ruby
class SlackIdVerifyJobJob < ApplicationJob
queue_as :default
def perform()
# curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/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
# Equivalent ruby code:
url = "https://hooks.slack.com/services/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"
options = {
body: {"text": "Hello, World!"}.to_json,
@1c7
1c7 / example.js
Last active January 8, 2019 05:18
微信小程序代码
Page({
data: {
offsetY: 0,
},
onShow(){
this.get_image_offset();
},
get_image_offset(){
if(this.data.offsetY == 0){
var that = this;