Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / page-lifecycle.html
Created Apr 29, 2021
戻るとかでページを離脱する際の event を捕捉できるか、実験
View page-lifecycle.html
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<script type="text/javascript" src="https://unpkg.com/page-lifecycle@0.1.2/dist/lifecycle.es5.js"></script>
<script type="text/javascript">
lifecycle.addEventListener('statechange', (event) => {
console.log('statchange')
console.log(event)
@wtnabe
wtnabe / README.md
Created Mar 7, 2021
PostgreSQL 12のcollationの動作確認。columnかorder byにcollateを付与して利用する。アルファベットの大文字小文字の順番はcreate collateするしかなさそう。
View README.md

PostgreSQL 12 collation behavior verification

Procedure

  1. git clone
  2. mkdir pgdata
  3. docker-compose run -e POSTGRES_PASSWORD=password postgres
  4. docker-compose up
  5. psql -h localhost -U postgres -f ./create_database.sql
  6. psql -h localhost -U postgres -f ./create_table.sql collation_practice
@wtnabe
wtnabe / stimulus-and-mobx-counter.html
Last active Feb 25, 2021
Stimulus 2 and MobX 6 Counter example
View stimulus-and-mobx-counter.html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://cdn.jsdelivr.net/npm/stimulus@2.0.0/dist/stimulus.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mobx@6.1.7/dist/mobx.umd.development.js"></script>
<script>
mobx.configure({
enforceActions: "always"
})
View javascript-proxy-example.ts
export class FooModel extends Function {
private repos: any
/**
* @param {object} repos
* @return {Proxy}
*/
constructor (repos: any = createRepository('foo')) {
super()
this.repos = repos
View nestjs-console.ts
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
const repl = require('repl')
async function bootstrap () {
const app = await NestFactory.createApplicationContext(AppModule)
console.log('starting repl ...')
repl.start().context.app = app
}
View nestjs-console.ts
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
const repl = require('repl')
async function bootstrap () {
const app = await NestFactory.createApplicationContext(AppModule)
console.log('starting repl ...')
repl.start().context.app = app
}
View 20200625-github.user.css
.py-2 {
padding-top: 6px !important;
padding-bottom: 6px !important;
}
.BorderGrid--spacious .BorderGrid-cell {
padding-top: 16px;
padding-bottom: 16px;
}
View heroku-papertrail-router-path.awk
#! /usr/bin/awk -f
BEGIN {
FS = "\t"
print "\n"
}
$9 ~ /heroku\/router/ {
split($10, c, " ")
path = c[3]
@wtnabe
wtnabe / test-prepare-and-clean.rake
Last active Apr 30, 2020
test:prepare task を利用し、テスト開始前に必要なプロセスを foreman で起動しつつ rake 終了時に掃除する ( Thread が at_exit で自動的に kill されることを利用している )
View test-prepare-and-clean.rake
require 'childprocess'
if (!ENV['CI_ENV'] && ENV['CI_ENV'] != 'false')
namespace :test do
task :prepare do
puts 'foreman start -f Procfile.test'
Thread.new do
begin
ChildProcess.posix_spawn = true
puts "foreman starting ..."
@wtnabe
wtnabe / forceTimeout.js
Last active Apr 23, 2020
強制的にtimeout扱いで例外を上げるwrapper function
View forceTimeout.js
class ForceTimeout extends Error {
get name () { return 'ForceTimeout' }
}
async function forceTimeout (time, cb) {
const intervalId = setInterval(() => {
throw new ForceTimeout()
}, time)
try {