This file contains 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
// C# の ?? 演算子と同様の用途・目的で、|?? というユーザー定義の記号演算子をあらかじめ定義しておく。 | |
// ただし null かどうかではなく、Option型の引数をとって Some(a) なら a を、 | |
// None であれば第2引数に指定された既定値を返す仕組み。 | |
let (|??) opt def = | |
match opt with | |
|Some(a) -> a | |
|None -> def | |
// LINQ の FirstOrDefault に近いのは、Seq.tryFind。 | |
// Seq.tryFind は、集合の中から predicate で該当するものがあれば Some(a)、 |
This file contains 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
module Bot | |
open System.Configuration | |
open Newtonsoft.Json | |
open Twitterizer | |
let Tweet() = | |
// Need appSettings section in .config: | |
// <add key="key" value="{ConsumerKey:'...', ConsumerSecret:'...', AccessToken:'...', AccessTokenSecret:'...'}" /> | |
let key = ConfigurationManager.AppSettings.["twitterKey"] | |
let tokens = JsonConvert.DeserializeObject<OAuthTokens>(key) |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>QUnit Test Suite</title> | |
<link href="Content/qunit.css" rel="stylesheet" /> | |
<script src="Scripts/qunit.js"></script> | |
<!-- Your project file goes here --> | |
<script src="Scripts/formatAsYen.js"></script> | |
<!-- Your tests file goes here --> | |
<script src="Scripts/formatAsYen.test.js"></script> |
This file contains 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 formatAsYen(num) { | |
///<param name="num" type="Number"></param> | |
return "\\" + num.toString(); | |
} |
This file contains 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
test("prepend Yen sign.", function () { | |
QUnit.equal(formatAsYen(123), "\\123"); | |
}); | |
test("insert comma at par 3characters.", function () { | |
QUnit.equal(formatAsYen(1234567), "\\1,234,567"); | |
}); |
This file contains 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
/// <reference path="qunit.js" /> | |
/// <reference path="formatAsYen.js" /> | |
test("prepend Yen sign.", function () { | |
QUnit.equal(formatAsYen(123), "\\123"); | |
}); | |
test("insert comma at par 3characters.", function () { | |
QUnit.equal(formatAsYen(1234567), "\\1,234,567"); | |
}); |
This file contains 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
<div id='qunit-fixture'> | |
<input type='checkbox' id='cb1' name='cb1' | |
data-toggle-target='#tb1' value='on'/> | |
<input type='text' id='tb1' name='tb1' value=''/> | |
</div> |
This file contains 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
/// <reference path="qunit.js" /> | |
/// <reference path="jquery-1.7.2.min.js" /> | |
/// <reference path="jquery.disabled-if-check-off.js" /> | |
test('initial state of text box is disabled.', function(){ | |
$('#cb1').disabledIfCheckOff(); | |
Qunit.equal($('#cb1').prop('checked'), false); | |
Qunit.equal($('#tb1').prop('disabled'), true); | |
}); |
This file contains 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
test('initial state of text box is disabled.', function(){ | |
$('#qunit-fixture').append( | |
"<input type='checkbox' id='cb1' name='cb1' "+ | |
" data-toggle-target='#tb1' value='on'/>"+ | |
"<input type='text' id='tb1' name='tb1' value=''/>"); | |
$('#cb1').disabledIfCheckOff(); | |
Qunit.equal($('#cb1').prop('checked'), false); | |
Qunit.equal($('#tb1').prop('disabled'), true); | |
}); |
This file contains 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 setupFixture(f) { | |
var lines = f.toString().split('\n'), html = [], i = 0; | |
do i++; while (!(lines[i-1].match(/\/\*[ \t\r]*$/))); | |
while (!(lines[i].match(/^[ \t\r]*\*\//))) html.push(lines[i++]); | |
$('#qunit-fixture').html(html.join('')); | |
} |