Notifications
Clear all

วิธีการโพสต์ Programming Code ให้มี Syntax Highlight

5 ข้อความ
3 Users
0 Likes
11.5 K Views
The Neural Engineer
(@neural-engineer)
Honorable Member Admin
เข้าร่วมเมื่อ: 7 years ago
ข้อความ: 412
Topic starter  

กระทู้นี้เพื่อนๆ สามารถทดลองโพสต์ programming code ได้ โดยให้ใส่ tag ชื่อภาษาครอบโค้ดของเรา ดังตัวอย่างครับ

ซึ่งจะปรากฏเป็น syntax ที่ highlight สวยงามดังนี้

 
for i in range(5): 
  print(3)</pre>
<p>

ในบางครั้งโค้ดจะติดแท็ก html มาด้วยเวลาเว้นบรรทัด (เป็นข้อจำกัดของ webboard ที่บางครั้งก็ตรวจเจอและแก้ไขให้โดยอัตโนมัติ บางครั้งก็ไม่)  เช่น 

 
for i in range(5): 
  print(3)</p>
<p>

วิธีลบ tag html พวก <p></p> ออกให้  ครอบด้วย <pre></pre> ก่อนเขียนโค้ด หรือสามารถ hi-light ด้วย code แท็บตามรูปก็ได้ครับ

เราก็จะได้โค้ดที่ต้องการโดยไม่มี tag html ครับ
 
for i in range(5): 
  print(3)

This topic was modified 7 years ago 7 times by The Neural Engineer
This topic was modified 6 years ago 5 times by The Neural Engineer

   
อ้างอิง
The Neural Engineer
(@neural-engineer)
Honorable Member Admin
เข้าร่วมเมื่อ: 7 years ago
ข้อความ: 412
Topic starter  

ตัวอย่างโค้ดของ Keras ที่นำมาจาก GitHub :  https://github.com/keras-team/keras/blob/master/examples/imdb_lstm.py สามารถนำมาแปะอย่างสวยงามได้ดังนี้ครับ 

'''Trains an LSTM model on the IMDB sentiment classification task.

The dataset is actually too small for LSTM to be of any advantage
compared to simpler, much faster methods such as TF-IDF + LogReg.

# Notes

- RNNs are tricky. Choice of batch size is important,
choice of loss and optimizer is critical, etc.
Some configurations won't converge.

- LSTM loss decrease patterns during training can be quite different
from what you see with CNNs/MLPs/etc.
'''
from __future__ import print_function

from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Embedding
from keras.layers import LSTM
from keras.datasets import imdb

max_features = 20000
# cut texts after this number of words (among top max_features most common words)
maxlen = 80
batch_size = 32

print('Loading data...')
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')

print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
print('x_train shape:', x_train.shape)
print('x_test shape:', x_test.shape)

print('Build model...')
model = Sequential()
model.add(Embedding(max_features, 128))
model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation='sigmoid'))

# try using different optimizers and different optimizer configs
model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

print('Train...')
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=15,
          validation_data=(x_test, y_test))
score, acc = model.evaluate(x_test, y_test,
                            batch_size=batch_size)
print('Test score:', score)
print('Test accuracy:', acc)
This post was modified 7 years ago 7 times by The Neural Engineer
This post was modified 6 years ago by The Neural Engineer

   
ตอบกลับอ้างอิง
wpforo gvector
(@wpforo)
New Member Admin
เข้าร่วมเมื่อ: 7 years ago
ข้อความ: 2
 
	foreach($default as $k =&gt; $v){
		if(!empty($v) &amp;&amp; is_array($v)){
		}
	}

   
ตอบกลับอ้างอิง
wpforo gvector
(@wpforo)
New Member Admin
เข้าร่วมเมื่อ: 7 years ago
ข้อความ: 2
 
&lt;select name="syntaxhighlighter_settings[theme]" id="syntaxhighlighter-theme" class="postform"&gt;
&lt;?php
               foreach ( $this-&gt;themes as $theme =&gt; $name ) {
                  echo '             &lt;option value="' . esc_attr( $theme ) . '"' . selected( $this-&gt;settings['theme'], $theme, false ) . '&gt;' . esc_html( $name ) . "&amp;nbsp;&lt;/option&gt;\n";
               }
?&gt;
            &lt;/select&gt;

   
ตอบกลับอ้างอิง
nameless
(@nameless)
Member Moderator
เข้าร่วมเมื่อ: 7 years ago
ข้อความ: 7
 
for i in range(6):
    if i &gt; 3 &amp;&amp; i &lt;=5:
        print(i)
This post was modified 6 years ago by nameless
This post was modified 2 years ago by The Neural Engineer

   
ตอบกลับอ้างอิง
Share: