2010年12月31日 星期五

讓putty可以使用數字鍵

Terminal
-> Features

將Disable application keypad mode勾選

2010年12月16日 星期四

安裝media player classic中文語系

使用K-lite mega codec安裝時
選擇 Advanced install
然後在 additional tasks and options頁面,選擇 install languages files for MPC



安裝完成後,開啟media player classic
在 view -> language 中選擇 Chinese(Traditional)
就會有中文的介面了

檢視(view) -> 選項(options) -> 播放程式(player)
裡面的語系(language)選項可以更改語言

2010年12月15日 星期三

安裝msn時顯示已安裝之解決方法

引用自 三秒練功房


Windows Live 2009 通用移除程式完全版
http://www.threesecond.info/v2/modules/xhnewbb/viewtopic.php?topic_id=1643

2010年12月10日 星期五

設定vmware開機自動啟動

StartVM.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]

"StartVM"="\"C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmware.exe\" -x \"C:\\Users\\Duck\\Documents\\Virtual Machines\\my_FREEBSD\\my_FREEBSD.vmx\""

指令格式:
 vmware -x vm_machine (使用完整路徑)

2010年11月26日 星期五

php.ini

php5.3.3的php.ini放置位址
/usr/local/etc/php.ini

2010年11月25日 星期四

安裝 vim

cd /usr/ports/editor/vim
make install clean

參數設定:
/usr/local/share/vim/vim73/vimrc
set nocompatible
syntax on
set sw=2
set hls
set cindent
set backspace=2


/home/usr/.vimrc
set nocompatible
syntax on
set sw=2
set hls
set cindent
set backspace=2

2010年11月5日 星期五

freebsd apache + php + mysql

1.mysql 5.5

#安裝
cd /usr/ports/database/mysql55-server/
make install clean

#加入開機啟動
/etc/rc.conf
+ mysql_enable="YES"

#啟動mysql (直接reboot也可以)
/usr/local/etc/rc.d/mysql-server start

#設定root密碼
mysqladmin -u root password 新密碼

#測試密碼
mysql -u root -p


2.apache22
#安裝
cd /usr/ports/www/apache22/
make install clean
config 選擇 mod_mysql

#設定/etc/hosts
127.0.0.1               localhost MyFreeBSD

#設定/etc/rc.conf
hostname="MyFreeBSD"
apache22_enable="YES"
apachectl start

3.php
#安裝
cd /usr/ports/lang/php5
make install clean

#安裝 php-extensions
cd /usr/ports/lang/php5-extensions
make install clean

#修改/usr/local/etc/apache22/httpd.conf
#拿掉開頭的"#"
Include etc/apache22/extra/httpd-userdir.conf


#安裝mod_php56
cd /usr/ports/www/mod_php56
make install clean

#增加index.php
DirectoryIndex index.htm index.php

#增加下面幾行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

#修改/usr/local/etc/apache22/extra/httpd-userdir.conf
UserDir public_html
兩個public_html都改成www

2010年11月4日 星期四

port更新

方法一:cvsup

#從 /usr/ports/net/cvsup-without-gui 安裝

cd  /usr/ports/net/cvsup-without-gui
make install clean

#複製config檔案
cp /usr/share/examples/cvsup/ports-supfile /usr/ports-supfile

#更改 default host
*default host=freebsd.csie.ncu.edu.tw

#更新ports
cvsup -g -L 2 /usr/ports-supfile


方法二:csup

#複製config檔案
cp /usr/share/examples/cvsup/ports-supfile /usr/ports-supfile


#更改 default host

*default host=freebsd.csie.ncu.edu.tw


#更新ports
csup -g -L 2 /usr/ports-supfile




方法三:portsnap


#修改config檔 /etc/portsnap.conf

SERVERNAME=portsnap.tw.FreeBSD.org

#第一次執行更新
portsnap fetch extract

#之後更新
portsnap fetch update


cvsup 及 csup 使用 port 5999 容易被防火牆擋下來
portsnap 使用 http protocol 是被防火牆擋下來時的好選擇

實測結果 portsnap.tw.freebsd.org 下載速度緩慢(6-8k),直接從portsnap.freebsd.org下載也僅100k上下,第一次更新的話需要較久的時間。

20111227 更新
目前實測portsnap.tw.freebsd.org有500kBps ~ 1MBps,速度快了很多。

2010年11月3日 星期三

使用http通訊協定抓取遠端檔案

