七夕节马上要到了,前端工程师,后端工程师,算法工程师都怎么哄女朋友开心?
这篇文章的前提是,你得有个女朋友,没有就先收藏着吧!
七夕节的来源是梁山伯与祝英台的美丽传说,化成了一对蝴蝶~ 美丽的神话!虽然现在一般是过214的情人节了,但是不得不说,古老的传统的文化遗产,还是要继承啊~
在互联网公司中,主要的程序员品种包括:前端工程师,后端工程师,算法工程师。
对于具体的职业职能划分还不是很清楚的,我们简单的介绍一下不同程序员岗位的职责:
前端程序员:绘制UI界面,与设计和产品经理进行需求的对接,绘制特定的前端界面推向用户
后端程序员:接收前端json字符串,与数据库对接,将json推向前端进行显示
算法工程师:进行特定的规则映射,优化函数的算法模型,改进提高映射准确率。
七夕节到了,怎么结合自身的的专业技能,哄女朋友开心呢?
前端工程师:我先来,画个动态的晚霞页面!
1.定义样式风格:
.star {
width: 2px;
height: 2px;
background: #f7f7b6;
position: absolute;
left: 0;
top: 0;
backface-visibility: hidden;
}
2.定义动画特性
@keyframes rotate {
0% {
transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);
}
100% {
transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg);
}
}
3.定义星空样式数据
export default {
data() {
return {
starsCount: 800, //星星数量
distance: 900, //间距
}
}
}
4.定义星星运行速度与规则:
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})`;
});
前端预览效果图:
后端工程师看后,先点了点头,然后表示不服,画页面太肤浅了,我开发一个接口,定时在女朋友生日的时候发送祝福邮件吧!
1.导入pom.xml 文件
<!-- mail邮件服务启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2.application-dev.properties内部增加配置链接
#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
## 这里填邮箱的授权码
spring.mail.password=#yourpassword#
3.配置邮件发送工具类 MailUtils.java
@Component
public class MailUtils {
@Autowired
private JavaMailSenderImpl mailSender;
@Value("${spring.mail.username}")
private String mailfrom;
// 发送简单邮件
public void sendSimpleEmail(String mailto, String title, String content) {
// 定制邮件发送内容
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(mailfrom);
message.setTo(mailto);
message.setSubject(title);
message.setText(content);
// 发送邮件
mailSender.send(message);
}
}
4.测试使用定时注解进行注释
@Component
class DemoApplicationTests {
@Autowired
private MailUtils mailUtils;
/**
* 定时邮件发送任务,每月1日中午12点整发送邮件
*/
@Scheduled(cron = "0 0 12 1 * ?")
void sendmail(){
// 定制邮件内容
StringBuffer content = new StringBuffer();
content.append("HelloWorld");
//分别是接收者邮箱,标题,内容
mailUtils.sendSimpleEmail("123456789@qq.com","自定义标题",content.toString());
}
}
@scheduled注解 使用方法: cron:秒,分,时,天,月,年,* 号表示 所有的时间均匹配
5.工程进行打包,部署在服务器的容器中运行即可。
算法工程师,又开发接口,又画页面,我就训练一个自动写诗机器人把!
1.定义神经网络RNN结构
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_state
2.定义模型训练方法:
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.数据集预处理
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:
pass
poetry.txt文件中存放这唐诗的数据集,用来训练模型
4.测试一下训练后的模型效果:
藏头诗创作:“七夕快乐”
模型运算的结果
哈哈哈,各种节日都是程序员的表(zhuang)演(bi) 时间,不过这些都是锦上添花,只有实实在在,真心,才会天长地久啊~
提前祝各位情侣七夕节快乐!
作者:千与编程
来源:juejin.cn/post/6995491512716918814