Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
take it easy

soar_lin SoarLin

🐢
take it easy
View GitHub Profile
@SoarLin
SoarLin / lambda-get-ip.js
Created Sep 2, 2018
AWS Lambda Function to Get Internet IP
View lambda-get-ip.js
const http = require('http');
exports.handler = function(event, context, callback) {
const option = {
"hostname": "api.ipify.org",
"path": "/?format=JSON",
"method": "GET"
};
callback(null, Request(option).
@SoarLin
SoarLin / Makefile
Created Sep 2, 2018
aws-lambda-image_makefile
View Makefile
lambda:
npm install .
@echo "Factory package files..."
. . . . . . .
@echo "Create package archive..."
@cd build && zip -rq aws-lambda-image.zip .
@mv build/aws-lambda-image.zip ./
uploadlambda: lambda
@if [ -z "${LAMBDA_FUNCTION_NAME}" ]; then (echo "Please export LAMBDA_FUNCTION_NAME" && exit 1); fi
@SoarLin
SoarLin / firebase-messaging-sw.js
Created Jun 2, 2018
Firebase Messaging Service Worker JS
View firebase-messaging-sw.js
// [START initialize_firebase_in_sw]
// Import and configure the Firebase SDK
// These scripts are made available when the app is served or deployed on Firebase Hosting
// If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup
importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: '<YOUR_SENDER_ID>'
});
const messaging = firebase.messaging();
View vue-register-fcm.vue
<template>
<div>
...
<button @click="registeFCM">Register</button>
...
</div>
</template>
<script>
import 'firebase/messaging'
@SoarLin
SoarLin / vue_firebase_main.js
Created Jun 2, 2018
Vue Project use firebase cloud messaging
View vue_firebase_main.js
const FCMconfig = {
apiKey: 'YOUR_API_KEY',
authDomain: 'YOUR_DOMAIN',
databaseURL: 'https://<YOUR_PROJECT_ID>.firebaseio.com',
projectId: 'YOUR_PROJECT_ID',
storageBucket: '<YOUR_PROJECT_ID>.appspot.com',
messagingSenderId: 'YOUR_SENDER_ID'
}
firebase.initializeApp(FCMconfig)
@SoarLin
SoarLin / build_utils.js
Created Jun 2, 2018
Vue use global SASS resource
View build_utils.js
exports.cssLoaders = function (options) {
options = options || {}
const cssLoader = {...}
const postcssLoader = {...}
function generateLoaders (loader, loaderOptions) {...}
// =========
// SASS 配置
// =========
function resolveResouce(name) {
View Login.spec.js
import { shallow, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import VueI18n from 'vue-i18n'
import i18n from '@/i18n'
import router from '@/router'
// Component
import Login from '@/pages/Login'
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@SoarLin
SoarLin / decorator2.js
Created May 19, 2017
Decorator 實作範例 2
View decorator2.js
function Sale(price) {
this.price = price || 100;
this.decorators_list = [];
}
Sale.decorators = {};
Sale.decorators.fedtax = {
getPrice: function(price) {
return price + (price * 5/100);
}
@SoarLin
SoarLin / decorator1.js
Last active May 19, 2017
Decorator 實作範例 1
View decorator1.js
function Sale(price) {
this.price = price || 100;
}
Sale.prototype.getPrice = function() {
return this.price;
};
Sale.prototype.decorate = function (decorator) {
var F = function(){},
overrides = this.constructor.decorators[decorator],
i, newobj;