來源檔案位址 超連結
ex: "http://tw.yahoo.com/index.htm"
儲存檔案位址 本機儲存位址
ex: "c:\download\index.htm"
using System; 
using System.IO; 
using System.Text; 
using System.Net; 
 
        static void get_file(string[] args) 
        { 
            try 
            { 
                string fn = "超連結"; 
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(fn); 
                HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); 
                Console.WriteLine("File size = " + httpResponse.ContentLength); 
                    System.IO.Stream datastream = httpResponse.GetResponseStream(); 
                    byte[] buffer = new byte[8192]; 
                    FileStream fs = new FileStream("本機儲存位址", FileMode.Create, FileAccess.Write); 
                    int size = 0; 
                    do 
                    { 
                        size = datastream.Read(buffer, 0, buffer.Length); 
                        if (size > 0) 
                            fs.Write(buffer, 0, size); 
                    } while (size > 0); 
                    Console.WriteLine(fn + " download Done!!"); 
                    fs.Close(); 
                    httpResponse.Close(); 
            } 
            catch(Exception) 
            { 
                Console.WriteLine("Url not exists!"); 
            } 
            Console.ReadKey(); 
        }

2010年10月26日 星期二

移除創見隨身碟防寫保護

原文如下:
http://asper.pixnet.net/blog/post/25960737

一個隨身碟搞了一兩個小時,還不是一定成功,都快被搞死了 =.=a

2010年10月22日 星期五

修改plurk樣式






code:

#timeline_holder .plurk_cnt,
.plurk_cnt,
.plurk_box .list,
.list .plurk_cnt,
.list .plurk_cnt tr,
.plurk_box .mini_form,
td.td_cnt texture,
textarea#input_small
{
background:#D4EEFB !important;
}

.plurk_cnt{
border-right :1px solid #AAA;
border-left: 1px solid #AAA;
border-top: 1px solid #AAA;
}

.plurk_box .list {
border-right :1px solid #AAA;
border-left: 1px solid #AAA;
}
.plurk_box .mini_form {
border-right :1px solid #AAA;
border-left: 1px solid #AAA;
}

.plurk_box .caption {
border-right :1px solid #AAA;
border-left: 1px solid #AAA;
border-bottom: 1px solid #AAA;
border-top: 1px solid #AAA;
background-color: #A9DFF6;
font-size: 11px;
}

.list .plurk_cnt tr {
  border-bottom: 1px dashed #AAA;
}

2010年10月6日 星期三

檢查service是否執行

檢查service是否執行,如未執行則執行之 程式碼參考以下網站 http://blog.miniasp.com/post/2009/04/Windows-Service-Start-Stop-Restart-in-CSharp.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace auto_services
{
  class Program
  {
    class APP
    {
      //start_serv returns
      //return 1 work start
      //return 0 work fault
      public static int start_serv(string m_ServiceName)
      {
        try
        {
          // 建立 ServiceController 物件實體
          ServiceController service = new ServiceController(m_ServiceName);
          // 設定一個 Timeout 時間,若超過 30 秒啟動不成功就宣告失敗!                      
          TimeSpan timeout = TimeSpan.FromMilliseconds(1000 * 30);
          // 啟動服務                      
          service.Start();
          // 設定該服務必須在等待 timeout 時間內將狀態改變至「已啟動(Running)」的狀態
          service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }                
        catch                
        {                    
          return 0;                
        }                
          return 1;
      }            
      //status_serv returns            
      //return 1 work            
      //return 0 stop            
      public static int status_serv(string m_ServiceName)            
      {                
        // 建立 ServiceController 物件實體                  
        ServiceController service = new ServiceController(m_ServiceName);
        if (service.Status != ServiceControllerStatus.Stopped && service.Status != ServiceControllerStatus.StopPending)
          return 1;                
        else                    
          return 0;            
      }            
      public static void run_serv(string m_ServiceName)            
      {                
        if (APP.status_serv(m_ServiceName) == 0)                
        {                    
          int i = APP.start_serv(m_ServiceName);                    
          if (i == 1)                        
            Console.WriteLine(m_ServiceName + "服務成功啟動!");                    
          else                        
            Console.WriteLine(m_ServiceName + "服務無法啟動,請檢查相關設定!");                
        }                
        else                
        {                    
          Console.WriteLine(m_ServiceName + "服務已啟動!");                
        }            
      }        
    }
        static void Main(string[] args)
        {            
      // 已知的 Service Name              
      string m_ServiceName = "MSSQL";            
      //檢查並執行             
      APP.run_serv(m_ServiceName);        
    }    
  }
}

2010年7月14日 星期三

自動修改ip,name,workgroup V1.0

