Skip to content

Instantly share code, notes, and snippets.

View ypresto's full-sized avatar
🏠
Working from home

Yuya Tanaka ypresto

🏠
Working from home
View GitHub Profile
@ypresto
ypresto / settings-for-vscode-color.json
Last active September 9, 2019 16:21
Personally recommended color config for VSCode
{
"workbench.colorTheme": "One Dark Pro",
"workbench.colorCustomizations": {
"[One Dark Pro]": {
// Reduce brightness
"activityBar.background": "#1b1d23",
"badge.background": "#1b1d23",
"editor.background": "#1b1d23",
"sideBarSectionHeader.background": "#1b1d23",
"tab.activeBackground": "#1b1d23",
@ypresto
ypresto / backtrace_relative_path.rb
Last active May 30, 2019 06:29
Prepend specified path to backtrace in rspec output (for rails in subdirectory).
# NOTE: Put this file to spec/support/ .
# Prepend specified path to backtrace and Failure/Error section.
# Useful for multi module repository where rails is placed in the subdirectory.
# Intended for editors with click-to-open-file feature.
#
# For example
# # ./spec/models/your_model_spec.rb:12:in `your_method'
# to
# # ./rails/spec/models/your_model_spec.rb:12:in `your_method'
@ypresto
ypresto / safari-11-file-xhr-workaround.js
Last active May 11, 2018 09:21
[Does NOT work in Firefox] iOS 11.3 Safari / macOS Safari 11.1 empty <input type="file"> XHR bug workaround for rails-ujs / jquery_ujs
// iOS 11.3 Safari / macOS Safari 11.1 empty <input type="file"> XHR bug workaround.
// Replace empty File object with equivalent Blob in FormData, keeping its order, before sending it to server.
// Should work with IE10 and all other modern browsers.
// Because useragent value can be customized by WebView or etc., applying workaround code for all browsers.
// https://stackoverflow.com/questions/49614091/safari-11-1-ajax-xhr-form-submission-fails-when-inputtype-file-is-empty
// https://github.com/rails/rails/issues/32440
document.addEventListener('ajax:beforeSend', function(e) {
var formData = e.detail[1].data
if (!(formData instanceof window.FormData)) return
if (!formData.keys) return // unsupported browser
@ypresto
ypresto / safari-11-file-xhr-workaround-2.js
Last active September 6, 2018 13:47
iOS 11.3 Safari / macOS Safari 11.1 empty <input type="file"> XHR bug workaround for rails-ujs / jquery_ujs
// iOS 11.3 Safari / macOS Safari 11.1 empty <input type="file"> XHR bug workaround.
// This should work with every modern browser which supports ES5 (including IE9).
// https://stackoverflow.com/questions/49614091/safari-11-1-ajax-xhr-form-submission-fails-when-inputtype-file-is-empty
// https://github.com/rails/rails/issues/32440
document.addEventListener('ajax:before', function(e) {
var inputs = e.target.querySelectorAll('input[type="file"]:not([disabled])')
inputs.forEach(function(input) {
if (input.files.length > 0) return
input.setAttribute('data-safari-temp-disabled', 'true')
@ypresto
ypresto / keybase.md
Created September 25, 2017 10:03
keybase.md

Keybase proof

I hereby claim:

  • I am ypresto on github.
  • I am ypresto (https://keybase.io/ypresto) on keybase.
  • I have a public key ASBiAns4kqBa5eKu8wuHbtMxxMxV675BuMcbDtVlY93JBwo

To claim this, I am signing this object:

@ypresto
ypresto / init.lua
Last active March 1, 2018 14:22
英数キーとかかなキーとかを同時押しの時だけAltキーにするHammerspoonの設定
local pressedKeyTable = {}
-- TODO: Consider about consumed per keys is necessary or not.
local consumed = false
local keyCodeTable = {}
keyCodeTable[0x66] = true -- EISUU
keyCodeTable[0x68] = true -- KANA
eventtap = hs.eventtap.new({ hs.eventtap.event.types.keyDown, hs.eventtap.event.types.keyUp }, function(event)
local keyCode = event:getKeyCode()
if keyCodeTable[keyCode] == true then
@ypresto
ypresto / UriTypeHierarchyAdapter.java
Last active April 9, 2024 09:54
Gson adapter for Android's Uri class.
import android.net.Uri;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
@ypresto
ypresto / YPLayoutGuideHelper.m
Last active April 20, 2020 15:07
Apply automaticallyAdjustsScrollViewInsets in child view controller like Container View or UIPageViewController
//
// YPLayoutGuideHelper.m
//
// Created by Yuya Tanaka, 2015
//
// This is free and unencumbered software released into the public domain.
// Refer: http://unlicense.org/
//
// automaticallyAdjustsScrollViewInsets doesn't work for child view controllers
// hosted by something like Container View or UIPageViewController.
@ypresto
ypresto / LimitCacheSizeGlideModule.java
Last active April 27, 2019 16:51
Limit cache size of glide based on total size of Internal Storage implemented on the device.
package com.example.glide;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import com.bumptech.glide.Glide;
@ypresto
ypresto / brook-rxjs-bridge.js
Last active August 29, 2015 14:27
Translate brook promise and channel into RxJS.
Namespace('brook.rxjsbridge')
.use('brook promise')
.define(function(ns) {
'use strict';
var observableFromPromise = function(promise, value) {
return Rx.Observable.create(function(observer) {
var called = false;
var throwIfCalled = function() {
if (called) {
throw new Error('promise resolved twice.');