Skip to content

Instantly share code, notes, and snippets.

View emmiep's full-sized avatar

Emmie Päivärinta emmiep

View GitHub Profile
@emmiep
emmiep / rollup.config.js
Last active June 13, 2018 17:21
Bundle mixed JavaScript/TypeScript project with rollup
import typescript from 'rollup-plugin-typescript2';
export default {
input: 'src/index.js',
output: {
file: 'dist/app.js',
format: 'umd',
name: 'app',
sourcemap: true
},
@emmiep
emmiep / docker-compose.yml
Created June 19, 2018 11:59
Minimal golang docker
---
version: '3'
services:
go:
image: 'golang:1.10-alpine'
volumes:
- './:/go/src/github.com/emmiep/hello/:ro'
working_dir: '/go/src/github.com/emmiep/hello'
command: ['go', 'run', 'main.go']
@emmiep
emmiep / Dockerfile
Last active July 2, 2018 19:14
Docker multistage vue-cli + nginx
FROM node:9.11-alpine as build
WORKDIR /usr/app
COPY ./package.json ./yarn.lock ./
RUN yarn
COPY ./ ./
RUN yarn run build
FROM nginx:1.14-alpine
@emmiep
emmiep / nginx.conf
Last active July 3, 2018 12:18
Nginx basic SPA config
http {
server {
listen 80;
root /usr/share/nginx/html;
location / {
internal;
}
location ~ ^/(js/|img/|css/|favicon\.ico$) {
@emmiep
emmiep / nodemon.json
Created August 8, 2018 11:13
Nodemon for dart
{
"watch": [
"bin/",
"lib/"
],
"execMap": {
"dart": "dart"
},
"ext": "dart"
}
@emmiep
emmiep / noreturn.js
Created August 9, 2018 19:38
Good coding style?
function getUser(id) {
if (users.has(id)) {
return users.get(id);
}
}
@emmiep
emmiep / mode.js
Created August 12, 2018 13:27
Object rest spread with falsy value
view({showProfile}={}) {
const {name, id, profile} = this;
return {
name,
id,
...(showProfile && {profile})
};
}
@emmiep
emmiep / cache.js
Created August 24, 2018 13:40
Async caching with WeakMap and promises
export function createAsyncCache(fn) {
const cache = new WeakMap();
return {
get(key) {
if (cache.has(key)) {
return cache.get(key);
}
const promise = Promise.resolve(fn(key));
@emmiep
emmiep / whilewait.go
Last active March 16, 2019 14:59
Periodically do background task while waiting for result
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan string)
t := time.NewTicker(200 * time.Millisecond)
@emmiep
emmiep / randstring.go
Created April 6, 2019 18:56
Random strings in Go
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
"io"
)
func randomString(n int) (str string, err error) {