在C:\下放置mac.txt檔案 內容為 12345 00:00:00:00:00:00
電腦名稱 :123
電腦編號 :45
網路卡號 :00:00:00:00:00:00
using System;
using System.Management;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;

class Program
{
    public static void Main()
    {
        FileInfo filename = new FileInfo("C:\\done");

        if(!filename.Exists)
        {
            string fn = "C:\\mac.txt";
            FileStream fs = new FileStream(fn,FileMode.Open);
            StreamReader sr = new StreamReader(fs,Encoding.UTF8);

            string[] map = new string[50000];
            string mac = APP.GetMAC();

            while(sr.Peek() != -1){
                string tmp = sr.ReadLine();
                string[] tmp_sp = tmp.Split(' ');
                map[Convert.ToInt32(tmp_sp[0])] = tmp_sp[1];
            }
       
            for (int i = 30000; i < 40700; i++)
            {
                if (map[i] != null)
                {
                    if (map[i].CompareTo(mac) == 0)
                    {
                        /*更改電腦名稱,群組,網路位址*/
                   
                        APP.change_name(i);
                        APP.change_group(i);
                        APP.SetNetIP(i);
                        FileStream files = filename.Create();
                        files.Close();                   
                    }
                }
            }
            fs.Close();
        }
    }
}

class APP
{
//修改電腦名稱_code
    enum _COMPUTER_NAME_FORMAT
    {
        ComputerNameNetBIOS,
        ComputerNameDnsHostname,
        ComputerNameDnsDomain,
        ComputerNameDnsFullyQualified,
        ComputerNamePhysicalNetBIOS,
        ComputerNamePhysicalDnsHostname,
        ComputerNamePhysicalDnsDomain,
        ComputerNamePhysicalDnsFullyQualified,
        ComputerNameMax
    };
   
    [DllImport("kernel32.dll")]
    static extern bool SetComputerName(string lpComputerName);

    [DllImport("kernel32.dll")]
    static extern bool SetComputerNameEx(_COMPUTER_NAME_FORMAT iType, string lpComputerName);

    public static void change_name(int i)
    {
        string room = Convert.ToString(i / 100);
        string id = "";
        int sitnum = i % 100;
        if (sitnum < 10)
            id = string.Concat("0",Convert.ToString(sitnum));
        else
            id = Convert.ToString(sitnum);
        string MachineName = "";
        if(room.CompareTo("313") == 0)
            MachineName = string.Concat("P",room,"_",id);
        else
            MachineName = string.Concat("CC",room,"_",id);

        SetComputerName(MachineName);
        SetComputerNameEx(_COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, MachineName);

//修改電腦名稱_code_end

    }

//修改工作群組_code
    public static void change_group(int i)
    {
        string num = Convert.ToString(i / 100);
        string WorkgroupName = "";
        if(num.CompareTo("313") == 0)
            WorkgroupName = string.Concat("P", num);
        else
            WorkgroupName = string.Concat("CC",num);
        ManagementObject manage = new ManagementObject(string.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName));
        object[] args = { WorkgroupName, null, null, null };
        manage.InvokeMethod("JoinDomainOrWorkgroup", args);
    }
//修改工作群組_code_end

//取得mac address_code
    public static string GetMAC()
    {
        using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
        {
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"])
                    return mo["MacAddress"].ToString();
            }
        }

        return null;
    }
//取得mac address_code_end

//修改ip address_code
    public static void SetNetIP(int i)
    {
        string class_name =Convert.ToString(i / 100);
        string id = Convert.ToString(i % 100);
        string cclass;
        switch(class_name)
        {
            case "305":
                cclass = "35";
                break;
            case "307":
                cclass = "37";
                break;
            case "402":
                cclass = "42";
                break;
            case "403":
                cclass = "43";
                break;
            case "406":
                cclass = "46";
                break;
            case "313":
                cclass = "13";
                break;
            default:
                cclass = "0";
                break;
        }
        string ip, submask, gateway, DNS1, DNS2;
        string Cls = "Win32_NetworkAdapterConfiguration";
        string NS = "root\\CIMV2";
        ip = string.Concat("192.168.", cclass, ".", id);
        submask = "255.255.255.0";
        gateway = string.Concat("192.168.", cclass, ".254");
        DNS1 = "120.125.1.1";
        DNS2 = "120.125.2.1";
        using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
        {
            string index = "";
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"])
                {
                    index = mo["Index"].ToString();
                }
            }

            ManagementObject objCls = new ManagementObject(NS, Cls + ".INDEX=" + index, null);
            ManagementBaseObject objInPara;

            objInPara = objCls.GetMethodParameters("EnableStatic");
            objInPara["IPAddress"] = new string[] { ip};
            objInPara["SubnetMask"] = new string[] { submask};
            objCls.InvokeMethod("EnableStatic", objInPara, null);

            objInPara = objCls.GetMethodParameters("SetGateways");
            objInPara["DefaultIPGateway"] = new string[] { gateway};
            objCls.InvokeMethod("SetGateways", objInPara, null);

            objInPara = objCls.GetMethodParameters("SetDNSServerSearchOrder");
            objInPara["DNSServerSearchOrder"] = new string[] { DNS1,DNS2};
            objCls.InvokeMethod("SetDNSServerSearchOrder", objInPara, null);

        }
    }
