七夕節(jié),程序員們都怎么哄女朋友開心?
大家好,馬上就七夕節(jié)了,七夕節(jié)是牛郎織女鵲橋相會(huì)的相會(huì)的日子。
這篇文章的前提是,你得有個(gè)女朋友,沒有就先收藏著吧
!
一、七夕節(jié)的由來
七夕節(jié)的來源是梁山伯與祝英臺的美麗傳說,化成了一對蝴蝶~

美麗的神話!雖然現(xiàn)在一般是過214的情人節(jié)了,但是不得不說,古老的傳統(tǒng)的文化遺產(chǎn),還是要繼承啊~
在互聯(lián)網(wǎng)公司中,主要的程序員品種包括:前端工程師,后端工程師,算法工程師。(客戶端表示有被冒犯到
)
二、程序員的分類
對于具體的職業(yè)職能劃分還不是很清楚的,我們簡單的介紹一下不同程序員崗位的職責(zé):
前端程序員:繪制UI界面,與設(shè)計(jì)和產(chǎn)品經(jīng)理進(jìn)行需求的對接,繪制特定的前端界面推向用戶
后端程序員:接收前端json字符串,與數(shù)據(jù)庫對接,將json推向前端進(jìn)行顯示
算法工程師:進(jìn)行特定的規(guī)則映射,優(yōu)化函數(shù)的算法模型,改進(jìn)提高映射準(zhǔn)確率。
七夕節(jié)到了,怎么結(jié)合自身的的專業(yè)技能,哄女朋友開心呢?
三、是時(shí)候表演真正的技術(shù)了!
前端工程師:我先來,畫個(gè)動(dòng)態(tài)的晚霞頁面!
1.定義樣式風(fēng)格:
.star {
width: 2px;
height: 2px;
background: #f7f7b6;
position: absolute;
left: 0;
top: 0;
backface-visibility: hidden;
}2.定義動(dòng)畫特性:
@keyframes rotate {
0% {
transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);
}
100% {
transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg);
}
}3.定義星空樣式數(shù)據(jù)
export default {
data() {
return {
starsCount: 800, //星星數(shù)量
distance: 900, //間距
}
}
}4.定義星星運(yùn)行速度與規(guī)則:
starNodes.forEach((item) => {
let speed = 0.2 + Math.random() * 1;
let thisDistance = this.distance + Math.random() * 300;
item.style.transformOrigin = `0 0 ${thisDistance}px`;
item.style.transform =
`
translate3d(0,0,-${thisDistance}px)
rotateY(${Math.random() * 360}deg)
rotateX(${Math.random() * -50}deg)
scale(${speed},${speed})`;
});前端預(yù)覽效果圖:

