Skip to content

Instantly share code, notes, and snippets.

@franzwong
franzwong / index.js
Last active January 9, 2019 06:58
HowTo: Create AWS Lambda with Cloudformation
// For simplicity, error handling is not included
const axios = require('axios')
const AWS = require('aws-sdk');
const region = process.env['AwsRegion']
AWS.config.update({region});
const url = process.env['ExchangeRateURL']
const bucket = process.env['S3Bucket']
@franzwong
franzwong / nginx.conf
Created January 1, 2019 10:12
Dockerized nginx as reverse proxy
events {}
http {
upstream webapp {
server host.docker.internal:3000; # development only
}
server {
listen 80;
server_name localhost;
@franzwong
franzwong / quicksort.js
Created December 18, 2018 05:39
Quicksort with ramda
const R = require('ramda')
function quicksort(list) {
return R.ifElse(
R.pipe(R.length, R.gt(2)),
R.identity,
list => {
const [pivot, ...rest] = list
return R.pipe(
R.partition(R.gt(pivot)),
@franzwong
franzwong / index.js
Created December 8, 2018 06:21
Working with fluture and sanctuary
const F = require('fluture')
const {create, env} = require ('sanctuary');
const {env: flutureEnv} = require ('fluture-sanctuary-types');
const S = create ({checkTypes: true, env: env.concat (flutureEnv)});
const getName = id => new Promise(resolve => {
console.log(id)
setTimeout(() => resolve('Franz'), 3000)
})
@franzwong
franzwong / maybe.js
Created November 26, 2018 13:26
Js Maybe type
const VALUE = Symbol('Value');
class Container {
constructor(x) {
this[VALUE] = x
}
map(f) {
return f(this[VALUE]);
}
@franzwong
franzwong / head.js
Created November 26, 2018 13:25
Js unit test
function head(x) {
if (typeof x === 'string' && x.length > 0) {
return x.charAt(0)
} else if (Array.isArray(x) && x.length > 0) {
return x[0]
}
return null
}
module.exports = {
@franzwong
franzwong / index.html
Last active November 5, 2018 08:33
Layout
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="build/style.css">
</head>
<body>
<div class="container">
<header class="header">
</header>
<div class="body">
@franzwong
franzwong / aws-setup.md
Last active October 25, 2018 07:45
Setup aws env

Prerequisite

brew install jq

Setup

# Configuration
@franzwong
franzwong / proxy.md
Created July 9, 2018 06:16
Set proxy in mac

Turn on

networksetup -setwebproxy Wi-Fi my-proxy.com 8080
networksetup -setsecurewebproxy Wi-Fi my-proxy.com 8080

Turn off

@franzwong
franzwong / Sample.elm
Created July 8, 2018 05:34
Send HTTP request with Elm
module Sample exposing (..)
import Html exposing (Html, input, button, div, text, program)
import Html.Events exposing (onInput, onClick)
import Http exposing (post, jsonBody)
import Json.Encode as Encode exposing (..)
import Json.Decode as Decode exposing (Decoder, int, string)
import Json.Decode.Pipeline exposing (decode, required)
import Debug exposing (log)