//修改ip address_code_end
}

2010年6月24日 星期四

隱藏下載檔案

$file = ""; #檔案所在位置
$filename = ""; #檔案下載檔名
$filesize = ; #檔案大小(byte)
header("Expires:0");
header("Content-Type:application/save-as");
header("Content-Disposition:attachment; filename=".$filename);
header("Content-Length:".$filesize);
readfile($file);

office 2010 kms 認證 bat 檔

@echo off
if exist "%programfiles(x86)%\microsoft office\office14\ospp.vbs" goto file1
if exist "%programfiles%\microsoft office\office14\ospp.vbs" goto file2
goto end

:file1
cscript "%programfiles(x86)%\microsoft office\office14\ospp.vbs" /osppsvcrestart
cscript "%programfiles(x86)%\microsoft office\office14\ospp.vbs" /sethst:your-kms-server
cscript "%programfiles(x86)%\microsoft office\office14\ospp.vbs" /act
goto end

:file2
cscript "%programfiles%\microsoft office\office14\ospp.vbs" /osppsvcrestart
cscript "%programfiles%\microsoft office\office14\ospp.vbs" /sethst:your-kms-server
cscript "%programfiles%\microsoft office\office14\ospp.vbs" /act
goto end

:end
PAUSE

另存成.bat檔,修改藍色部位,即可使用 。

2012/08/20新增
加入紅色部分指令,有時候office的服務不會自動啟動,這行指令可以啟動服務,再做驗證。

2010年5月14日 星期五

freebsd-update

資料來源
http://www.freebsd.org/releases/7.3R/announce.html

FreeBSD Update

The freebsd-update(8) utility supports binary upgrades of i386 and amd64 systems running earlier FreeBSD releases. Systems running 7.[012]-RELEASE, 7.3-BETA1, or 7.3-RC[12] can upgrade as follows:

# freebsd-update upgrade -r 7.3-RELEASE

During this process, FreeBSD Update may ask the user to help by merging some configuration files or by confirming that the automatically performed merging was done correctly.
 
# freebsd-update install

The system must be rebooted with the newly installed kernel before continuing.
 
# shutdown -r now

After rebooting, freebsd-update needs to be run again to install the new userland components, and the system needs to be rebooted again:
 
# freebsd-update install
# shutdown -r now

Users of earlier FreeBSD releases (FreeBSD 6.x) can also use freebsd-update to upgrade to FreeBSD 7.3, but will be prompted to rebuild all third-party applications (e.g., anything installed from the ports tree) after the second invocation of "freebsd-update install", in order to handle differences in the system libraries between FreeBSD 6.x and FreeBSD 7.x.

2011年1月3日補充
如果是8.1-RELEASE-p0 更新到 8.1-RELEASE-p2的話
# freebsd-update fetch
# freebsd-update install
# reboot
即可

2010年4月14日 星期三

顯示編輯器的行數

參考   http://msdn.microsoft.com/zh-tw/library/ms165340.aspx

  1. 在 [工具] 功能表中選取 [選項]。
  2. 在 [文字編輯器] 資料夾中,選擇 [所有語言] 子資料夾內之 [一般] 選項,將此選項設定為全域性。
    -或-
    在您用來進 行程式設計的語言子資料夾內選擇 [一般] 選項。
  3. 在 [ 顯示] 下,選取 [ 行號]。

獲得mac address

using System;
using System.Management;

class App
{
  static string GetMAC()
  {
 using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
 {
   ManagementObjectCollection moc = mc.GetInstances();
   foreach (ManagementObject mo in moc)
   {                
     if ((bool)mo["IPEnabled"])
       return mo["MacAddress"].ToString();
   }
 }
   return null;
  }

  public static void Main()
  {
 SelectQuery query = new SelectQuery("Win32_ComputerSystem");
 ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
 foreach (ManagementObject mo in searcher.Get())
 { 
   Console.WriteLine("Mac Address : {0} ", GetMAC());
 }
 Console.ReadKey();
  }
}

