[網站] 好站連結 (八) Android, javascript, CSS, PHP, Perl, FreeBSD, Linux

PHP

CSS

Html5

Git:

Javascript:

FreeBSD:

[Read More]

2011 OSDC Day 1 筆記

Update: 補上 OSDC 紀錄影片 2011.06.26 今年很高興可以北上參加 OSDC 2011 (Open Source Developers Conference),由於之前都在南部唸書及工作,沒有機會北上參加聚會,現在人在新竹,終於有機會可以參加了,雖然早上六點就要起床趕電車了,不過到現場聽課感覺就是不同,也可以認識很多新朋友,底下來紀錄上課筆記

微軟與 jQuery 社群的親密接觸

講者: Eric Shangkuan (Microsoft) Slide: 微軟與 jQuery 社群的親密接觸 這是 OSDC 第一場演講,早上九點就開始了,雖然人不多,但是蠻多人還是為了講者而來,首先介紹什麼是 jQuery,以及 jQuery 一些基本用法,像是 CSS selector,如何在 Windows Visual Studio 上面開發 jQuery 及撰寫 plugin 整合進去 ASP.Net,最後介紹三個不錯用的 jQuery Plugin: Templeate, Datalink, Globalzation

  • Templeate: 這搭配 Facebook api 可以直接做個人頁面,請參考這裡
  • Globalzation: 前端多國語系實做
  • Datalink: 可以快速處理 form,利用 object 跟 jQuery 搭配

如果要研究上述三個 jQuery Plugin 可以參考底下: jQuery Datalink: https://github.com/jquery/jquery-datalink jQuery Templeate: https://github.com/jquery/jquery-tmpl jQuery Globalzation: https://github.com/jquery/jquery-global

HandlerSocket - A NoSQL plugin for MySQL

講者: Jui-Nan Lin (PIXNET) Slide: HandlerSocket - A NoSQL plugin for MySQL 會後有部份聽眾提出了一些問題,PIXNET 也已經回報給 MySQL 請他們修復這些問題,可以參考 gslin 大神回覆的這篇: MySQL HandlerSocket 的情況…,不過 NoSQL 有個缺點就是沒有帳號密碼,這部份蠻好解覺的,因為 DB 都直接放在後面,前面加上防火牆就好了。

[Read More]

[Linux] 嵌入式系統不可或缺的工具 – busybox 分析 ifconfig command

Busybox

玩過嵌入式系統的使用者,一定都會知道 Busybox,它提供一些小型 Linux command,方便在 console 端使用,以及一些 C 語言或者是 shell script 裡面,大家都知道 ifconfig 這指令,為了從 Kernel 2.6.15 轉換到 2.6.34.7 版本,原本的 Busybox 版本只有 1.0.1,現在已經到 1.18.1,轉換過程改了 Kernel netfilter 部份,以及 user space 部份 iptables extension。ifconfig 是 Busybox 其中一個指令用來查看目前有多少網路介面(network interface),來看看他是如何得到這些 interface 資訊,包含介面名稱、type、IP Adress、IP network mask、HW address 等….。

要讀取 interface 相關資訊可以透過兩種方式,一種是讀取 (IPv6 是 /proc/net/if_inet6),另一種透過 Socket 連接SOCK_DGRAM,最後用 iotcl 方式讀取 interface 相關資料,busybox 會先偵測檔案 /proc/net/dev 是否存在,如果 Kernel 有支援,就會讀取此檔案,如果不存在,則利用 socket 讀取資料。

if_readlist_proc 函式裡面:

1
2
3
4
fh = fopen_or_warn(_PATH_PROCNET_DEV, "r");
if (!fh) {
    return if_readconf();
}

看一下 /proc/net/dev 內容

1
2
3
4
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:     104       1    0    0    0     0          0         0      104       1    0    0    0     0       0          0
  eth0:21798505   51360    0    0    0     0          0         0  7693686   46844    0    0    0     0       0          0
[Read More]

