This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 与えられた西暦がうるう年かどうかを返す | |
| function isLeap(year) { | |
| // うるう年の場合、"2月29日"は2月のはず | |
| return new Date(year, 2 - 1, 29).getMonth() == 2 - 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // %n$... でn番目の引数を参照する | |
| printf("%2$d\n", 111, 222); // => 222 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| // sessionStorage: Live until session end. | |
| // localStorage: Live forever. | |
| // Size limit: 5MB / domain. | |
| var storage = sessionStorage; // or localStorage; | |
| // Save: 値は文字列化される(toString())ので、数値などはいいが、オブジェクトはJSONなどでエンコードしておく必要がある | |
| storage.setItem('KEY', value); | |
| // Load. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function defineClass(props) { | |
| var parent = props.parent; | |
| var ctor = props.init || (parent ? function() { parent.apply(this, arguments); } | |
| : function() {}); | |
| if (parent) | |
| ctor.prototype = Object.create(parent.prototype); | |
| for (var key in props) | |
| ctor.prototype[key] = props[key]; | |
| return ctor; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const char *cstr = [nsstr UTF8String]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static final Map<String, String> FOOBAR_MAP = | |
| new ImmutableMap.Builder<String, String>() | |
| .put("foo", "bar") | |
| .build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ([stringA compare:stringB] == NSOrderedSame) { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var canvas = document.getElementById('mycanvas'); | |
| var context = canvas.getContext('2d'); | |
| // キャンバス全体のピクセル情報を取得 | |
| var imageData = context.getImageData(0, 0, canvas.width, canvas.height); | |
| var width = imageData.width, height = imageData.height; | |
| var pixels = imageData.data; // ピクセル配列:RGBA4要素で1ピクセル | |
| // ピクセル単位で操作できる | |
| for (var y = 0; y < height; ++y) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 現在実行中のスクリプトタグを取得 | |
| var currentScript = document.currentScript || (function() { | |
| var nodeList = document.getElementsByTagName('script') | |
| return nodeList.item(nodeList.length - 1) | |
| }()) | |
| var text = currentScript.text // text で内部テキストが取得できる。 | |
| //=> "\n ここのテキストを取得したい\n " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; Common Lisp backquote implementation, written in Common Lisp. | |
| ;;; Author: Guy L. Steele Jr. Date: 27 December 1985 | |
| ;;; Tested under Symbolics Common Lisp and Lucid Common Lisp. | |
| ;;; This software is in the public domain. | |
| ;;; $ is pseudo-backquote and % is pseudo-comma. This makes it | |
| ;;; possible to test this code without interfering with normal | |
| ;;; Common Lisp syntax. | |
| ;;; The following are unique tokens used during processing. |
NewerOlder