Skip to content

Instantly share code, notes, and snippets.

View mkamakura's full-sized avatar

Masaya Kamakura mkamakura

  • self employed
  • Tokyo/Japan
  • 07:49 (UTC +09:00)
View GitHub Profile
function diff(arr1: number[], arr2: number[]) {
const uniqueArr1 = arr1.filter(a1 => !arr2.includes(a1))
const uniqueArr2 = arr2.filter(a2 => !arr1.includes(a2))
return [...uniqueArr1, ...uniqueArr2]
}
const test1 = [[1,4,3,7],[3,4,5]]
console.log(diff(test1[0], test1[1]))
const test2 = [[1,4,3,7],[3,4,5],[5]]
declare module '@emotion/styled' {
import styled, { CreateStyled } from '@emotion/styled'
import { ThemeType } from '@pulse/types'
export default styled as CreateStyled<ThemeType>
}
@mkamakura
mkamakura / encrypt-sample.js
Last active March 29, 2019 21:26
a sample to encrypt with AES-128-CBC on NodeJS
function encrypt(text, key, iv) {
let cipher = crypto.createCipheriv('aes-128-cbc', key, iv)
let encrypted = cipher.update(text)
encrypted = Buffer.concat([encrypted, cipher.final()])
return encrypted.toString('base64')
}
@mkamakura
mkamakura / needLogin.js
Last active November 8, 2018 10:06
redirect login page on nextjs
/* @flow */
import React, { Component } from 'react'
import Router from 'next/router'
import { checkLogin } from '../../redux/modules/auth'
type Props = {
location: string,
}
export default ({ location }: Props) => (ComposedComponent: any) => class needLogin extends Component<Object> {
@mkamakura
mkamakura / withError.js
Created November 4, 2018 14:41
withError on Nextjs
import React from 'react'
import ErrorPage from 'next/error'
export default Component => {
return class WithError extends React.Component {
static async getInitialProps(ctx) {
const props =
(Component.getInitialProps
? await Component.getInitialProps(ctx)
: null) || {}
const express = require('express')
export default function maintenance (app, options) {
let mode = false
let endpoint = false
let url = '/maintenance'
let accessKey
let view = 'maintenance.html'
let api = false
let status = 503
@mkamakura
mkamakura / HeadTitle.js
Last active October 17, 2018 21:39
Inject page title with Nextjs
/* @flow */
import React, { Component } from 'react'
import Head from 'next/head'
export default (title: string) => (ComposedComponent: any) => class HeadTitle extends Component<Object> {
render () {
return [
<Head key='head'><title>{title}</title></Head>,
<ComposedComponent key='composedComponent' {...this.props} />,
]
@mkamakura
mkamakura / Dockerfile
Created February 23, 2018 06:32
Local Node Environment (using Proxy)
FROM ubuntu:latest
#### Change to bash
RUN mv /bin/sh /bin/sh_tmp && ln -s /bin/bash /bin/sh
# Setup proxy
ENV http_proxy http://hoge.co.jp:10080
ENV https_proxy http://hoge.co.jp:10080
ENV no_proxy localhost
@mkamakura
mkamakura / Dockerfile
Last active March 2, 2018 12:15
Golang(API Server) Local Environment
FROM golang:1.9.4-alpine
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash git openssh curl coreutils
RUN go get github.com/golang/dep/cmd/dep
RUN go get github.com/codegangsta/gin
RUN mkdir -p /go/src/github.com/mkamakura/myProject/backend
@mkamakura
mkamakura / gif_generator.js
Created January 30, 2018 09:16
gif generator
const GifEncoder = require('gifencoder')
const pngFileStream = require('png-file-stream')
const fs = require('fs')
const chalk = require('chalk')
const config = require('./config')
const baseDir = 'e2e/screenshots/'
const dirs = fs.readdirSync(baseDir)
const promises = []
dirs.forEach(async (dir) => {