Skip to content

Instantly share code, notes, and snippets.

@adon-at-work
adon-at-work / package.json
Created May 7, 2018 18:57
adon-test package.json
{
"name": "adon-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@adon-at-work
adon-at-work / end-to-end-externs-protobuf.js.patch
Created June 16, 2016 06:26
Patch end-to-end/lib/protobufjs/externs/protobuf.js
From: adon <[email protected]>
Date: Thu, 16 Jun 2016 14:13:18 +0800
Subject: [PATCH] patch
---
./protobuf.js | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/protobuf.js b/protobuf.js
index b161ad1..7844c4b 100644
@adon-at-work
adon-at-work / rawTextCanonicalization.js
Last active October 16, 2015 07:43
rawText and styleTag Canonicalizations
/*
* The following works for all RAWTEXT tags except a minor usability issue on the obsolete <xmp> tag. Take <style> as example.
* Canonicalization Goal: the </style> immediately after styleContent cannot be put inside an unclosed HTML comment,
* otherwise, older browsers (e.g., IE7) won't be able to close the style tag as in HTML5 parsing
* There's no problem regardless of whether the original style block is already enclosed in comment <!-- -->
* If it does, either styleContent<!----> or <!--styleContent--><!----> is okay, the injected block just opens and closes itself
* If it opens without closing, i.e., <!--styleContent<!----> is okay too, we successfully ended the comment with the last -->
* <%%> is similar and is for IE in particular
*/
function rawTextCanonicalization(content) {
@adon-at-work
adon-at-work / checkout.js
Created March 28, 2015 12:03
paypal-checkout
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'AUHU3rEmdnduhJ2imK4XsVV3NaNpRqqAZrUzl3vgXeBMnriivdIIUJqVCwPI50ItM-V_dvBVmj0_quLG',
'client_secret': 'ED6TKYUbhOADfnBHW0HOQpvsJju0tY4zW0lJ3x1trJtt3SAaG-G-MGh93sraOtutJL-PX5bseqZ_NPrY'
});
app.get('/checkout/thankyou', function(req, res) {
// you need to apply some input checks
@adon-at-work
adon-at-work / express-error-handling-examples.js
Last active August 29, 2015 14:17
express-error-handling-examples.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('hello world! '
+ '<br/><a href="error">An example throwing error</a>'
+ '<br/><a href="error-handled">An example throwing error, but handled').end();
});
app.get('/error', function (req, res) {
@adon-at-work
adon-at-work / multer-to-s3.js
Last active April 3, 2023 18:10
Sample File Upload From Multer to S3
var AWS = require('aws-sdk'),
fs = require('fs');
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk
AWS.config.loadFromPath('./aws-config.json');
// assume you already have the S3 Bucket created, and it is called ierg4210-shopxx-photos
var photoBucket = new AWS.S3({params: {Bucket: 'ierg4210-shopxx-photos'}});
function uploadToS3(file, destFileName, callback) {
@adon-at-work
adon-at-work / app.js
Created March 12, 2015 16:11
IERG4210 Sample Code: Share the DB pool
var config = require('./shopXX-ierg4210.config.js'),
express = require('express'),
exphbs = require('express-handlebars'),
anyDB = require('any-db'),
frontEndRouter = require('./frontend.js');
var dbPool = anyDB.createPool(config.dbURI, {
min: 2, max: 20
});
@adon-at-work
adon-at-work / gist:4102e0c6da80af019393
Created February 27, 2015 16:12
Sample file on how to further upload files to S3
var AWS = require('aws-sdk'),
fs = require('fs');
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk
// AWS.config.loadFromPath('./aws-config.json');
// assume you already have the S3 Bucket created, and it is called ierg4210-shopxx-photos
var photoBucket = new AWS.S3({params: {Bucket: 'ierg4210-shopxx-photos'}});
// filepath equals the location of the uploaded file you got from multer