気になった事柄や、書評されていた本をさっと検索できるようにしたものです。
Firefoxのみテスト済み
ブックマークレット←ドラッグアンドドロップで追加
コード
javascript:(function(){window.open('http://calil.jp/search?q='+encodeURI(document.getSelection()));})()
javascript:(function(){window.open('http://calil.jp/search?q='+encodeURI(document.getSelection()));})()
// ==UserScript==
// @name favoritetags
// @namespace jp.mamono.favoritetags
// @include http://b.hatena.ne.jp/entry/*
// ==/UserScript==
(function (){
var cloudStr = 'tag-cloud-size-';
var baseCloudsize = 9;
var overCloudsize = 11;
var maxTag = 3;
function Tag(tagElement) {
this.tag = tagElement;
this.getName = function() {
return this.tag.getElementsByTagName('a')[0].textContent;
}
this.getSize = function() {
return parseInt(this.tag.getElementsByTagName('span')[0].textContent.match(/\d+/));
}
this.getText = function() {
return this.getName() + this.tag.getElementsByTagName('span')[0].textContent;
}
}
function d() {
alert('test');
}
function addFavoriteTags(usertag) {
function onload(response) {
var result = new Array();
if (response.responseText != null) {
var tags = findTags(response.responseText).getElementsByTagName('li');
for (var i = 0; i < tags.length; i++) {
result.push(new Tag(tags[i]));
}
}
if (result.length == 0) return;
result.sort(function(o1, o2) { return o2.getSize() - o1.getSize(); });
var addTag = document.createElement('span');
addTag.setAttribute('style', 'font-size:80%');
for (var i = 0; i < result.length; i++) {
if (i >= maxTag) break;
addTag.textContent = addTag.textContent + result[i].getText();
}
usertag.parentNode.insertBefore(addTag, usertag.nextSibling);
}
GM_xmlhttpRequest({ method: "GET", url: 'http://b.hatena.ne.jp/' + usertag.text + '/', onload: onload });
}
function findTags(html) {
var result = new Array();
var sep = '\n';
var t = html.split(sep);
var addflag = false;
for (var i = 0; i < t.length; i++) {
if (t[i].match(/
How to Code などブロックをendで閉じるか}で閉じるかほどの意味しかないことを。
しかし、その差が気にならない人が良いプログラマーになるということもまずないのだけれども。
// ==UserScript==
// @name GR+?B
// @namespace http://d.hatena.ne.jp/nozom/
// @description show ?B button and count in Google Reader
// @include http://www.google.com/reader/view/*
// @include https://www.google.com/reader/view/*
// ==/UserScript==
// original author is id:kusigahama
// see http://d.hatena.ne.jp/kusigahama/20051207#p1
(function() {
const user = 'mamotena';
var timerID = null;
var busy = false;
var urlCache = new Object();
function getUrlCache(url) {
if (typeof urlCache[url] == 'undefined')
urlCache[url] = new Object();
return urlCache[url];
}
String.prototype.htmlescape = function() {
return this.replace(/&/g, "&").replace(/</g, "<");
}
function findNode(root, xpath) {
var result = document.evaluate(xpath, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (! result.snapshotLength) return null;
return result.snapshotItem(0);
}
function getBookmarkCountSpan(node) {
return findNode(node, 'span[@class="hatena-bookmark-count"]');
}
function insertChartSBM(targetNode, url) {
var a = document.createElement('a');
a.setAttribute('href', "http://amachang.art-code.org/chart/?" + url);
a.setAttribute('target', '_blank');
a.appendChild(document.createTextNode('C'));
with (targetNode) {
appendChild(document.createTextNode(" ("));
appendChild(a);
appendChild(document.createTextNode(") "));
}
}
function insertBookmarkCount(targetNode, url, count) {
var a = document.createElement('a');
a.setAttribute('href', "http://b.hatena.ne.jp/entry/" + url);
a.setAttribute('target', '_blank');
var str = (count > 0 ? "" + count : "no") + " user" + (count != 1 ? "s" : "");
a.appendChild(document.createTextNode(str));
with (a.style) {
fontSize = "0.9em";
textDecoration = "none";
if (count >= 5) {
fontWeight = "bold";
backgroundColor = "#fff0f0";
color = "#f66";
}
if (count >= 10) {
backgroundColor = "#ffcccc";
color = "red";
}
}
with (targetNode) {
appendChild(document.createTextNode(" ("));
appendChild(a);
appendChild(document.createTextNode(") "));
}
}
function createBookmarkCount(url, count) {
var node = document.createElement('span');
node.setAttribute('class', 'hatena-bookmark-count');
if (count > 0) {
insertBookmarkCount(node, url, count);
} else {
node.appendChild(document.createTextNode(' '));
}
insertChartSBM(node, url);
return node;
}
function setBookmarkCounts(infoArray) {
for (var i = 0; i < infoArray.length; i++) {
var entry = infoArray[i].entry;
var url = infoArray[i].url;
var title = infoArray[i].title;
var entryContainerTitle = infoArray[i].entryContainerTitle;
var collapsedTitle = infoArray[i].collapsedTitle;
var entryActions = infoArray[i].entryActions;
var count = getUrlCache(url).count;
if (typeof count != 'undefined') {
if (typeof collapsedTitle != 'undefined') {
var node = createBookmarkCount(url, count);
collapsedTitle.insertBefore(node, collapsedTitle.childNodes[1]);
}
if (typeof entryContainerTitle != 'undefined') {
var node = createBookmarkCount(url, count);
entryContainerTitle.insertBefore(node, entryContainerTitle.childNodes[1]);
}
}
}
}
function callXmlrpc(requestbody, infoArray) {
const endpoint = "http://b.hatena.ne.jp/xmlrpc";
function onload(response) {
if (response.responseText.match(/<fault>/)) {
// clearInterval(timerID);
//setInterval(timerID, 15000);
//alert("xmlrpc call failed: " + response.responseText + "\n" + "request: " + requestbody);
} else {
var pattern = /<name>([^<]+)<\/name>\s*<value><int>(\d+)/g;
var m;
while (m = pattern.exec(response.responseText)) {
getUrlCache(m[1]).count = m[2];
}
setBookmarkCounts(infoArray);
}
busy = false;
}
// alert('xmlrpc call :' + requestbody);
GM_xmlhttpRequest({ method: "POST", url: endpoint, data: requestbody, onload: onload });
}
function createAddBookmarkIcon(url, title) {
var a = document.createElement('a');
a.setAttribute('href', 'http://b.hatena.ne.jp/add?mode=confirm&is_bm=1&title=' + escape(title) + '&url=' + escape(url));
a.setAttribute('target', '_blank');
var img = document.createElement('img');
img.setAttribute('src', 'http://b.hatena.ne.jp/images/append.gif');
img.setAttribute('alt', 'add bookmark');
img.setAttribute('title', 'add bookmark');
with (img.style) {
borderWidth = '0px';
}
a.appendChild(img);
var node = document.createElement('span');
node.setAttribute('class', 'hatena-bookmark-icon');
node.appendChild(a);
return node;
}
function createBookmarkIcon() {
var img = document.createElement('img');
img.setAttribute('src', 'http://www.hatena.ne.jp/images/user_bookmark.gif');
img.setAttribute('alt', 'bookmarked');
img.setAttribute('title', 'bookmarked');
var node = document.createElement('span');
node.setAttribute('class', 'hatena-bookmark-icon');
node.appendChild(img);
return node;
}
function addBookmarkIcon(currentEntry) {
var entryContainerTitle = findNode(currentEntry, './/div[@class="entry-container"]//h2');
var entryActions = findNode(currentEntry, './/div[@class="entry-actions"]');
if ((entryContainerTitle == null) || (entryActions == null)) return;
var link = entryContainerTitle.firstChild;
var title = link.firstChild.textContent;
function onload(response) {
if (response.responseText != null) {
var responseXML = (new DOMParser()).parseFromString(response.responseText, "application/xml");
if (responseXML != null) {
var channel = responseXML.getElementsByTagName('channel')[0];
if (channel != null) {
var items = channel.getElementsByTagName('items')[0];
if (items != null) {
var lis = items.getElementsByTagName('li');
if (lis.length > 0) {
getUrlCache(link.href).bookmarked = true;
entryActions.appendChild(createBookmarkIcon());
} else {
getUrlCache(link.href).bookmarked = false;
entryActions.appendChild(createAddBookmarkIcon(link.href, title));
}
}
}
}
}
}
var bookmarked = getUrlCache(link.href).bookmarked;
if (typeof bookmarked == 'undefined') {
getUrlCache(link.href).bookmarked = 'loading';
var url = 'http://b.hatena.ne.jp/' + user + '/rss?url=' + escape(link.href);
GM_xmlhttpRequest({ method: "GET", url: url, onload: onload });
} else if (bookmarked == 'loading') {
// skipped
} else if (bookmarked) {
entryActions.appendChild(createBookmarkIcon());
} else {
entryActions.appendChild(createAddBookmarkIcon(link.href, title));
}
}
function timerHandler() {
if (busy) return;
var entries = document.getElementById('entries');
if (entries == null) return;
var currentEntry = document.getElementById('current-entry');
if (currentEntry != null) {
if (findNode(currentEntry, './/span[@class="hatena-bookmark-icon"]') == null) {
addBookmarkIcon(currentEntry);
}
}
busy = true;
var infoArray = new Array();
var reqUrlArray = new Array();
var reqUrlHash = new Object();
for (var i = 0; i < entries.childNodes.length; i++) {
var entry = entries.childNodes[i];
var collapsedTitle = findNode(entry, './/div[@class="collapsed"]//h2');
var entryContainerTitle = findNode(entry, './/div[@class="entry-container"]//h2');
var link = null;
var title = null;
if (entryContainerTitle != null) {
link = entryContainerTitle.firstChild;
title = link.firstChild.textContent;
} else if (collapsedTitle != null) {
link = collapsedTitle.parentNode.parentNode.firstChild;
title = collapsedTitle.textContent;
}
if (link != null) {
var info = { entry: entry, url: link.href, title: title };
if ((collapsedTitle != null) && (getBookmarkCountSpan(collapsedTitle) == null)) {
info.collapsedTitle = collapsedTitle;
}
if ((entryContainerTitle != null) && (getBookmarkCountSpan(entryContainerTitle) == null)) {
info.entryContainerTitle = entryContainerTitle;
}
if ((info.collapsedTitle != null) || (info.entryContainerTitle != null)) {
infoArray.push(info);
if ((getUrlCache(link.href).count == null) &&
(! reqUrlHash[link.href])) {
reqUrlHash[link.href] = true;
reqUrlArray.push(link.href);
}
}
}
}
if (infoArray.length == 0) {
busy = false;
return;
}
if (reqUrlArray.length == 0) {
// all items are found in the cache
setBookmarkCounts(infoArray);
busy = false;
} else {
// avoid xmlrpc call failure in 'too many params' error
reqUrlArray = reqUrlArray.splice(0, 50);
var request = '<?xml version="1.0"?>\n<methodCall>\n<methodName>bookmark.getCount</methodName>\n<params>\n';
for (var i = 0; i < reqUrlArray.length; i++) {
var url = reqUrlArray[i];
request += "<param><value><string>" + url.htmlescape() + "</string></value></param>\n";
}
request += "</params>\n</methodCall>\n";
callXmlrpc(request, infoArray);
}
}
// be careful not to be too busy
timerID = setInterval(timerHandler, 15000);
})();
// 47行目
a.setAttribute('href', "http://b.hatena.ne.jp/entry/" + escape(url));
id:kei-sさんのGoogle Readerでfaviconを表示させるGreasemonkeyスクリプト公開に触発されて、Google Readerにはてなブックマーク件数とブックマークアイコンを表示するGreasemonkeyスクリプトをバージョンアップした。
grb+-20061113.user.js
if (response.responseText.match(/<fault>/)) {
// この中をコメントアウト
// clearInterval(timerID);
//alert("xmlrpc call failed: " + response.responseText + "\n" + "request: " + requestbody);
} else {
マジックミラー越しにくつろぐ女性。それを食い入るように見つめて物色する男性。つぎつぎと“カップル”が成立しては、街に消えていく。「市場」とも「水族館」ともいえる異様な空間がそこにはあった。
カフェ開発やりたいけど、一般的なカフェは無線使い放題じゃないし、電源も借りられなーい!だからといってネットカフェじゃ居心地悪いし、気がつけば漫画を読んじゃう!そもそもお洒落な感じがいいのですー!ってプログラマのためにカフェをやるとしたらどうなるんだろう?
// Test.java
public class Test {
public static main(String[] args) {
PrivateVariable pv = new PrivateVariable();
// System.out.print(pv.himitu);
// ↑このコードはprivateの変数を呼び出してるのでコンパイルエラー
Field field = pv.getClass().getDeclaredField("himitu");
// ↑対象のオブジェクトからクラスをとってgetDeclaredField()を使ってprivate変数を取得しています。渡している文字列は変数名です。
field.setAccessible(true);
// ↑取得したFieldオブジェクトのアクセスチェックするしないの指定。
//trueを渡すとアクセスチェックが抑制され、private変数も呼び出せるようになる。
System.out.print(field.get(pv));
// ↑Fieldオブジェクトにprivate変数があるオブジェクトを渡して値を取得する。
}
}
// PrivateVariable.java
public class PrivateVariable {
private String himitu = "実は俺・・・";
}
>>> u'Hello!!'
u'Hello!!' #出力に小文字のuがついてたらUnicode
>>> u'Hello\u0020!!' #\uでユニコードをそのまま使える
u'Hello !!'
word = ur'Hellow\u0020!!\n world'
print word
Hellow !!\n world #ユニコードは変換されてるけど\nは変換されてない
str(u"あいう") #これはASCIIに変換できないのでエラーとなる
u"あいう".encode('utf-8') #utf-8形式に変換
"あいう".encode('utf-8') #デフォルトはASCII型なのでできないとエラーになる
unicode('hentai', 'utf-8') #Unicodeへ変換
list = ['hello','Hentai',4]
print list
['hello','Hentai',4]
print list[1]
Hentai
print list[1:]
['Hentai',4] #単一だと中身で複数だとちゃんとリストの切り出しなのがすごい
list = ['hello','hentai',200,4649]
list[1] = 'do' + list[1]
print list[1]
dohentai
list[:2] = [] #最初の二つの要素を除去
print list
[200,4649]
list[0:1] = ['hentai','hello'] #最初に挿入
print list
['hentai','hello',200,4649]
list[0] = ['hentai', 'hello'] #要素指定だとそれがリストに入れ替わる
print list
[['hentai', 'hello'],'hello',200,4649]
list[0:] = ['hentai','hello'] #0以降なので全部入れ替わる
print list
['hentai', 'hello']
list = ['hello','hentai',200,4649]
print len(list) #要素数の表示
4
word = 'hello'
print word 'hello' #これはダメ
print 'hello''hello' #これはいける
hellohello
word = 'hello'
print word[1:3] #2文字目から3文字目まで
el
word = 'hello'
print word[:4] #4文字目まで
hell
print word[2:] #3文字目から最後まで
llo
word = 'hello'
print word[100:] #何も出力されないがエラーも出ない
print word[-2:] #マイナスを入れると・・・
lo #最後の2文字が
print word[-2:4] #lohelloを期待したけど・・・何も出力されない
word = 'hello'
word[0] = 'x' #エラーとなる
word = 'x' + word #これなら代入なのでいける
print word
xhello
print word[1:] + 'world'
helloworld
word = 'hello'
print word[2:] + word[:2]
hello
word = 'hello'
len(word)
5
1)AdobeのDownLoad Manegaerが起動
2)ダウンロードが完了すると下記フォルダにファイルが展開される
C:\Users\hogehoge\AppData\LocalLow\NOS\Adobe_Downloads
展開されたファイルは
Setup.exe、setuo.ini、Data1.cab、AcroReader.msi、abcpy.ini
となりましたので
3)上記フォルダ内のファイルを全て別フォルダに退避。
4)セットアップを中断し、PCを再起動。
5)退避させたsetup.exeのプロパティ→互換性→「視覚テーマを無効にする」にチェック
6)setup.exeを起動しインストール
>>> width = 10 #エンター押しても表示されないが代入はされてる
>>> width #変数を入力すると値が表示
10
>>> print width #も同じ結果
10
>>> 7/2 #整数の演算は切り捨てだが
3
>>> 7.0/2 #7を7.0にして割ると
3.5
>>> 7.0/3 #無理数も
2.3333333333333335
>>> 3+3
6
>>> _
6
>>> print "10" #文字の10を印字
10
>>> _ #式のみなので最後の6が表示される
6
>>> "Hello" #直接印字
'Hello'
>>> _ #'Hello'が入っている
'Hello'
>>> hello = "こんにちは\
... はじめまして"
>>> print hello
こんにちははじめまして
>>> hello
'unicode...'
>>> r"test\n\
... tetest!!"
'test\\n\\\ntetest!!"
>>> print r"test\n\
... tetest!!"
test\n\
tetest!!
>>> t = """test
... te
... testtttt"""
>>> print t
test
te
testtttt
>>> t = "test"
>>> e = "exam"
>>> te = t + e #+は結合
>>> print te
testexam
>>> print te*10 #*で繰り返し
testexamtestexamtestexamtestexamtestexamtestexamtestexamtestexamtestexamtestexam
print "Hello world!!"
for num in range(1,10) :
print "Hello world!!", num;
IndentationError: expected anaindented block
for num in range(1,10) :
print "Hellow world!!", num;
実行結果:
Hello world!! 1
Hello world!! 2
Hello world!! 3
Hello world!! 4
Hello world!! 5
Hello world!! 6
Hello world!! 7
Hello world!! 8
Hello world!! 9
def : Collection(OCLType //コレクション内部の型) = expression //コレクションを返す式
OCL ocl = OCL.newInstance(ECoreEnviromnmentFactory.INSTANCE);
OCLHelper helper = ocl.createOCLHelper();
helper.defineAttribute("collection : Collection(Integer) = OrderedSet{1,2,3}"); //OrderedSet型で要素が1,2,3が作られCollection(Integer)型のcollectionという変数が定義される
//helper#define*で定義された属性や操作はこのhelperから作られたQueryでしか有効にならないので注意
// 上の続きでcollectionはInteger型が入ったコレクション
collection.oclIsTypeOf(OrderedSet(Integer)) // これはダメだった