Skip to content

Instantly share code, notes, and snippets.

View tanjo's full-sized avatar
🌐
https://twitter.com/tanjoin

Yuuki Tanjo tanjo

🌐
https://twitter.com/tanjoin
View GitHub Profile
@tanjo
tanjo / UIStoryboard+Main.swift
Created February 7, 2020 09:17
Main.storyboard からインスタンス生成するための Extension
import UIKit
extension UIStoryboard {
static func mainInstantiate<T>(withViewController type: T.Type) -> T where T: UIViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let controller = storyboard.instantiateViewController(withIdentifier: type.storyboardIdentifier) as? T else {
fatalError("Could not instantiate view controller with type \(T.self)")
}
return controller
@tanjo
tanjo / sample.js
Last active November 1, 2019 10:10
rgb(0, 1, 2) から HEX に変換するスクリプト
["rgb(0, 1, 2)", "rgb(0, 1, 2)", "rgb(0, 1, 2)", "rgb(0, 1, 2)", "rgb(0, 1, 2)"]
.map((e) => "#" + e.style.borderTopColor
.replace(/rgb/g, '')
.replace(/\(/g,'')
.replace(/\)/g,'')
.replace(/ /g,'')
.split(',')
.map((e) => ("0" + parseInt(e).toString(16)).slice(-2))
.join(''))
.join(" ");
@tanjo
tanjo / main.js
Last active January 21, 2019 08:03
puppeteer で画像をダウンロード
const fs = require('fs').promises;
const puppeteer = require('puppeteer');
const headleass = true;
(async () => {
var browser = await puppeteer.launch({ headless: headleass, args: ['--lang=ja,en-US,en'] });
var page = await browser.newPage();
page.setViewport({ width: 1920, height: 1080 });
// 自分のツイッターのアイコン
var source = await page.goto('https://pbs.twimg.com/profile_images/450452672638763008/2wm_mrCJ.jpeg');
@tanjo
tanjo / gist:f3dde96c5d2610d3ca6cf1d4093e36f9
Last active September 28, 2018 09:08
ブラウザの座標を表示する
var div = document.createElement('div');
div.id = "tj-pos-view";
div.style.cssText = "position: fixed; right: 0; top: 0; background: black; color: white;"
document.body.appendChild(div);
document.body.addEventListener("mousemove", (e) => document.getElementById("tj-pos-view").innerText = "x: " + e.pageX + " y: " + e.pageY);
@tanjo
tanjo / tea.js
Created May 11, 2018 05:28
Botkit で使えるお茶リアクション
module.exports = function(controller) {
controller.hears(['茶', 'tea', 'おちゃ', 'りょくちゃ', '🍵', '旦', 'Tea'], ['ambient'], function(bot, message) {
bot.api.reactions.add({
timestamp: message.ts,
channel: message.channel,
name: 'tea'
});
});
};
@tanjo
tanjo / keydown.js
Created April 19, 2018 09:02
ショートカットの Command + ↓ が効かなかったときに試したコード
document.onkeydown = function(e) {
if((e.ctrlKey && !e.metaKey) || (!e.ctrlKey && e.metaKey)) {
if (e.keyCode === 40) {
window.scrollTo(0,document.body.scrollHeight);
}
}
console.log(JSON.stringify(e.keyCode));
}
@tanjo
tanjo / README.md
Created February 5, 2018 10:28
UIGestureRecognizerState の rawValue

UIGestureRecognizerState の rawValue について

一覧

  • possible 0
  • began 1
  • changed 2
  • ended 3
  • cancelled 4
  • failed 5
@tanjo
tanjo / Jsonable.swift
Created January 17, 2018 11:27
Jsonable のススメ
//
// Jsonable.swift
//
// MIT License
//
// Copyright (c) 2018 tanjo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@tanjo
tanjo / BaseApi.java
Created September 13, 2017 08:51
Retrofit 2 の interface を同一ファイルに書く
package in.tanjo.retrofit.api;
import retrofit2.Retrofit;
class BaseApi<T> {
T service;
public BaseApi(Class<T> tClass) {
this.service = RetrofitUtil.getInstance().create(tClass);
@tanjo
tanjo / README.md
Last active September 13, 2017 06:42
RxBus をシンプルに

RxBus をちょびっとシンプルに書く

ベースはここ

違うところ

趣味の領域だが、subscribe に以下の処理を入れたり、 filtero -> o instanceof SomeEventmapo -> (SomeEvent) o) を記載するとダサいのでスマートに書く