Skip to content

Instantly share code, notes, and snippets.

@aoi0308
aoi0308 / Sample_LINQ_GetElementById.cs
Last active December 11, 2015 20:09
xml.GetElementById("hoge") 相当のことを LINQ to XML でする。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
@aoi0308
aoi0308 / ezlibrarian.patch
Created December 5, 2012 08:00
ezLibrarianの修正パッチと日本語対応
diff -r -u redmine_ezlibrarian.origin//app/views/lib_mailer/lib_new.text.html.rhtml redmine_ezlibrarian/app/views/lib_mailer/lib_new.text.html.rhtml
--- redmine_ezlibrarian.origin//app/views/lib_mailer/lib_new.text.html.rhtml 2009-07-14 14:13:45.000000000 +0900
+++ redmine_ezlibrarian/app/views/lib_mailer/lib_new.text.html.rhtml 2011-08-26 09:20:51.281250000 +0900
@@ -34,7 +34,7 @@
<td style="width:35%"><%= @book.holder_change_histories_count > 1 ? "#{@book.holder_change_histories_count - 1} " : 0 %></td>
</tr>
<tr>
- <td style="width:15%"><b><%=l(:field_author)%>:</b></td>
+ <td style="width:15%"><b><%=l(:field_book_author)%>:</b></td>
<td style="width:35%"><%= @book.author %></td>
@aoi0308
aoi0308 / closure2.js
Created September 9, 2012 15:11
クロージャのサンプル その2
var plus5 = addfac(5);
console.log(plus5(10));
function addfac(n) {
return function(m) {
return n + m;
};
}
@aoi0308
aoi0308 / pipe.js
Created June 28, 2012 03:33
Nodeの裏でJavaのプログラムを起動して標準入出力をパイプするプログラム
var util = require('util')
,spawn = require('child_process').spawn
,java = spawn('java', ['Sample']);
process.stdin.resume();
java.stdin.on('close', function() {
process.exit(0);
});
util.pump(process.stdin, java.stdin);
@aoi0308
aoi0308 / node-debug.sh
Created June 13, 2012 12:27
Nodeデバッグ用シェルスクリプト
#!/bin/bash
#
# ./node-debug.sh app.js
#
function usage() {
echo "Usage $0 [-p port] [jsfile]"
exit 1
}
@aoi0308
aoi0308 / closure.js
Created May 1, 2012 04:15
クロージャの簡単なサンプル
/*
* 実行にはjQueryが必要。
* if文の中で関数外(forEachメソッドの引数は関数です)の変数 n を参照している。
*/
function doClick() {
var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
var n = $('#num').val();
arr.forEach(function(i) {
if (i % n == 0) {
@aoi0308
aoi0308 / accum.scala
Created April 10, 2012 02:12
アキュムレータ(クラス使用)
/**
* https://gist.github.com/2344525 の別バージョン
* 高階関数じゃなくてクラスを使用してみる。
*/
class Accum(private var n: Int) {
def apply(i: Int): Int = { n += i; n }
}
object Accum {
def apply(n: Int): Accum = new Accum(n)
@aoi0308
aoi0308 / accum.scala
Created April 9, 2012 16:21
アキュムレータ
/**
* ハッカーと画家のP.198に載ってるアキュムレータをScalaで実装。
* 元ネタは Common Lisp
* (defun foo (n)
* (lambda (i) (incf n i)))
*
* Int固定じゃなくてもっと汎用的にするにはどうするんだろ。
*/
def accum(n: Int): (Int => Int) = {
var m = n
@aoi0308
aoi0308 / scala_3_6.scala
Created March 24, 2012 16:25
コップ本第2版のP.76のプログラムを少しいじったもの
import scala.io.Source
def widthOfLength(s: String): Int = s.length.toString.length
if (args.length == 0) {
Console.err.println("Please enter filename")
sys.exit(-1)
}
val lines = Source.fromFile(args(0)).getLines().toList
@aoi0308
aoi0308 / payment.scala
Created March 16, 2012 02:22
所持金と支払価格から、お釣りが最小になる払い方を求める。
/**
* do execute.
* $ scala payment.scala {pocket} {price}
*/
object Main {
implicit val coins = List(1, 5, 10, 50, 100, 500, 1000, 5000, 10000)
def main(args: Array[String]): Unit = {
if (args.length != 2) sys.exit(-1)