Skip to content

Instantly share code, notes, and snippets.

View cho45's full-sized avatar

Satoh, Hiroh cho45

View GitHub Profile
#!ruby
require 'serialport'
@port = SerialPort.new(
"/dev/tty.usbserial-A402PY11",
38400,
8,
1,
0
function createElementFromString (str, opts) {
if (!opts) opts = { data: {} };
if (!opts.data) opts.data = { };
var t, cur = opts.parent || document.createDocumentFragment(), root, stack = [cur];
while (str.length) {
if (str.indexOf("<") == 0) {
if ((t = str.match(/^\s*<(\/?[^\s>\/]+)([^>]+?)?(\/)?>/))) {
var tag = t[1], attrs = t[2], isempty = !!t[3];
if (tag.indexOf("/") == -1) {
function log (m) {
var o = Array.prototype.concat.apply([], arguments);
location.href = "javascript:(function () { if (window.console) console.log.apply(console.log, "+o.toSource()+") })();";
}
// from http://www.joehewitt.com/blog/files/getElementsBySelector.js
// modified
function convertSelectorToXPath (rule, start) {
var regElement = /^([#.]?)([a-z0-9\\*_-]*)((\|)([a-z0-9\\*_-]*))?/i;
var regAttr1 = /^\[([^\]]*)\]/i;
var regAttr2 = /^\[\s*([^~=\s]+)\s*(~?=)\s*"([^"]+)"\s*\]/i;
var regPseudo = /^:([a-z_-])+/i;
var regCombinator = /^(\s*[>+\s])?/i;
var regComma = /^\s*,/i;
 気 私 |            ________
 持    |.      ,. - ´     ` - 、
 ち .あ |   ,.ノ                ヽ
 悪 あ | ∠,イ / i{ ハ! i ! l }.    、
 い い |   /イ { -从{ i} ! ハ}┼!┐   :ハ
 ん う  |   {ⅩレT:カVリN T:カ}!: :Ⅹ: : :.';
 で の |   ∠: : ! ゞ '    ゞイ!: : : : : :.N
 す    |     レi入"  r--、  "'レ!: : ;、/レ'
 よ    |.    //   >- ,.  -<  `'´
 ね.   |   { {   ,イ^{、 __ ,..イ:::>、
var DTMF = function () { this.init.apply(this, arguments) };
DTMF.prototype = {
table : {
"1" : [697, 1209], "2" : [697, 1336], "3" : [697, 1477], "A" : [697, 1633],
"4" : [770, 1209], "5" : [770, 1336], "6" : [770, 1477], "B" : [770, 1633],
"7" : [852, 1209], "8" : [852, 1336], "9" : [852, 1477], "C" : [852, 1633],
"*" : [941, 1209], "0" : [941, 1336], "#" : [941, 1477], "D" : [941, 1633]
},
init : function (context, opts) {
nnoremap epp a<C-R>=join(split(substitute(expand("%:p"), '.*lib/\\|.pm$', "", "g"), "/"), "::")<CR>
sub unindent ($) {
my ($str) = @_;
$str =~ /^\n*(\s+)/;
if ($1) {
my $indent = $1;
$str =~ s/$indent//g;
}
$str;
}
@cho45
cho45 / post.js
Created August 7, 2008 14:55
ダイアリの編集API適当にたたく
var url = "http://cho45.g.hatena.ne.jp/cho45/";
var s = {};
next(function getRkm () {
return xhttp.get(url).
next(function (r) {
s.rkm = r.responseText.replace(/^[\S\s]*Hatena\.rkm\s*=\s*(?:'([^']+)'|"([^"]+)")[\S\s]*$/, function (_, v1, v2) {
return v1 || v2;
});
});
@cho45
cho45 / hatena-multi.uc.js
Created August 15, 2008 15:20
はてなアカウント
/**
* Multi login for Hatena
* cho45 <cho45@lowreal.net>
* 2007-10-15
*
* License:
* Creative Commons by
* http://creativecommons.org/licenses/by/3.0/
*
* Using information in your password manager,