2012/02/04

Ubuntu/Linux Mint安裝jdownloader

紀錄如何在Ubuntu/Linux Mint安裝jdownloader並啟用自動關機功能

首先,藉由ppa來源安裝jdownloader


 sudo add-apt-repository ppa:jd-team/jdownloader
 sudo apt-get update
 sudo apt-get install jdownloader

安裝後如果要啟用jdownloader的自動關機
必須要讓使用者具有root權限來做關機的動作
所以接著要把使用者加入到sudoer文件中

為了防止出錯
先把sudoer這個檔案做備份
sudo cp /etc/sudoer /etc/sudoer.bak

接著用文字編輯器(這裡用的是vim)打開sudoer
sudo vim /etc/sudoer

在sudoer的最後加入
使用者名稱 ALL= NOPASSWD: /sbin/shutdown

存檔離開之後就可以正確執行jdownloader的自動關機功能

P.S如果所有步驟做完仍然不能執行,請先把sudoer回復
sudo cp /etc/sudoer.bak /etc/sudoer

2012/01/28

[C++]Lottery Number Creator

實作C++亂數的使用
範例是用樂透彩,由電腦亂數取出每一組有6個數字(不重複)的序列並印出

#include <iostream>
#include <time.h>

using namespace std;

int main()
{
    int a,n;
    int Index = 0;
    int Box[6];
    bool Exist ;

    srand(time(NULL));

    cout << "Please input a number:";
    cin >> n;

    while(n > 0)
    {
        for(int i=0; i<6; i++)
        {
            a = rand()%49+1;
            Exist = false;

            for(int j=0; j<Index; j++)
            {
                if(Box[j] == a)
                {
                    Exist = true;
                    break;
                }
            }

            if(Exist == false)
            {
                Box[Index] = a;
                Index++;
            }

            else
            {
                i--;
            }
        }

        for(int i=0; i<6; i++)
        {
            if(Box[i] < 10)
            {
                cout << 0 << Box[i] << " ";
            }
            else
            {
                cout << Box[i] << " ";
            }
        }

        cout << endl;
        n--;
        Index = 0;
    }

    system("PAUSE");
    return 0;
}

2012/01/19

Blogger Dynamic Views

把網誌的樣式換成Blogger Dynamic Views
(其實是在http://btemplates.com/找到的樣式套上來都有點問題)
有別以往靜態顯示
從左上角的下拉式選單可以變換動態顯示的模式
整體看起來的效果滿簡潔的
小小的缺點是目前還沒有辦法加上像以前側欄的小工具、連結...等

2011/11/12

[ArchLinux]開機時啟動Num Lock

X.org

If you use startx to start your X session, simply install the numlockx package and add it to your ~/.xinitrc file.
Install numlockx:
# pacman -S numlockx
Add it to ~/.xinitrc before exec:
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
#

numlockx &

exec your_window_manager


2011/11/11

wxDev C++ 安裝

簡單的寫一下初學C++的工具「Dev C++」的安裝過程
(目前Dev C++官方已經來到了7.4版)

2011/11/02

[C++]讀檔寫到陣列


一支用來讀取文字檔內容並且將資料轉成數值供運算的程式
其中每一行的資料數n可以自訂
可以儲存的資料這邊預設最多到100行

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
    int n;
    string Loc;
    string Line;
    string Get = "";
    int Row = 0;
    int Col = 0;
    int End = 0;
 
    cout << "請輸入檔案路徑:";
    getline(cin,Loc);
    cout << "每行有幾筆資料:";
    cin >> n;
 
    int Box[100][n];
 
    for(int i=0; i<100; i++)
    {
        for(int j=0; j<n; j++)
        {
            Box[i][j] = -1;
        }
    }
 
    ifstream infile(Loc.c_str(),ios::in);
 
    if(infile)
    {
        while(!infile.eof())
        {
            getline(infile,Line);
            Line = Line + " ";
         
            for(int i=0; i<Line.length(); i++)
            {
                if(Line[i] != ' ')
                {
                    Get = Get + Line[i];
                }
                else
                {
                    Box[Row][Col] = atoi(Get.c_str());
                    Get = "";
                    Col++;
                }
             
            }
            Row++;
            End++;
            Col = 0;
        }
        Line = "";
    }
    //
    else
    {
        cout << "Failed..." << endl;
    }
 
    for(int i=0; i<End; i++)
    {
        for(int j=0; j<n; j++)
        {
            cout << Box[i][j] << " ";
        }
        cout << endl;
    }
 
    system("PAUSE");
    return EXIT_SUCCESS;
}