有沒有讓你眼前一亮的代碼?

來源:互聯網
上載者:User
工作學習中遇到過哪些讓你覺得眼前一亮的代碼,可以分享出來讓大家學習,無論代碼簡單還是複雜,也不限語言,只要你覺得寫法很巧妙,或者有新意,或者原來還可以這樣,或者你從中學到了什麼,都可以分享!(不一定要非常有技巧,看上去很美的簡短代碼都可以,並非只要酷炫罕見的代碼)

回複內容:

"★★★★★☆☆☆☆☆".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 一行列印小九九
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.