Skip to content

Instantly share code, notes, and snippets.

;;; 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.
// 現在実行中のスクリプトタグを取得
var currentScript = document.currentScript || (function() {
var nodeList = document.getElementsByTagName('script')
return nodeList.item(nodeList.length - 1)
}())
var text = currentScript.text // text で内部テキストが取得できる。
//=> "\n ここのテキストを取得したい\n "
@tyfkda
tyfkda / file0.js
Last active January 17, 2021 02:29
HTML5でキャンバスをピクセル単位で操作する: Please see https://tyfkda.github.io/blog/2014/12/26/canvas-pixel.html
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) {
@tyfkda
tyfkda / compare_nsstring.m
Last active August 29, 2015 14:14
Compare NSString
if ([stringA compare:stringB] == NSOrderedSame) {
}
@tyfkda
tyfkda / immutable_map.java
Last active August 29, 2015 14:14
Create immutable Map in Java
private static final Map<String, String> FOOBAR_MAP =
new ImmutableMap.Builder<String, String>()
.put("foo", "bar")
.build();
@tyfkda
tyfkda / convert-ns-to-c-string.m
Last active August 29, 2015 14:14
Convert NSString to C-string
const char *cstr = [nsstr UTF8String];
@tyfkda
tyfkda / define-class.js
Last active August 29, 2015 14:14
Class definition in JavaScript
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;
}
@tyfkda
tyfkda / storage.js
Last active August 29, 2015 14:14
HTML5 storage
(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.
@tyfkda
tyfkda / printf-order.c
Last active August 29, 2015 14:15
printfで引数の順番を指定して参照する ref: http://qiita.com/tyfkda/items/c5847f2139a77100f760
// %n$... でn番目の引数を参照する
printf("%2$d\n", 111, 222); // => 222
@tyfkda
tyfkda / is_leap.js
Last active August 29, 2015 14:15
JavaScriptでうるう年判定 ref: http://qiita.com/tyfkda/items/bd2e2e93d5875547f8cf
// 与えられた西暦がうるう年かどうかを返す
function isLeap(year) {
// うるう年の場合、"2月29日"は2月のはず
return new Date(year, 2 - 1, 29).getMonth() == 2 - 1;
}