Skip to content

Instantly share code, notes, and snippets.

@osamum
osamum / webServer.js
Last active July 10, 2016 15:02
Tiny Web server for development
/*Web コンテンツを開発するための Node.js 簡易 Web サーバー サンプル*/
//Web サーバーが Listen する IP アドレス
var LISTEN_IP = '127.0.0.1';
//Web サーバーが Listen する ポート
var LISTEN_PORT = 8086;
//ファイル名が指定されない場合に返す既定のファイル名
var DEFAULT_FILE = "default.html";
var http = require('http'),
@osamum
osamum / richText.html
Created May 30, 2016 07:32
Sample code of how to create rich text editor for monoe's blog's article.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" lang="ja" content="text/html;charset=utf-8"/>
<title></title>
<script>
//innerText をサポートしない Web ブラウザと共通で使用するための
//setText 関数を定義
function setAlter_innerText(element) {
if (element.innerText) {
@osamum
osamum / generator-yield_basic.html
Last active June 30, 2016 08:33
Sample of JavaScript's asynchronous processing (generator/yield) : de:code2016 - ARC-003
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="display"></div>
<button id="btnStart">次へ</button>
@osamum
osamum / promise.js
Last active August 21, 2017 05:42
Sample of JavaScript's asynchronous processing (promise) : de:code2016 - ARC-003
//※アロー関数を使用しています。(Internet Explorer では動作しません)
//()=>{} は function(){} と同じ意味です。
//Promise を使用した記述
//以下のように非同期処理をメソッドチェーンで記述できる
//new Promise(()=>{1回目の処理}).then(2回めの処理,エラー処理).then(3回めの処理)
p_setTimeout('A', 3000)
.then((arg)=>{
echo_arg(arg);
return p_setTimeout('B',2000);})
.then((arg)=>{
@osamum
osamum / aync_await.js
Last active August 21, 2017 06:31
Sample of JavaScript's asynchronous processing (async/await) : de:code2016 - ARC-003
//async/await は Promise の糖衣構文(Syntax-Sugar)です。
//Promise の処理をメソッドチェーンではなく、以下のように記述することができます。
(async ()=>{
echo_arg(await p_setTimeout('A',3000));
echo_arg(await p_setTimeout('B',2000));
echo_arg(await p_setTimeout('C',1000));
})();
function p_setTimeout(arg, delayLenght){
@osamum
osamum / callBack.js
Last active June 29, 2016 09:29
Sample of JavaScript's asynchronous processing (callBack) : de:code2016 - ARC-003
//非同期を制御するために一般的に使用されるコールバックパターン
setTimeout(function(){
echo_arg('A');
//前の処理のイベントハンドラ内に次に実行したい処理を記述する
setTimeout(function(){
echo_arg('B');
setTimeout(function(){
echo_arg('c');
},1000);
},2000);
@osamum
osamum / gamepad.html
Created May 31, 2016 04:54
Sample code of HTML5's Gamepad API
<!DOCTYPE html>
<html lang="ja" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>HTML5 Gamepad API Sample</title>
<script>
var displayDiv = null;
//ゲームパッドと操作の検出
@osamum
osamum / cssFilter.html
Last active May 31, 2016 07:18
Sample code of CSS3's API
<!DOCTYPE html>
<html lang="ja" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style>
option {
font-size: 20px;
}
select {
@osamum
osamum / nfc-detect_sample.html
Created June 2, 2016 07:10
Sample code of UWP's detect NFC device for hosted web app.
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>NFC Divice detect sample</title>
<script>
window.onload = function () {
var status = document.getElementById('status');
//Windows Runtime が検出されたら
if (typeof Windows !=='undefined') {
//非同期実行のためコードの順番ではなく、
//コンソールには C, B, A の順番で出力される
setTimeout('echo_arg("A")',3000);
setTimeout('echo_arg("B")',2000);
setTimeout('echo_arg("C")',1000);