星期五, 6月 08, 2007

Tag Cloud

其實本來Blogger就有Tag排序的功能,只是沒有做成Tag Cloud的樣式。
所以我們只需要把原有的Tag List製做成Tag Cloud即可。
首先,先改CSS的設計部分:
/* Style for Label Cloud */
#labelCloud {
text-align: center;
}
#labelCloud .label-cloud li{
display: inline;
background-image: none !important;
padding: 0 5px;
margin: 0;
vertical-align: baseline !important;
border: 0 !important;
}
#labelCloud ul{
list-style-type: none;
margin: 0 auto;
padding: 0;
}
#labelCloud .label-count {
padding-left: 0.2em;
font-size: 9px;
color: #777;
}

接下來,加入製做Tag Cloud的js code
紅色部分是自訂的地方,諸如blog網址、大小字型、顏色…等。
<!-- User defined inline javascript -->
<script language='javascript' type='text/javascript'>
<!-- Functions used for Label Cloud: adjustLabel(), generateLabels()-->
var labels = new Object;
function adjustLabel(min, max, weight, total) {
  if (min &gt; max)
    var temp=(min-max)/Math.log(total), result=min-Math.floor(Math.log(weight)*temp);
  else
    var temp=(max-min)/Math.log(total), result=Math.floor(Math.log(weight)*temp+min);
  return result;
}  

function generateLabels(){
  var blogURL = 'http://abinlee.blogspot.com';
  var maxFontSize = 18;
  var minFontSize = 11;
  var maxColor = [204,204,204];
  var minColor = [119,119,119];
  var showCount = true;
 
  var labelColor= [];
  var labelSize = 0;
  var labelCount = new Array(); 
 
  for (var i in labels)
    if (!labelCount[labels[i]])
      labelCount[labels[i]] = new Array(labels[i])
 
  total = labelCount.length-1;
  section = document.getElementById('labelCloud');
  ul = document.createElement('ul');
  ul.className = 'label-cloud';
 
  for(var tag in labels) {
    for (var i=0; i &lt; 3; i++)
      labelColor[i]=adjustLabel(minColor[i], maxColor[i], labels[tag], total);
   
    labelSize = adjustLabel(minFontSize, maxFontSize, labels[tag], total);
    li = document.createElement('li');
    li.style.fontSize = labelSize+'px';

    a = document.createElement('a');
    a.title = labels[tag]+' articles with Label: '+tag;
    a.style.color = 'rgb('+labelColor[0]+','+labelColor[1]+','+labelColor[2]+')';
    a.href = blogURL+'/search/label/'+encodeURIComponent(tag);
   
    if (showCount) {
      span = document.createElement('span');
      span.innerHTML = '('+labels[tag]+') ';
      span.className = 'label-count';
      a.appendChild(document.createTextNode(tag));
      li.appendChild(a);
      li.appendChild(span);
    }
    else {
      a.appendChild(document.createTextNode(tag));
      li.appendChild(a);
    }
    ul.appendChild(li);
    ul.appendChild(document.createTextNode(' '));
  }
  section.appendChild(ul);   
}
</script>

最後把widget code展開,找到id='Label1'的widget,將這整個widget以下面的code取代掉。
<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'>  <!-- Add Label Cloud -->
  <b:if cond='data:title'>
    <h2><data:title/></h2>
  </b:if>
  <div class='widget-content'> 
  <div id='labelCloud'/>
    <script type='text/javascript'>
      <b:loop values='data:labels' var='label'>
        labels[&quot;<data:label.name/>&quot;] = <data:label.count/>;
      </b:loop>
      generateLabels();
    </script>
    <noscript>
      <ul>
      <b:loop values='data:labels' var='label'>
        <li>
          <b:if cond='data:blog.url == data:label.url'>
            <data:label.name/>
          <b:else/>
            <a expr:href='data:label.url'><data:label.name/></a>
          </b:if>
          (<data:label.count/>)
        </li>
      </b:loop>
      </ul>
    </noscript>
    <b:include name='quickedit'/>
  </div>
</b:includable>
</b:widget>   


ps. 因為這樣子做出的Tag Cloud是以Blogger給定的Tag list製做的,所以排序就是以Blogger的設定為主,以次數或是字母排序。當然,改成了Tag Cloud之後,還使用次數排序,就看不出效果啦~

Toggle/ Untoggle Your Blogger's Sidebar

參考自abintech的Blog hack系列
要做的工作就是:
  1. 把想展開摺疊的區塊找出來,
  2. 做一個按鈕或連結,當按下去的時候,去切換該區塊的狀態(display inline or none)。
打開完整範本原始碼,首先貼入處理這個動作的 Javascript (貼在head標籤內):