修改電腦工作群組

using System;
using System.Management;
class program
{
  public static void Main()
  {
    string WorkgroupName = "ECLASS";
    ManagementObject manage = new ManagementObject(string.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName));
    object[] args = { WorkgroupName, null, null, null };
    manage.InvokeMethod("JoinDomainOrWorkgroup", args);
    Console.WriteLine("Done! The Workgroup name will take effect after the next computer restart.");
    Console.ReadKey();
  }
}

修改電腦名稱

using System;
using System.Runtime.InteropServices;
class Program
{
    enum _COMPUTER_NAME_FORMAT
    {
        ComputerNameNetBIOS,
        ComputerNameDnsHostname,
        ComputerNameDnsDomain,
        ComputerNameDnsFullyQualified,
        ComputerNamePhysicalNetBIOS,
        ComputerNamePhysicalDnsHostname,
        ComputerNamePhysicalDnsDomain,
        ComputerNamePhysicalDnsFullyQualified,
        ComputerNameMax
    };
    //_COMPUTER_NAME_FORMAT COMPUTER_NAME_FORMAT;

    [DllImport("kernel32.dll")]
    static extern bool SetComputerName(string lpComputerName);

    [DllImport("kernel32.dll")]
    static extern bool SetComputerNameEx(_COMPUTER_NAME_FORMAT iType, string lpComputerName);

    public static void Main()
    {
        string MachineName = "winxp-vm";
        bool succeeded = SetComputerName(MachineName);
        bool succeeded2 = SetComputerNameEx(_COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, MachineName);

        if (succeeded && succeeded2){
            Console.WriteLine("Done! The name will take effect after the next computer restart.");
        }
        else
        {
            Console.WriteLine("Error!");
        }
        Console.ReadKey();
    }
}

2010年3月30日 星期二

安裝 apache2.2 + php5

windows 設定
先安裝apache2.2
再安裝php5
安裝完後在httpd.conf最後面加上

#c:/program files/php/  是php的安裝路徑
LoadModule    php5_module    "C:/Program Files/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/Program Files/PHP/"

freebsd 設定

先安裝apache2.2
再安裝php5
安裝完後檢視httpd.conf 如果沒有以下設定則加上
AddType application/X-httpd-php .php
AddType application/X-httpd-php-source .phps

關閉檔案目錄顯示
Options -Indexes FollowSymLinks
(前面加個減號 或者是整個拿掉)

2010年3月22日 星期一

SDP

網站:SDP

可以線上即時抓取串流影音檔案。

1.開啟主程式。


















2.開啟鏈結




3.開始抓取串流



4.儲存檔案位址



5.抓取中



6.停止抓取





轉檔軟體 - 阿特拉斯的軟體倉庫

網站:阿特拉斯的軟體倉庫

有可以轉檔的工具程式,下載網路影音檔案的程式,音樂、圖片的編輯程式,FLV檔案的編輯程式...等等。

2010年3月9日 星期二

big5與utf-8互轉

big5轉utf8
$txt_utf8 = iconv("big5","UTF-8",$line);
utf8轉big5
$txt_big5 = iconv("UTF-8","big5",$line);

2010年3月2日 星期二

清理 shm 資訊

config.h
#define BRDSHM_KEY 2997
#define UTMPSHM_KEY 1998
#define FILMSHM_KEY 2999

%ipcs
Message Queues:
T ID KEY MODE OWNER GROUP

Shared Memory:
T ID KEY MODE OWNER GROUP
m 65536 1998 --rw------- bbs bbs
m 65537 2997 --rw------- bbs bbs
m 65538 2999 --rw------- bbs bbs

Semaphores:
T ID KEY MODE OWNER GROUP

%ipcrm -M 1998
%ipcrm -M 2997
%ipcrm -M 2999

2010年2月24日 星期三

Fatal error: Allowed memory size of 134217728 bytes exhausted



Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in /usr/home/web/php_excel/Classes/PHPExcel/Cell.php on line 155


出現這個訊息是預設的記憶體空間不足
可以在程式裡加上

ini_set('memory_limit','200M');

暫時擴充程式可以使用的記憶體空間

2010年1月7日 星期四

進入不同資料夾執行相同動作之shell

#!/bin/sh

file=`cat /home/bbs/brd/zzz2`  //所有路徑名單

for th in $file  //逐一執行所有路徑
do
  cd /home/bbs/brd/$th  //進入某路徑
  /home/bbs/bin/redir -b  //執行指令
  mv .DIR .DIR.bak
  mv .DIR.re .DIR
  echo $th done...
done