Skip to content

Instantly share code, notes, and snippets.

View kk6's full-sized avatar
🐾
Playing with my cat.

kk6 kk6

🐾
Playing with my cat.
View GitHub Profile
@kk6
kk6 / gist:d14da41f041296dd55c18fb3da8db788
Last active June 17, 2021 02:49
jest で TypeScript のテストを書く場合の最低限度の設定など

jest で TypeScript のテストを書く場合の最低限度の設定など

Next.js のチュートリアルをTypeScript化まで完了したので、その先をということでチュートリアルで作ったものに対してユニットテストを書きたくなったので jest を導入した。最小構成だとこんな感じになると思う。

ちなみに今回の内容だと Next.js 特有の仕組みとかも使ってないし React も使ってないので、「jest で TypeScript のテストを書く」というタイトルにした。

(ReactやNextのコンポーネントをテストするなら React Testing Library を使うのが良さそう。これはまた次回。)

インストール

@kk6
kk6 / pyproject.toml
Created December 15, 2018 01:18
for poetry issue
[tool.poetry]
name = "kk6-demo"
version = "0.1.1"
description = ""
authors = ["kk6 <hiro.ashiya@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.7"
twine = "^1.12"
@kk6
kk6 / config.py
Created November 1, 2018 06:54
ptpythonの設定(~/.ptpython/config.py)
# Source: https://github.com/jonathanslenders/ptpython/blob/master/examples/ptpython_config/config.py
# Pygments CSS Themes: http://jwarby.github.io/jekyll-pygments-themes/languages/python.html
def configure(repl):
repl.vi_mode = True
repl.confirm_exit = False
repl.highlight_matching_parenthesis = True
repl.color_depth = "DEPTH_24_BIT"
repl.use_code_colorscheme("native")
@kk6
kk6 / mstdn.py
Last active July 31, 2017 23:28
Pythonでmastodon APIを叩くやつ
# -*- coding: utf-8 -*-
from urllib.parse import urlunsplit
import requests
from oauthlib.oauth2 import LegacyApplicationClient
from requests_oauthlib import OAuth2Session
def register_app(client_name, host, redirect_uris='urn:ietf:wg:oauth:2.0:oob',
scopes='read write follow'):
@kk6
kk6 / twitter_nav.css
Created January 27, 2017 06:32
twitterのタブを並び替えるユーザースタイルシート
.nav {
display: flex;
}
.home {
order: 1;
}
.moments {
order: 3;
}
.notifications {
@kk6
kk6 / update_venv.py
Last active March 28, 2017 15:27
Pythonのバージョン上げた後にvirtualenv更新するやつ(Python3.5以上で動作)
import os
import subprocess
IGNORE = ['i', 'dont','wanna','update', 'these']
VENVS_DIR = os.path.join(os.path.expanduser('~'), '.virtualenvs')
def get_venvs():
p = subprocess.run("source $(which virtualenvwrapper.sh) && lsvirtualenv -b",
shell=True, stdout=subprocess.PIPE)
@kk6
kk6 / sort_media_tweet.py
Last active December 8, 2016 18:48
メディアツイートをいいねやRT順に並べて表示
# -*- coding: utf-8 -*-
"""
メディアツイートをいいねやRT順に並べて表示
必要なファイルとか:
- twitterのConsumer Key, Consumer Secret
- 全ツイート履歴のCSV (twitter公式の「設定 > ユーザー情報」の一番下にある「全ツイート履歴」より)
インストールが必要なパッケージ:
- arrow
@kk6
kk6 / gist:521556a824ea43af54a4
Created March 11, 2016 08:40
twitterのプロフィールページで実行すると投稿画像グリッド表示してくれるやつ
javascript:var arr=document.location.href.split('/');var name=arr[arr.length-1];var url='https://twitter.com/search?f=images&vertical=default&q=from%3A'+name+'&src=typd';document.location.href=url;
@kk6
kk6 / .stylelintrc
Created October 26, 2015 14:57
http://mdo.github.io/code-guide/ を参考にしてみた
{
"rules": {
"block-closing-brace-newline-before": [2, "always"],
"block-opening-brace-space-before": [2, "always"],
"color-hex-case": [2, "lower"],
"color-hex-length": [2, "short"],
"color-no-invalid-hex": 2,
"declaration-colon-space-after": [2, "always"],
"declaration-colon-space-before": [2, "never"],
"declaration-no-important": 2,
@kk6
kk6 / auto_attr_init.py
Created October 3, 2013 11:48
http://melborne.github.io/2013/09/27/auto-attr-set-in-ruby/ をPythonでやるとこれでいいのかなっていう。passなりreturnなり書かないとダメなのがダサいしそもそもPython的にはこういうのはキモいよねっていう。
#-*- coding:utf-8 -*-
from functools import wraps
import inspect
def auto_attr_init(f):
@wraps(f)
def _auto_attr_init(*args, **kwargs):
arg_values = args[1:] + inspect.getargspec(f).defaults
for pair in zip(f.__code__.co_varnames[1:], arg_values):