[C/C++] 判斷檔案是否存在 file_exists

在 PHP 函式裡面,有直接 file_exists 可以使用,相當方便:

1
2
3
4
5
<?php
if(file_exists("files/appleboy.c")) {
    echo "File found!";
}
?>

在 C 裡面該如何實做?有兩種方式如下:

1. 直接開檔

1
2
3
4
5
6
7
8
9
bool file_exists(const char * filename)
{
    if (FILE * file = fopen(filename, "r"))
    {
        fclose(file);
        return true;
    }
    return false;
}

C++ 寫法

[Read More]

[C/C++] 將字串轉成 16 進位

最近在碰嵌入式系統遇到一個還蠻常見的問題,我要將16進位的字串(例如 AAC2) test 轉成16進位的 unsigned int,讓我可以進行 & | not 一些二進位運算,底下是轉換程式,大家參考看看

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int power(int x,int n)
{
    int i;
    int num = 1;
    for(i=1;i<=n;i++)
        num*=x;
    return num;
}

int transfer_string_to_hex(unsigned char *str_name)
{
    char string[]="0123456789ABCDEF";
    int number[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    int i = 0;
    int j = 0;
    int str_number = 0;
    for(i=0; i<sizeof(str_name); i++)
    {
        for(j=0; j<sizeof(string); j++)
        {
            if(toupper(str_name<em></em>) == string[j])
            {
                str_number += power(16, (sizeof(str_name)-1-i))* number[j];
                break;
            }
        }
    }
    return str_number;
}

由於嵌入式並沒有 pow 這個函式可以使用,所以自己寫了 power 來取代,我用在偵測網路線是否有插上:

[Read More]

[C/C++] cstring (string.h) 函式:strcat, strncat, strcmp, strncmp

串接函式 strcat

strcat 此函式用來連接兩字串合併成單一字串,直接看底下範例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/* strcat example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[80];
  strcpy (str,"these ");
  strcat (str,"strings ");
  strcat (str,"are ");
  strcat (str,"concatenated.");
  puts (str);
  return 0;
}

output:

[Read More]

[C/C++] cstring (string.h) 搜尋函式:strstr, strchr

這次介紹 C 語言常用 string 函式:strstr,主要是針對兩個輸入參數做比對,Parameters 1輸入字串Parameters 2找尋字串,strstr 會先將頭一次比對成功的 pointer 回傳,也就是如果要找尋 appleboyappleboy 字串中的 boy,函式會回傳第一次比對成功的 boy pointer,而並非回傳最後一個比對到的,底下是一個參考範例:

strstr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/* strstr example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="This is a simple string";
  char * pch;
  /* 找尋 simple 字串 */
  pch = strstr (str,"simple");
  /* 將 simple 換成 sample */
  strncpy (pch,"sample",6);
  puts (str);
  return 0;
}

看一下 Kernel 原始檔案,strstr 函式:

[Read More]

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C#

html

  • [將所有 的內容包到一個

    中][7]

apache

javascript

CSS

[Read More]

[C/C++] count 1 bits of input value by shifting.

之前寫了一篇:『[C/C++] 計算二進位任意數含有多少個位元為1?』,裡面用 n &= (n - 1); 的方式來計算二進位數字總共會得到多少 bit,這次來紀錄利用 shift 方式也可以得到總共含有多少 bit 數目,函式如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <stdlib.h>
int count_1_bit_count(unsigned int);
int main(){
    int count = 0, a;
    a = 1023;
    count = count_1_bit_count(a);
    printf("%d有%d個位元為1\n\n", a, count);
    system("pause");
    return 0;
}
int count_1_bit_count(unsigned int n)
{
    int count = 0;
    for(count = 0; n != 0; n >>= 1L)
    {    
        if(n & 0x01)
            count++;
    }    
    return count;
}

關鍵就是在 n »= 1L,把該數字往右位移 1 bit,然後跟 0x01 去做 and,如果數字大於0,count 就加 1。