JavaScript

JSでRSA

JSでRSA暗号が使えるやつ使ってみた http://cryptico.wwwtyro.net/鍵作る var pass = 'kazusuke'; var rsa_key = cryptico.generateRSAKey(pass, 1024); var pub_key = cryptico.publicKeyString(rsa_key); 'hello'を暗号化 var enc = cryptico.encrypt('hel…

jsonのparse

jsで JSON.stringify({host:"shokai.org", port:8080}) すると "{"host":"shokai.org","port":8080}" になる これをJavaで import org.json.JSONObject; JSONObject json = new JSONObject(data); json.getString("host"); json.getInt("port"); parseできる

Array.filter

はてブのタグみたいな記法をparseしたかった マツモティウスが教えてくれた "[aa][bbb][てすと]".split(/[\[\]]/) ["", "aa", "", "bbb", "", "てすと", ""]空文字列が入る filter使ったら消せた。 "[aa][bbb][てすと]".split(/[\[\]]/).filter(function(tag…

window.webkitNotifications

chromeで動くhttp://dev.shokai.org/test/webkit-notification/ $(function(){ $('input#notify').click(function(){ switch(window.webkitNotifications.checkPermission()){ case 1: window.webkitNotifications.requestPermission(); case 0: var notif =…

websocketを接続しなおす

websocketサーバーの方を修正した時にブラウザをリロードするのが面倒なので定期的にwebsocketのreadyStateを見てつなぎ直す var ws = null; var ws_connect_timer = setInterval(function(){ if(ws == null || ws.readyState != 1){ ws = new WebSocket("ws…

geolocation api

とりあえずchromeとiPhoneとAndroidでjsから位置とれたhttp://dev.shokai.org/js/geo/ $(function(){ log('start'); start(); }); var wid = null; function start(){ if(wid != null) return; wid = navigator.geolocation.watchPosition(function(e){ var …

v8インストール

chromeのjsエンジン brew install v8 v8 test.js chromeの開発パネルと同じようにエラーを表示してくれるので便利 test.js:5: TypeError: Object [object Object] has no method 'addspacea' print(g.addspacea("てすと")); ^ TypeError: Object [object Obj…

折りたたみメニュー2

デフォルトでたたんでおけるようにした section2を畳んでる function $(id){ return document.getElementById(id); } function hideSec(id){ var elm = $(id); switch(elm.style.display){ case "block": case "": elm.style.display = "none"; break; case …

折りたたみ

var hideCache = new Object(); function $(id){ return document.getElementById(id); } function hideSec(id){ var elm = $(id); if(hideCache[id] == undefined || hideCache[id] == null){ hideCache[id] = elm.innerHTML; elm.innerHTML = ""; } else{ …

Eclipseのプラグインでやってみる

これ参考に http://www.atmarkit.co.jp/fjava/javatips/035eclipse012.html Eclipse IDE for Java Developers http://www.eclipse.org/downloads/index.phpJavaScript Editor PlugIn for Eclipse http://sourceforge.net/projects/jseditorで、動かなかった…