Skip to content

Instantly share code, notes, and snippets.

View hoangsetup's full-sized avatar
🎯
Work until you no longer have to represent yourself.!

Hoang Dinh hoangsetup

🎯
Work until you no longer have to represent yourself.!
View GitHub Profile
var fs = require('fs');
fs.writeFile('env.temp', `DATA_DIR=${process.env.DATA_DIR}`, function (err) {
if (err) {
return console.log(err);
}
console.log('The file was saved!');
});
@hoangsetup
hoangsetup / AWS_S3_File_Upload.js
Created February 11, 2018 13:18 — forked from homam/AWS_S3_File_Upload.js
How to upload files to AWS S3 with NodeJS SDK
var AWS = require('aws-sdk'),
fs = require('fs');
// For dev purposes only
AWS.config.update({ accessKeyId: '...', secretAccessKey: '...' });
// Read in the file, convert it to base64, store to S3
fs.readFile('del.txt', function (err, data) {
if (err) { throw err; }
exports.handler = function(event, context, callback) {
console.log('Received event:', JSON.stringify(event, null, 2));
// Retrieve request parameters from the Lambda function input:
var signature = event.headers['X-ChatWorkWebhookSignature'];
var body = event.body;
if (validate(signature, body)) {
// write operation for webhook
callback(null, {"statusCode": 200, "body": "Success"})
} else {
@hoangsetup
hoangsetup / Middleware.js
Created March 15, 2018 07:07 — forked from darrenscerri/Middleware.js
A very minimal Javascript (ES5 & ES6) Middleware Pattern Implementation
var Middleware = function() {};
Middleware.prototype.use = function(fn) {
var self = this;
this.go = (function(stack) {
return function(next) {
stack.call(self, function() {
fn.call(self, next.bind(self));
});
@hoangsetup
hoangsetup / iframe.html
Created June 7, 2018 07:34 — forked from cirocosta/iframe.html
Sending messages from child iframe to parent webpage
<!DOCTYPE html>
<html>
<head>
<title>My Iframe</title>
</head>
<body>
<button>Botão</button>
<script type="text/javascript">
@hoangsetup
hoangsetup / weather.gs
Created July 22, 2018 05:09
Google apps script weather app
function onOpen(){
var ui = SpreadsheetApp.getUi();
ui.createMenu("Weather Forecast")
.addItem("Update", "weatherForecast")
.addToUi();
}
function weatherForecast(){
var NOTATIONS = {
CITY: "B1",
@hoangsetup
hoangsetup / git-reset-author.sh
Created October 24, 2018 03:14 — forked from bgromov/git-reset-author.sh
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@hoangsetup
hoangsetup / class_decorator.ts
Created November 27, 2018 06:47 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@hoangsetup
hoangsetup / gist:152c18b89fe10e489cc9b5921215ab6d
Created January 10, 2019 14:36 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@hoangsetup
hoangsetup / destructuring.js
Created February 18, 2019 11:40 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];