<script type='text/javascript'>
<!-- Function used for Sidebar Element Toggling: ElementToggle()-->
function ElementToggle(id) {
var element = document.getElementById(id).getElementsByTagName(&#39;div');
for(i = 0; i < element.length; i++) {
attribute = element[i].getAttribute('id');
if(attribute == 'toggle')
{
if (element[i].style.display == &#39;none')
element[i].style.display = &#39;inline';
else
element[i].style.display = &#39;none';
}
}
}
</script>


接下來,要去修改元件 (Widget) 的程式碼。同樣以個人資料 (Profile) 元件為例,找 <b:widget ...> 開頭 </b:widget> 結尾的區段,應該是類似下面這樣:

<b:widget id='Profile1' locked='false' title='AUTHOR PROFILE' type='Profile'>
<b:includable id='main'>
<b:if cond='data:title != ""'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>
............. (程式內文略過不表)
</b:includable>
</b:widget>


這個元件的 ID = Profile1,是範本裡用來識別該元件的方法,接下來要插入動態切換的連結,可以用圖片(此處我用[+/-]代替)


<b:widget id='Profile1' locked='false' title='AUTHOR PROFILE' type='Profile'>
<b:includable id='main'>
<b:if cond='data:title != ""'>
<h2><data:title/><a href='javascript:void(0); style='float:right;margin:-23px 0;' onclick='javascript:ElementToggle("Profile1");'>[+/-]</a></h2>
</b:if> <div class='widget-content' id='toggle' style='display:none;'
>
............. (程式內文略過不表)
</b:includable>
</b:widget>

搞定 !
---------From Moto http://moto.debian.org.tw/viewtopic.php?t=11377-----------
pulseaudio可以輸出到常用的alsa oss 驅動的裝置,esound server,遠端電腦(rtp),或甚至是windows 的waveout驅動.

可以接收來自
1.有支援pulseaudio的程式(xine,bmpx,audacious等等)
2.透過alsa-lib的plugin讓所有支援alsa的程式使用pulseaudio
3.支援esd的程式..pulseaudio可以完全取代esd
4.OSS模擬 (像是aoss一樣,可以給java發出聲音)
其他其他...
大概分享一下我在我電腦上使用pulseaudio的安裝方法
apt-get install pulseaudio pulseaudio-module-x11 paman pavucontrol pulseaudio-esound-compat pulseaudio-utils
module-x11 讓x11發出的警告beep聲音透過pulseaudio發出,像是..命令列已經沒有東西了又按backspace就會逼..vi裡面亂按也會..
paman pulseaudio manager可以讓你看目前server的狀態,所有的input/output
pavucontrol 音量控制,這個一定要裝,可以控制個別程式的音量

修改 /etc/pulse/default.pa
輸出輸入
### Load audio drivers statically
load-module module-alsa-sink device=dmix
load-module module-alsa-source device=plughw:1,0
輸出到alsa的dmix裝置,
從硬體1,0來錄音,你也可以設定成dsnoop

其實,修改到這樣子就可以用了...
不過我還加了esd的功能..
load-module module-esound-protocol-tcp auth-ip-acl=10.11.12.13;192.168.50.0/24;127.0.0.0/8
load-module module-esound-protocol-unix
讓那些ip可以透過tcp把聲音送到本機,或是也可以用unix socket

恩...就先這樣,執行pulseaudio之前.要先建立esd socket,不然,本機也會用tcp連線
mkdir -p /tmp/.esd
chmod 1777 /tmp/.esd
touch /tmp/.esd/socket
chmod 777 /tmp/.esd/socket
執行看看
pulseaudio --verbose
Note: 1. mplayer設定成pulse輸出的話,會crash. 改用esd輸出。
To support audio of Flash:
pulseaudio.revolutionlinux.com



星期一, 6月 04, 2007

In Ubuntu, there are many remote desktop utilities: tightvnc, vncserver, vnc4server(Xvnc), x11vnc, vino( the vnc which Feisty build in ).
The difference between them is to open a new display or connect to the existing one.

The easiest way for building server is choose the System -> Preference -> Remote Desktop and set up your settings.
But it's the solution in Gnome.

I use E17 as my window-manager, and don't know how to set up the vino-preference.
So, I've tried vncserver, vnc4server and finally x11vnc.

x11vnc is a server which let you control desktop environment remotely. It needs to start up X window first and use this display session( usually :0 ).
The most common problem is Xlib find display:0 error as .Xauthority isn't well set up.
When you see the tips and tried
ps -wwaux|grep auth
You'll find the existing session's auth. Here's the file used by Enlightenment 17.
x11vnc -auth /var/:0.Xauth
Also, you need a password for authentication of remote connection.
Just exec vncpasswd to generate ~/.vnc/passwd and use -rfbauth $HOME/passwd.
Or use -usepw. A .x11vncrc will be helpful.

As the client side, you can just use RealVnc's free client to connect the server.

ps. I found some errors as :
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
Google it and find the solution:
sudo xhost local:kimk
But I still don't understand why.