Skip to content

Instantly share code, notes, and snippets.

View kTmnh's full-sized avatar

Katsumasa Tamanaha kTmnh

View GitHub Profile
@kTmnh
kTmnh / ios6-timers.js
Last active April 27, 2022 21:24 — forked from ronkorving/ios6-timers.js
iOS6 webkit timer bug workaround
(function (window) {
// This library re-implements setTimeout, setInterval, clearTimeout, clearInterval for iOS6.
// iOS6 suffers from a bug that kills timers that are created while a page is scrolling.
// This library fixes that problem by recreating timers after scrolling finishes (with interval correction).
// This code is free to use by anyone (MIT, blabla).
// Original Author: [email protected]
var timeouts = {};
var intervals = {};
var orgSetTimeout = window.setTimeout;
var orgSetInterval = window.setInterval;
@kTmnh
kTmnh / javascript_techniques.js
Last active May 13, 2016 09:26
JavaScript techniques including bitwise operator replacement techniques, shortcuts, etc.
var PI = Math.PI;
//Faster replacement for Math object methods.
Math.round(PI) === PI + (PI < 0 ? -0.5 : +0.5) >> 0;
Math.ceil(PI) === PI + (PI < 0 ? -1 : 0) >> 0;
Math.floor(PI) === PI + (PI < 0 ? -1 : 0) >> 0;
//Conditional operator is faster than Math object methods.
Math.max(a, b) === (a > b) ? a : b;
Math.min(a, b) === (a < b) ? a : b;
@kTmnh
kTmnh / gist:4661261
Last active December 11, 2015 21:18
iOS 6 timer bug test sample. Apparently, Apple fixed the problem on iOS 6.1.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script>
window.onload = function() {
var element = document.getElementById("test");
var result = document.getElementById("result");
var count = 0;
@kTmnh
kTmnh / gist:5525045
Created May 6, 2013 13:15
drag and drop test
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#dropTarget {
width: 100%;
height: 200px;
border: 1px dashed #000000;