Skip to content

Instantly share code, notes, and snippets.

@ktrysmt
ktrysmt / benchmark_bytebuffer_test.go
Created May 19, 2016 09:10
結局Goの文字列結合はどれが一番早いのか
package main
import (
"bytes"
"fmt"
"testing"
)
var m = [...]string{
"AAAAAAAAA",
@ktrysmt
ktrysmt / convertNodeTreeToArray.js
Last active September 28, 2016 13:19
Convert from a DOM Node included childNodes nested to a nested array.
var convert = (a) => {
var r = []
if (a.firstChild === null) {
r.push(a)
}
else if (a.childNodes.length > 0) {
var c = a.childNodes
Array.from(c).forEach(function (v) {
if (v.firstChild === null) {
r.push(v)
@ktrysmt
ktrysmt / convertNodeToFlattenArray.js
Last active October 5, 2016 07:13
Flatten from a DOM Node included childNodes nested to a flat array.
var r = []
const flatten = (a) => {
if (a.firstChild === null) {
r.push(a)
}
else if (a.childNodes.length > 0) {
var c = a.childNodes
Array.from(c).forEach(function (v) {
if (v.firstChild === null) {
r.push(v)
@ktrysmt
ktrysmt / add-css-to-head.js
Created October 5, 2016 07:12
How to change dynamicly inline css via <head>
addCssToHead (css) {
var head = document.getElementsByTagName('head')[0]
var s = document.createElement('style')
s.setAttribute('type', 'text/css')
if (s.styleSheet) { // IE
s.styleSheet.cssText = css
} else { // the world
s.appendChild(document.createTextNode(css))
}
head.appendChild(s)
@ktrysmt
ktrysmt / es6-generator-sample.js
Created October 5, 2016 07:58
A simple snippet How to use es6 generator.
function* f() {
yield 9
yield 'home'
yield 'do not miss it!'
}
var bind = f()
console.log(bind.next(),bind.next(),bind.next(),bind.next())
@ktrysmt
ktrysmt / setImmediate.snipet.js
Last active October 10, 2016 02:26
Using setImmediate with DOM operations.
var child = document.getElementById("id").childNodes
var length=child.length,start=0;
var MAX_EXECUTION_COUNT=100;
setImmediate(function loop(){
for(var i=start;(i<start+MAX_EXECUTION_COUNT) && i<length ;i=(i+1)|0){
console.log(child[i])
}
if(i<length){
start += MAX_EXECUTION_COUNT;
setImmediate(loop,0);
@ktrysmt
ktrysmt / high-performance.for-loop.snipet.js
Last active October 9, 2016 15:03
Useful loop snipets in javascirpt.
var len = obj.length
for (var i= 0; i < len; i=(i+1)|0) {
console.log(obj[i])
}
@ktrysmt
ktrysmt / caret-animation.css
Created October 13, 2016 13:28
How to use css-animation as custom caret
input {
border-right: 1px solid transparent;
}
input:focus {
animation: PulseAttention 1.5s cubic-bezier(.215, .61, .355, 1) forwards infinite;
}
@keyframes PulseAttention {
50% {
border-color: red;
}
@ktrysmt
ktrysmt / async.js
Created October 24, 2016 15:05
A sample code of async/await by ES7
const panic = () => {
return new Promise((resolve) => {
throw new Error("throw.. ")
})
}
const sleep = () => {
return new Promise((resolve) => {
setTimeout(function() {
console.log("fin.")
@ktrysmt
ktrysmt / google-site-each-countries.json
Created December 16, 2016 11:35
List of google's urls each countries.
{
"matches": [
"*://www.google.com/*",
"*://www.google.ad/*",
"*://www.google.ae/*",
"*://www.google.com.af/*",
"*://www.google.com.ag/*",
"*://www.google.com.ai/*",
"*://www.google.am/*",
"*://www.google.co.ao/*",