Skip to content

Instantly share code, notes, and snippets.

View ryanhanwu's full-sized avatar
🎯
Focusing

Ryan Wu ryanhanwu

🎯
Focusing
View GitHub Profile
@ryanhanwu
ryanhanwu / test.js
Created October 31, 2019 16:22
how to load environment variable from dotenv with link break?
// MY_KEY=test\ntest2\ntest3
JSON.parse(`"${process.env.MY_KEY}"`)
/*
test
test2
test3
*/
@ryanhanwu
ryanhanwu / githistory.sh
Created October 1, 2019 13:48
Change git history names
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
@ryanhanwu
ryanhanwu / README.md
Last active June 17, 2019 14:28
Auto deployment script for CI with Git/Node.JS/Forever

Auto deployment script for CI with Git/Node.JS/Forever

Usage

1.Simply add the deploy.sh to your application folder

2.Start your service

deploy.sh start myApp.js
@ryanhanwu
ryanhanwu / dynamoScanPromise.js
Created April 26, 2017 17:15
A short snippet for scanning AWS DynamoDB table with AWS SDK and Promise
var params = {
TableName: 'MYTABLE',
FilterExpression: 'contains (myKey , :query)',
ExpressionAttributeValues: {
':query': query
}
}
var dynamoScan = new Promise(function(resolve, reject) {
var results = []
@ryanhanwu
ryanhanwu / inArray.asp
Created January 29, 2019 14:16
Asp InArray
<%
Function InArray(Needle, Haystack)
Dim i, x
InArray = False
For i = 0 To Ubound(Haystack)
If IsArray(Needle) = True Then
For x = 0 To Ubound(Needle)
If Trim(Haystack(i)) = Trim(Needle(x)) Then
InArray = True
@ryanhanwu
ryanhanwu / test.sh
Created January 8, 2019 18:03
AWS List size
aws s3api list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]"
/*
filepreview : A file preview generator for node.js
*/
var child_process = require('child_process');
var crypto = require('crypto');
var async = require('async');
var path = require('path');
@ryanhanwu
ryanhanwu / append.js
Created November 16, 2018 19:37
NodeJs Log
fs.appendFile('message.txt', 'data to append', function (err) {
if (err) throw err;
console.log('Saved!');
});
@ryanhanwu
ryanhanwu / parsekeyword.js
Last active October 25, 2018 13:50
Parse Double Quote #Search
module.exports= function parseKeywords(req, res, next){
const { q } = res.locals
//extract double quote terms
const re = /"(.*?)"/g
const phrases = []
let current
while ((current = re.exec(q))) {
phrases.push(current.pop())
}
//replace -_. with space for matches
@ryanhanwu
ryanhanwu / the-scratch.conf
Created May 4, 2018 14:10 — forked from korczis/the-scratch.conf
Nginx Node.js Proxy with caching, websockets, gzip
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=cache:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_the_scratch {
server 127.0.0.1:3000 weight=1 fail_timeout=60s;
}
# the nginx server instance
server {