后端工程師看后,先點(diǎn)了點(diǎn)頭,然后表示不服
,畫頁面有點(diǎn)膚淺了,我開發(fā)一個(gè)接口,定時(shí)在女朋友生日的時(shí)候發(fā)送祝福郵件吧!
1.導(dǎo)入pom.xml 文件
<!-- mail郵件服務(wù)啟動(dòng)器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>2.application-dev.properties內(nèi)部增加配置鏈接
#QQ\u90AE\u7BB1\u90AE\u4EF6\u53D1\u9001\u670D\u52A1\u914D\u7F6E
spring.mail.host=smtp.qq.com
spring.mail.port=587
## qq郵箱
spring.mail.username=#yourname#@qq.com
## 這里填郵箱的授權(quán)碼
spring.mail.password=#yourpassword#3.配置郵件發(fā)送工具類
MailUtils.java
@Component
public class MailUtils {
@Autowired
private JavaMailSenderImpl mailSender;
@Value("${spring.mail.username}")
private String mailfrom;
// 發(fā)送簡單郵件
public void sendSimpleEmail(String mailto, String title, String content) {
// 定制郵件發(fā)送內(nèi)容
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(mailfrom);
message.setTo(mailto);
message.setSubject(title);
message.setText(content);
// 發(fā)送郵件
mailSender.send(message);
}
}4.測試使用定時(shí)注解進(jìn)行注釋
@Component
class DemoApplicationTests {
@Autowired
private MailUtils mailUtils;
/**
* 定時(shí)郵件發(fā)送任務(wù),每月1日中午12點(diǎn)整發(fā)送郵件
*/
@Scheduled(cron = "0 0 12 1 * ?")
void sendmail(){
// 定制郵件內(nèi)容
StringBuffer content = new StringBuffer();
content.append("HelloWorld");
//分別是接收者郵箱,標(biāo)題,內(nèi)容
mailUtils.sendSimpleEmail("[email protected]","自定義標(biāo)題",content.toString());
}
}@scheduled注解 使用方法:cron:秒,分,時(shí),天,月,年,* 號表示 所有的時(shí)間均匹配
5. 工程進(jìn)行打包,部署在服務(wù)器的容器中運(yùn)行即可。
算法工程師,又開發(fā)接口,又畫頁面,我就訓(xùn)練一個(gè)自動(dòng)寫詩機(jī)器人把
!
1.定義神經(jīng)網(wǎng)絡(luò)RNN結(jié)構(gòu)
def neural_network(model = 'gru', rnn_size = 128, num_layers = 2):
cell = tf.contrib.rnn.BasicRNNCell(rnn_size, state_is_tuple = True)
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers, state_is_tuple = True)
initial_state = cell.zero_state(batch_size, tf.float32)
with tf.variable_scope('rnnlm'):
softmax_w = tf.get_variable("softmax_w", [rnn_size, len(words)])
softmax_b = tf.get_variable("softmax_b", [len(words)])
embedding = tf.get_variable("embedding", [len(words), rnn_size])
inputs = tf.nn.embedding_lookup(embedding, input_data)
outputs, last_state = tf.nn.dynamic_rnn(cell, inputs, initial_state = initial_state, scope = 'rnnlm')
output = tf.reshape(outputs, [-1, rnn_size])
logits = tf.matmul(output, softmax_w) + softmax_b
probs = tf.nn.softmax(logits)
return logits, last_state, probs, cell, initial_state2.定義模型訓(xùn)練方法
def train_neural_network():
logits, last_state, _, _, _ = neural_network()
targets = tf.reshape(output_targets, [-1])
loss = tf.contrib.legacy_seq2seq.sequence_loss_by_example([logits], [targets], \
[tf.ones_like(targets, dtype = tf.float32)], len(words))
cost = tf.reduce_mean(loss)
learning_rate = tf.Variable(0.0, trainable = False)
tvars = tf.trainable_variables()
grads, _ = tf.clip_by_global_norm(tf.gradients(cost, tvars), 5)
#optimizer = tf.train.GradientDescentOptimizer(learning_rate)
optimizer = tf.train.AdamOptimizer(learning_rate)
train_op = optimizer.apply_gradients(zip(grads, tvars))
Session_config = tf.ConfigProto(allow_soft_placement = True)
Session_config.gpu_options.allow_growth = True
trainds = DataSet(len(poetrys_vector))
with tf.Session(config = Session_config) as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver(tf.global_variables())
last_epoch = load_model(sess, saver, 'model/')
for epoch in range(last_epoch + 1, 100):
sess.run(tf.assign(learning_rate, 0.002 * (0.97 ** epoch)))
#sess.run(tf.assign(learning_rate, 0.01))
all_loss = 0.0
for batche in range(n_chunk):
x,y = trainds.next_batch(batch_size)
train_loss, _, _ = sess.run([cost, last_state, train_op], feed_dict={input_data: x, output_targets: y})
all_loss = all_loss + train_loss
if batche % 50 == 1:
print(epoch, batche, 0.002 * (0.97 ** epoch),train_loss)
saver.save(sess, 'model/poetry.module', global_step = epoch)
print (epoch,' Loss: ', all_loss * 1.0 / n_chunk)3.數(shù)據(jù)集預(yù)處理
poetry_file ='data/poetry.txt'
# 詩集
poetrys = []
with open(poetry_file, "r", encoding = 'utf-8') as f:
for line in f:
try:
#line = line.decode('UTF-8')
line = line.strip(u'\n')
title, content = line.strip(u' ').split(u':')
content = content.replace(u' ',u'')
if u'_' in content or u'(' in content or u'(' in content or u'《' in content or u'[' in content:
continue
if len(content) < 5 or len(content) > 79:
continue
content = u'[' + content + u']'
poetrys.append(content)
except Exception as e:
passpoetry.txt文件中存放這唐詩的數(shù)據(jù)集,用來訓(xùn)練模型
4.測試一下訓(xùn)練后的模型效果:
藏頭詩創(chuàng)作:“七夕快樂”
模型運(yùn)算的結(jié)果:

哈哈哈,各種節(jié)日都是程序員的表(zhuang)演(bi) 時(shí)間,不過這些都是錦上添花,只有實(shí)實(shí)在在,真心才會(huì)天長地久啊~
提前祝各位情侶七夕節(jié)快樂!
我是千與千尋,我們下期見~
end
往期精彩回顧 本站qq群851320808,加入微信群請掃碼:
