工作學習中遇到過哪些讓你覺得眼前一亮的代碼,可以分享出來讓大家學習,無論代碼簡單還是複雜,也不限語言,只要你覺得寫法很巧妙,或者有新意,或者原來還可以這樣,或者你從中學到了什麼,都可以分享!(不一定要非常有技巧,看上去很美的簡短代碼都可以,並非只要酷炫罕見的代碼)
回複內容:
"★★★★★☆☆☆☆☆".substring(5 - rating, 10 - rating);
echo 15 > /sys/class/acpi_backlight=vendor/acpi_osi=Linux/brightness
_='_=%r;print _%%_';print _%_
相比代碼其實我更喜歡看代碼中的那些注釋,給你感受下前端的世界:
關於正確地使用document.write
/* * 在IE下,document.write執行的順序會錯亂 * 假設使用document.write寫入script標籤,順序為a1->a2->a3,並在a3中定義了變數hello * 則同樣使用document.write寫入b1指令碼,無法讀取hello * 必須使用至少對應的3層嵌套,形成b1->b2->b3順序的document.write,在b3中讀取hello變數才可行 * 因此,使用checkStatus函數自調用遞迴5層來讀取全域的FOO變數 * * 如果在5層嵌套沒到的情況下發現全域FOO變數已經被賦值,則可以提前退出 */
素數正則:
^1?$|^(11+)\1+$
[].forEach.call($$("*"),function(a){ a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
void memcpy( char* to, char* from, size_t count )
{
size_t n = (count+7)/8;
switch( count%8 )
{
case 0: do{ *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
}while(--n>0);
}
}
@裝配腦袋 當年寫過一個42個字元的python代碼,列印代碼自身。神技。 趣味程式:列印自己代碼的程式
segmentation fault
Python 一行列印小九九