2015年4月27日 星期一

[WEB] Node Package , npm-dep-info ,自動幫你產生好npm套件的註解,讓你時時不會忘記裝了什麼!

安裝 Install


npm install npm-dep-info -g

此時進入您正在開發的node app / 資料夾 輸入
npm-dep-info -T
即可產生註解~讓你隨時隨地看看

2015年4月15日 星期三

[WEB] 以FISH SHELL 執行 特定環境(specify) 來源命令時(Source Command) 會失敗 ,ENV,解決 fish: Illegal command name之解法。

當我在開發撰寫Express.js的code時,我發現我照著以下的步驟:
express myapp
cd myapp
npm install
這時候依照套件建議以DEBUG logging in retail的方式執行 我們會執行:
 DEBUG=myapp:* ./bin/www
SHOW UP:
 fish: Illegal command name
這時問題來了,因為fish shell對以特定environment執行script時,會有特定的定義。 所以解決方法一是換成BASH去執行
bash
解決方法二呢? 其實參考 http://fishshell.com/docs/current/index.html#variables 對於environment的區塊有特定的解釋 要以env為command去呼叫你的app 所以其實我們知道其實改成
env DEBUG=app: ./bin/www
就能成功執行! 恭喜你可以繼續開發了!!!

2015年4月13日 星期一

[WEB] 在CENTOS 下,允許mysql連線,解決iptables為防火牆會擋住連線的問題

一般iptables為防火牆,會擋下各種嘗試的連線 但是一定需要連到本端的資料庫,所以必須更改iptables的設定
iptables -A INPUT -s 192.168.0.0/24 -p tcp -m tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
註:透過3306port 最後記得restart!
service iptables restart

2015年4月11日 星期六

[MAC OSX] 如何在fish shell 使用個人自訂的SCRIPT ,FISH SHELL , MAC

假設我今天在fish shell 想要自訂的命令或是fuction ,其實可以掛在
 /User/您的使用者/.config/fish/functions
之下 假設我的script檔為aliases cd的command用
vi config_my.fish

function ..
  cd ..
end
function cd.
  cd ..
end
function cd..
  cd ../..
end

最後一樣記得re-source,完成!

[WEB] Fish-Shell 與 NVM 套件管理, 設定談 , 在MAC OS 環境下。

在利用HomeBrew安裝nvm時
brew install nvm
如果您是用fish script,有時候用新的登入,初始之script也許會沒有把nvm的path註冊起來,這時候建議去更改fish 的初始檔 可以利用nvm-fish這個套件
git clone https://github.com/Alex7Kom/nvm-fish.git ~/.nvm-fish
(記得要先安裝好GIT) 然後第二步請更改您的fish,在打開程式碼後:
vi~/.config/fish/config.fish
在代碼最下方增加:
source ~/.nvm-fish/nvm.fish
最後記得要Re-source ! 完成

2014年10月8日 星期三

[C] Linked List 實作

#include <stdio.h>
#include <stdlib.h>

typedef struct IDlist
{
     int userId;
     struct IDlist* next;
}tIDlist;


typedef struct IDhead
{
     int count;
     tIDlist *rear;
     tIDlist *front;
     
}tIDhead;


void printAll();
void addToHead(tIDhead*,int);
void addToTail(tIDhead*,int);
void removeFirst(tIDhead*);
void removeLast(tIDhead*);
void removeNth(tIDhead*,int);
void printAll();


tIDhead *reg;
tIDlist *previous;
int main (void)
{
     
     
     reg=(tIDhead *)malloc(sizeof(tIDhead));
     
     previous=(tIDlist *)malloc(sizeof(tIDlist));
     previous=NULL;
     
     int menu;
     int IDnumber;
     int nth;
     reg->count=0;
     reg->front=NULL;
     reg->rear=NULL;
     
     while (1)
     {
          printf("Which operation you want to operate? \n");
          
          
          printf("  1. insert one user ID to the head\n");
          printf("  2. insert one user ID to the tail \n");
          printf("  3. remove the first user ID\n");
          printf("  4. remove the last user ID\n");
          printf("  5. remove the n-th user ID\n");
          
          scanf("%d",&menu);
          //if 1.
          if (menu == 1)
          {
               
               printf("Please enter the user ID number:");
               scanf("%d",&IDnumber);
               addToHead(reg,IDnumber);
               
          }
          
          //if 2.
          else if (menu == 2)
          {
               printf("Please enter the user ID number:");
               scanf("%d",&IDnumber);
               addToTail(reg,IDnumber);
             //  printf("%d",reg->front->userId);
          }
          //if 3.
          else if (menu == 3)
          {
                  removeFirst(reg);
          }
          //if 4.
          else if (menu == 4)
          {
               previous=reg->front;
               removeLast(reg);
          }
          //if 5.
          else if (menu == 5)
          {
               printf("what number u want remove?\n");
               scanf("%d",&nth);
               removeNth(reg,nth);
          }
          else
          {
               
          }
          
          
          printAll();
          
     }
     system("pause");
     return 0;
     
}
void addToHead(tIDhead* reg,int Idnumber){
     tIDlist *tmp;
     
     tmp=(tIDlist *)malloc(sizeof(tIDlist));
     tmp->userId=Idnumber;
     
     if(reg->count==0){
          reg->front=tmp;
          
     }
     else{
          tmp->next=reg->front;
          reg->front=tmp;
     }
     
     reg->count++;
}
void addToTail(tIDhead* reg,int Idnumber){
     tIDlist *tmp;
     
     tmp=(tIDlist *)malloc(sizeof(tIDlist));
     tmp->userId=Idnumber;
     
     
     if(reg->count==0){
          reg->front=tmp;
          
     }
     else{
          reg->rear->next=tmp;
     }
     
     reg->rear=tmp;
     
     tmp->next=NULL;
     
     reg->count++;
     
}
void printAll(){
     
     tIDlist *tmp;
     
     tmp=(tIDlist *)malloc(sizeof(tIDlist));
     tmp->next=NULL;

     tmp=reg->front;
     int i=0;
     while (i<reg->count) {
          if (tmp==NULL) {
               break;
          }
          printf("%d.%d\n",i+1,tmp->userId);
          
          tmp=tmp->next;
          
          i++;
          
     }
     
}
void removeFirst(tIDhead* reg){
     reg->front=reg->front->next;
     reg->count--;
}
void removeLast(tIDhead* reg){
     
     if (previous->next->next==NULL) {
          //previous finded

          reg->rear=previous;
          reg->count--;
     }
     else{
          previous=previous->next;
          removeLast(reg);
     }
     
}
void removeNth(tIDhead* reg,int nth){
     int count=1;
     previous=reg->front;
     if (nth==1) {
          removeFirst(reg);
     }
     else if(nth==reg->count){
          previous=reg->front;
          removeLast(reg);
     }
     else{
          while (count<nth) {
               if (count+1==nth) {
                    previous->next=previous->next->next;
                    reg->count--;
                    break;
               }
               previous=previous->next;
               count++;
          }
     }
}


有時間再來打註解,打得蠻草的
有些是作業的要求(禁止使用迴圈,防呆功能)
才寫這麼亂

2014年10月2日 星期四

[ C ] memset ,初始化陣列

如要初始化陣列,比方說元素全部設為0




char  IamArray[10][10];

memset( IamArray, 0 ,sizeof(IamArray));



#note : 大小給程式自己抓就好