今天看到个有趣的网站,给大家分享一下。
该网站的功能很神奇,可以实现编程语言的转化。感觉在一些场景之下还是有点作用的,比如你原来跟我一样是做Java的,因为工作需要突然转Go。这个时候用你Java的经验 + 这个工具,或许可以起到一定的帮助作用。
工具的使用也很简单,只需要在左侧黏贴你想转换的原始代码,然后点击
CONVERT CODE
,右侧输入框就会转换成目标代码:
像下面这样更加复杂的代码转换也是不在话下:
const fs = require('fs');
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
const fileName = 'contacts.csv';
const uploadFile = () => {
fs.readFile(fileName, (err, data) => {
if (err) throw err;
const params = {
Bucket: 'testBucket', // pass your bucket name
Key: 'contacts.csv', // file will be saved as testBucket/contacts.csv
Body: JSON.stringify(data, null, 2)
s3.upload(params, function(s3Err, data) {
if (s3Err) throw s3Err
uploadFile();
可以看到其中还包含了aws的内容,居然也能顺利的转成Java
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
public class UploadObject {
public static void main(String[] args) throws IOException {
String clientRegion = "*** Client region ***";
String bucketName = "*** Bucket name ***";
String stringObjKeyName = "*** String object key name ***";
String fileObjKeyName = "*** File object key name ***";
String fileName = "*** Path to file to upload ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(clientRegion)
.withCredentials(new ProfileCredentialsProvider())
.build();
// Upload a text string as a new object.
s3Client.putObject(bucketName, stringObjKeyName, "Uploaded String Object");
// Upload a file as a new object with ContentType and title specified.
PutObjectRequest request = new PutObjectRequest(bucketName, fileObjKeyName, new File(fileName));
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("plain/text");
metadata.addUserMetadata("x-amz-meta-title", "someTitle");
request.setMetadata(metadata);
s3Client.putObject(request);
catch(AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
catch(SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
根据官方说明,该工具也是通过AI实现的,是不是很神奇呢?这个到底是怎么实现的呢?有了解的小伙伴留言区一起探讨下吧!
欢迎关注我的公众号:程序猿DD。前沿技术早知道,弯道超车有希望!积累超车资本,从关注DD开始!
该网站的功能很神奇,可以实现编程语言的转化。感觉在一些场景之下还是有点作用的,比如你原来跟我一样是做Java的,因为工作需要突然转Go。这个时候用你Java的经验 + 这个工具,或许可以起到一定的帮助作用。根据官方说明,该工具也是通过AI实现的,是不是很神奇呢?这个到底是怎么实现的呢?欢迎关注我的公众号:程序猿DD。工具的使用也很简单,只需要在左侧黏贴你想转换的原始代码,然后点击。可以看到其中还包含了aws的内容,居然也能顺利的转成Java。今天看到个有趣的网站,给大家分享一下。
public class IO {
//指定编码格式的路径读取
public static char[] getTheFile(String path,String format) {
char[] article = null;
写了一段时间,一开始的思路是:每段每段的读取,把def、class、for等等的有缩进的划分为段落处理,代码写着写着,只能写出来print和赋值语句的转换功能。原因是这两个是单行就可完成的,但是无法得知多行程序里是否包含其他多行,如果硬着头皮写,这会造成反复的判断和代码量几十倍的增加。仔细思考了一番,想出来两种思路:
单行单行判断,遇到有缩进要求的,创建一个池添加进去,以作记录。比较麻烦,但是代码量应该不大。
一段一段判断,但是是从里向外判断,即找到缩进最大的进行转义,这就省去了考虑
我相信,读者朋友们可能有跟我经历类似的——
非科班出身热爱编程,从谭浩强的《C语言基础》到各种技术的入门视频书籍资源辗转腾挪,最终发现了Python 这样一个可以快速拥抱编程世界的语言。
搞Python已经3年了,web、数据分析处理(音频/视频/文本/)、GUI(tkinter/wxpython/pyqt/勉强算上webview),回过头看Python对于我这种情况的人,所带来的好处,总结为以下几点:
快速入门:即便是完全没接触过Python,静下心来,也能大致看出入门级的示例
快速实现想法:简单灵
try {
// Set up the audio format
AudioFormat format = new AudioFormat(800, 8, 1, true, true);
// Get a line to the speakers
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine speakers = (SourceDataLine) AudioSystem.getLine(info);
speakers.open(format);
speakers.start();
// Get the text to speak
String text = "你好,我是CSDN开发的AI语言模型。";
// Create a synthesizer
SpeechSynthesizer synthesizer = Central.createSynthesizer(null);
synthesizer.allocate();
// Set the synthesizer properties
synthesizer.getSynthesizerProperties().setVoice("cmn-Hans-CN");
synthesizer.getSynthesizerProperties().setSpeakingRate(150);
// Synthesize the text to an audio stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
synthesizer.synthesize(text, out);
out.close();
// Play the audio stream through the speakers
byte[] audio = out.toByteArray();
speakers.write(audio, , audio.length);
speakers.drain();
speakers.close();
// Deallocate the synthesizer
synthesizer.deallocate();
} catch (Exception e) {
e.printStackTrace();