之前把一台用不到的無線AP架在我房間內,想讓手機跟iPad都可以無線上網,但是很奇怪的事情發生了,我的Android手機居然抓不到WiFi的SSID,但是iPad跟iPhone都可以,google也找不到原因,後來就懶得理他了,反正我的手機有3G吃到飽。
但是最近忽然心血來潮把那台AP刷了最新版的dd-wrt,就抓的到了,可是我做了一些調整之後,又發現抓不到了!!!居然是設定的問題,所以我就開始檢查到底是什麼設定出問題,結果發現,是頻率不能調自動,我把頻率固定在頻道6就能夠抓到了~~~
2014年1月29日 星期三
使用jQuery的attr注意事項
這篇其實是寫給自己看的,最近在做一個階層式選單,所有資料都是使用ajax拿回來的,連第一層也是。所以頁面一打開,他會去讀第一層的資料,點第二層之後去拿第三層,點第三層去拿第四層....
但是為了避免資源浪費,所以拿過的資料不要重複拿,不要看的時候就把他隱藏起來,要看再打開讓他看,這時需要2個控制變數,一個判斷是否有拿過資料,一個判斷是否要打開或隱藏這個元素
所以我很自然的 取了 data, open 當做變數名稱放在html tag裡面使用,但是open在html5裡面居然是一個keyword,雖然使用$(this).attr('open', 'true')可以正確設置open='true',但是使用$(this).attr('open')取回值,他一律回open!!!!!!!
又不是歐噴醬,幹嘛一直回我歐噴!!!!!!
所以以後最好避免使用open當做tag的名稱...切記...
本次重點整理
但是為了避免資源浪費,所以拿過的資料不要重複拿,不要看的時候就把他隱藏起來,要看再打開讓他看,這時需要2個控制變數,一個判斷是否有拿過資料,一個判斷是否要打開或隱藏這個元素
所以我很自然的 取了 data, open 當做變數名稱放在html tag裡面使用,但是open在html5裡面居然是一個keyword,雖然使用$(this).attr('open', 'true')可以正確設置open='true',但是使用$(this).attr('open')取回值,他一律回open!!!!!!!
所以以後最好避免使用open當做tag的名稱...切記...
本次重點整理
- 要使用attr取得tag的內容,最好初始的html就有該tag名稱,不然他一律回undefined,直到你用attr設定了該tag的值
- html tag一律為字串,所以設定$(this).attr('data', true)跟$(this).attr('data', 'true')之後,取回內容一律為字串的true,建議一開始寫入就寫字串,比較不會混淆
- 千萬別用open當做tag名稱
,不然他會變歐噴醬。 - 使用attr設定tag值為false時會使得該tag消失,下次想用attr取回時會回傳undefined,要非常注意,解決方式是設置字串的false就好
標籤:
javascript,
jikker知識+
使用jQuery在表格中任一插入一列
最近再做一個表格,要能在表格中任意插入一列,google了幾個方法都是教你用eq(x),就能在某一行後面插入balabala...
阿我就是不知道要在哪行後面插入啊!!!!!,掯,這不是廢話嗎?
爆氣之後決定自己想辦法,以下就是source code。
要注意的是一般我們插入元件都會用append加到後面,但是append這個指令其實是會把要加入的內容放在該元素的最後面,而不是這個元素的後面。意思就是,新加入的內容還是算在該元素的頭上,不會自成一個元素。
在加入一般的元素或許沒什麼問題,但是要加入表格就會造成版面亂掉,
所以這邊加入要使用after或是before,這2個指令才會把加進去的內容放在原本的元素外面。
阿我就是不知道要在哪行後面插入啊!!!!!,掯,這不是廢話嗎?
爆氣之後決定自己想辦法,以下就是source code。
要注意的是一般我們插入元件都會用append加到後面,但是append這個指令其實是會把要加入的內容放在該元素的最後面,而不是這個元素的後面。意思就是,新加入的內容還是算在該元素的頭上,不會自成一個元素。
在加入一般的元素或許沒什麼問題,但是要加入表格就會造成版面亂掉,
所以這邊加入要使用after或是before,這2個指令才會把加進去的內容放在原本的元素外面。
$(document).on('click', '.tr', function(){
$(this).after("<tr class='tr'><td>data</td></tr>"); //要放在前面就把after換成before
});
標籤:
javascript,
jikker知識+
2013年12月13日 星期五
jQuery實做輸入時清除input文字
以下程式碼可以完成 點擊input對話框時清除上面的文字,若沒輸入則還原
$(".box").focus(function(){
$(this).addClass("focus");
if($(this).val() ==this.defaultValue){
$(this).val("");
}
}).blur(function(){
$(this).removeClass("focus");
if ($(this).val() == '') {
$(this).val(this.defaultValue);
}
});
標籤:
javascript,
jikker知識+
2013年11月28日 星期四
使用python實做AES加密
本篇是要註記一下如何使用python對檔案進行AES加密
所需工具
使用方法
python ./encrypt.py encrypt file
python ./encrypt.py decrypt file keyfile
所需工具
使用python的pycrpto工具就可以簡單的完成AES加解密的程序,要注意的地方是使用的key跟vi需要是16byte的倍數長度的字串,以及加密的區快也需要是16byte的倍數,所以若資料量不足16byte則建議用\0補足16byte。
加密執行完畢後會產生file.encrypt, file.key,file.encrypt就是加密後的檔案,file.key則放入解密需要的資訊,若遺失了檔案就無法解密了。解密執行完畢後則會產生出file.decrypt,就是解密後的檔案。
加密執行完畢後會產生file.encrypt, file.key,file.encrypt就是加密後的檔案,file.key則放入解密需要的資訊,若遺失了檔案就無法解密了。解密執行完畢後則會產生出file.decrypt,就是解密後的檔案。
使用方法
python ./encrypt.py encrypt file
python ./encrypt.py decrypt file keyfile
import os, sys, json
from Crypto.Cipher import AES
if len(sys.argv) < 3 or ( sys.argv[1] == "decrypt" and len(sys.argv) != 4 ):
print "command encrypt/decrypt file (keyfile)"
action = sys.argv[1]
file = sys.argv[2]
def encrypt(file):
print "Encrypt now"
if os.path.isfile(file):
statinfo = os.stat(file)
size = statinfo.st_size
name = os.path.basename(file)
key = genkey(file, size)
obj = AES.new(key[0].decode('hex'), AES.MODE_CBC, key[1].decode('hex') ) # 將key轉回binrary格式再使用
chunksize = 16*4 #單次加密區塊大小 必須為16的倍數
encrypt_file = file + '.encrypt' # 加密後檔名
with open(file, 'rb') as inputfile:
with open(encrypt_file, 'wb') as outputfile:
while True:
chunk = inputfile.read(chunksize) # 讀取原始檔案
if len(chunk) == 0: # 加密完畢後退出迴圈
break
elif len(chunk) % chunksize != 0: # 若剩餘長度不足大小 自動補\0
chunk += '\0' * (chunksize - len(chunk) % chunksize)
outputfile.write(obj.encrypt(chunk)) # 寫入加密後的資料
print "Encrypt finish."
else:
print "Encrypt file not exist.";
def decrypt(file, key):
print "Decrypt now"
if os.path.isfile(file):
f = open(key, 'r')
key = eval(f.read()) # 讀取key
f.close()
obj = AES.new(key[0].decode('hex'), AES.MODE_CBC, key[1].decode('hex') ) # 將key轉回binrary格式再使用
chunksize = 16*4*4 # 解密區塊大小 必須為16的倍數
name = file.split('.')[0] + ".decrypt" # 解密後檔名
with open(file, 'rb') as inputfile:
with open(name, 'wb') as outputfile:
while True:
chunk = inputfile.read(chunksize)
if len(chunk) == 0: # 解密完畢後退出迴圈
break
outputfile.write(obj.decrypt(chunk)) # 寫入解密後的資料
outputfile.truncate(key[2]) # 將多餘的檔案去除
print "Decrypt finish."
else:
print "Decrypt file not exist.";
def genkey(file, size):
# 產生16byte長度的亂數
# [key, vi, filesize]
key = [ os.urandom(16).encode('hex'), os.urandom(16).encode('hex'), size] # 將亂數轉為字串方便存成文字檔
keyfile = file + ".key"
fk = open( keyfile, 'w')
fk.write(json.dumps(key))
fk.close()
return key
if action == "decrypt":
key = sys.argv[3]
decrypt(file, key)
else:
encrypt(file)
網站在google, yahoo搜尋不到的解決方式
最近弄了幾個新網站,結果在google跟yahoo上搜尋沒在最前面,yahoo甚至找不到,只好手動提醒他們加入了
Google
到google的回報系統輸入你網站的網址及可
Yahoo!
由於yahoo搜尋現在都靠微軟的bing了,所以現在網路上一堆錯誤的回報網址,進去都是404,根據yahoo說明中心的說明,正確的回報系統在http://www.bing.com/toolbox/submit-site-url別跑錯了~~~
不過回報之後也沒有保證多久能找的到...慢慢等吧 XD
到google的回報系統輸入你網站的網址及可
Yahoo!
由於yahoo搜尋現在都靠微軟的bing了,所以現在網路上一堆錯誤的回報網址,進去都是404,根據yahoo說明中心的說明,正確的回報系統在http://www.bing.com/toolbox/submit-site-url別跑錯了~~~
不過回報之後也沒有保證多久能找的到...慢慢等吧 XD
2013年11月1日 星期五
jQuery File Tree 只顯示 資料夾 與中文亂碼修正
jQuery File Tree是一套滿好用的檔案樹套件,可以顯示遠端Server的檔案路徑。不過他目前只能選擇檔案,不能只選資料夾,而且若是中文檔名,取得的路徑還會是亂碼,以下做一點小修改,讓他支援中文檔名以及可以選取資料夾。
首先,針對他的connector動手腳,以下是php的範例,不過各版本其實是相同原理
jqueryFileTree.php
jQueryFileTree.js
先把所有escape換成encodeURIComponent,然後再把點擊資料夾的部分回傳資料以及加入CSS方便辨識
首先,針對他的connector動手腳,以下是php的範例,不過各版本其實是相同原理
jqueryFileTree.php
foreach( $files as $file ) {
if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) {
$ext = preg_replace('/^.*\./', '', $file);
echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
}
}
接下來修改
jQueryFileTree.js
先把所有escape換成encodeURIComponent,然後再把點擊資料夾的部分回傳資料以及加入CSS方便辨識
if(jQuery) (function($){
$.extend($.fn, {
fileTree: function(o, h) {
// Defaults
if( !o ) var o = {};
if( o.root == undefined ) o.root = '/';
if( o.script == undefined ) o.script = 'jqueryFileTree';
if( o.folderEvent == undefined ) o.folderEvent = 'click';
if( o.expandSpeed == undefined ) o.expandSpeed= 500;
if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
if( o.expandEasing == undefined ) o.expandEasing = null;
if( o.collapseEasing == undefined ) o.collapseEasing = null;
if( o.multiFolder == undefined ) o.multiFolder = true;
if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';
$(this).each( function() {
function showTree(c, t) {
$(c).addClass('wait');
$(".jqueryFileTree.start").remove();
$.post(o.script, { dir: t }, function(data) {
$(c).find('.start').html('');
$(c).removeClass('wait').append(data);
if( o.root == t ) $(c).find('UL:hidden').show(); else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
bindTree(c);
});
}
function bindTree(t) {
$(t).find('LI A').bind(o.folderEvent, function() {
if( $(this).parent().hasClass('directory') ) {
if( $(this).parent().hasClass('collapsed') ) {
// Expand
if( !o.multiFolder ) {
$(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
$(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
}
$(this).parent().find('UL').remove(); // cleanup
showTree( $(this).parent(), encodeURIComponent($(this).attr('rel').match( /.*\// )) );
$(this).parent().removeClass('collapsed').addClass('expanded');
$("a").removeClass("hover"); // 移除所有hover class
$(this).addClass('hover'); // 現有資料夾加入hover class
h($(this).attr('rel')); // 回傳路境
} else {
// Collapse
$(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
$(this).parent().removeClass('expanded').addClass('collapsed');
}
} else {
h($(this).attr('rel'));
}
return false;
});
// Prevent A from triggering the # on non-click events
if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; });
}
// Loading message
$(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>');
// Get the initial file list
showTree( $(this), encodeURIComponent(o.root) );
});
}
});
})(jQuery);
標籤:
javascript,
jikker知識+
訂閱:
文章 (Atom)