android编码技巧

by Kristóf Litavecz

通过克里斯托夫·利塔维奇(KristófLitavecz)

我如何使用编码技巧使航空公司取代丢失的婴儿车 (How I used my coding skills to make an airline replace my lost baby stroller)

Last summer my wife and our two children flew from Hungary to California to visit friends. Among other complications, our airline lost our little one’s stroller on the way.

去年夏天,我的妻子和我们的两个孩子从匈牙利飞往加利福尼亚,探望朋友。 除其他并发症外,我们的航空公司在途中丢失了我们的小推车。

After numerous unsuccessful attempts to contact the airline through emails, tweets, friendly phone calls — and then angry phone calls — to cover our costs, I had enough. I decided to take things to the next level.

在多次尝试通过电子邮件,推文,友好的电话(然后是愤怒的电话)来联系航空公司以支付我们的费用而失败之后,我受够了。 我决定将事情提高到一个新的水平。

So I built a Twitter Bot that replied to every tweet from the airline’s account to remind them of our case, which had been pending for over three months at that point.

因此,我建立了一个Twitter Bot ,回复了该航空公司帐户中的每条推文,以提醒他们我们的案件,当时该案件已经待了三个多月了。

By no means did I do this for revenge or extort money. All I wanted them to do was treat us fairly and cover the costs of a child’s lost stroller.

我决不是为了报仇或勒索钱财。 我想要他们做的就是公平地对待我们,并支付孩子失散的童车的费用。

I had been learning to program for about a year now, and making heavy use of freeCodeCamp community for support and inspiration.

我已经学习编程大约一年了,并且大量使用freeCodeCamp社区来获得支持和启发。

So, here is what I did:

所以,这就是我所做的:

  1. I created a new Cloud9 dev environment

    我创建了一个新的Cloud9开发环境

  2. I created a Twitter account

    我创建了一个Twitter帐户

  3. I created a simple Twitter Bot using Node.js我使用Node.js创建了一个简单的Twitter Bot
  4. I configured it so that it would randomly tweet one of ten reminder messages every hour

    我配置好了 这样它就会每小时随机发送10条提醒消息之一

  5. Then I launched the bot然后我启动了机器人

One and a half weeks later, the money landed in my account, and I bought a new stroller.

一个半星期后,这笔钱降到了我的帐户中,我买了一辆新的婴儿车。

I put all of my code on this GitHub repository in case you ever find yourself in a similar situation. And here’s how I did all this.

我将所有代码都放在此GitHub存储库中,以防您遇到类似情况。 这就是我所做的所有事情。

步骤1:创建新的Cloud9 IDE环境: (Step 1: Create a new Cloud9 IDE environment:)

Head to Cloud9 and create a new workspace.

前往Cloud9并创建一个新的工作区。

If you would like to replicate my bot just clone my repository by entering the following line in your terminal:

如果您想复制我的机器人,只需在终端中输入以下行即可克隆我的存储库:

git clone https://github.com/krizsoo/twitterbot

git clone https://github.com/krizsoo/twitterbot

第2步:创建一个Twitter帐户和一个Twitter应用 (Step 2: Create a Twitter account and a Twitter App)

If you don’t have a Twitter account yet, go ahead and create one. Once you are registered, you can create a new application, which will allow you to access Twitter’s API and programmatically generate tweets.

如果您还没有Twitter帐户, 请继续创建一个 。 注册后,您可以创建一个新的应用程序,该应用程序将允许您访问Twitter的API并以编程方式生成推文。

As soon as my app was set up I retrieved four security keys that are necessary to access the API:

设置我的应用程序后,我立即检索了访问API所需的四个安全密钥:

  • Consumer Key (API Key)使用者密钥(API密钥)
  • Consumer Secret (API Secret)消费者秘密(API秘密)
  • Access Token访问令牌
  • Access Token Secret访问令牌机密

All of the above keys should be added to the config.js file the following way:

以上所有键均应通过以下方式添加到config.js文件中:

步骤3:配置Twitter机器人 (Step 3: Configure the Twitter bot)

I had to do some initial configuration to ensure that the bot will do what it is supposed to do.

我必须进行一些初始配置,以确保该机器人能够执行应做的工作。

1.安装Node.js依赖项 (1. Install Node.js dependencies)

npm install --save twitter

2.设置搜索查询 (2. Set up the search query)

This was an important step to define a search query to which the Bot tweeted back to. I went to the “app.js” file and updated the search parameters.

这是定义Bot发回信息的搜索查询的重要步骤。 我转到“ app.js”文件并更新了搜索参数。

  • q represents the keywords.

    q代表关键字。

  • count represents the number of tweets the query should return.

    count表示查询应返回的推文数量。

  • result_type represents the sorting logic, in our case, it shows the most recent one first.

    result_type表示排序逻辑,在我们的例子中,它显示最近的一个。

  • lang stands for language (for example, English).

    lang代表语言(例如,英语)。

The below config would automatically reply to the most recent tweet that contains “@freecodecamp”

以下配置将自动回复包含“ @freecodecamp”的最新推文

// Set up your search parametersvar params = {  q: '@freecodecamp',  count: 1,  result_type: 'recent',  lang: 'en'}

步骤#4:配置推文 (Step #4: Configure the tweets)

Since the Bot was running hourly, I did not want it to tweet the same message over and over again. Therefore I created an array of ten or so tweets and the Bot randomly selected one every time.

由于Bot每小时运行一次,因此我不希望它一遍又一遍地发布相同的消息。 因此,我创建了一个由十个左右的鸣叫组成的数组,而Bot每次都随机选择一个。

//set up array of tweets that can be randomly selectedvar TWEETS_TO_REPLY = [    "This is the first version of my tweets",    "This is the second",    "Tweet 3 where is my stroller?"];

EDIT: As Jonny Asmar pointed out below, make sure that you do not mention people in your responses as that is against Twitter’s TOS.

编辑:正如乔尼·阿斯玛(Jonny Asmar)在下面指出的那样,请确保您在回复中不要提及其他人,因为这与Twitter的TOS背道而驰。

步骤#5:配置鸣叫频率 (Step #5: Configure the tweet frequency)

Lastly, I set up the Bot to run hourly.

最后,我将Bot设置为每小时运行一次。

First I created a variable that represents one hour in milliseconds:

首先,我创建了一个以毫秒为单位表示一个小时的变量:

//set up tweet time intervalvar INTERVAL = 1*60*60*1000;

Then I made sure that I launched the Bot accordingly:

然后,确保相应地启动了Bot:

// Start bot and timerBotStart();setInterval(BotStart, INTERVAL);

步骤6:启动漫游器 (Step 6: Launch the bot)

As soon as it was all configured I launched the Bot and waited patiently.

配置完成后,我启动了Bot,并耐心等待。

npm run serve

我从这一切中学到的 (What I learned from all this)

To my surprise, about 24 hours later, a customer service representative finally responded to me. They informed me that they had initiated the money transfer.

令我惊讶的是,大约24小时后,一位客户服务代表终于对我做出了回应。 他们告诉我他们已经开始汇款了。

A year ago I would not have been able to do any of this. Even if this is a small thing, this triumph mattered to me a lot.

一年前,我将无能为力。 即使这是一件小事,这种胜利对我也很重要。

This story is about how I learned to code in 2017, and how I found some additional inspiration this side project. I did not start a new career as a developer (yet), but there are many other ways you can make use of your coding skills in your day to day life. Some even argue that coding has become the 4th literacy.

这个故事是关于我如何在2017年学习编码的,以及如何从这个附带项目中获得其他启发的。 我还没有以开发人员的身份开始新的职业,但是在日常生活中还有很多其他方法可以利用您的编码技能。 甚至有人认为编码已经成为第四种读写能力 。

Hopefully for all of you who are starting to learn how to code, you will find a little inspiration in my story, too. On all those late nights when you’re struggling with a coding challenge, keep in mind that whether or not you will start a new career as a developer, understanding the language of the computers will pay off one day.

希望对所有开始学习编码的人,我的故事也能有所启发。 在所有深夜中,当您在编码挑战中苦苦挣扎时,请记住,无论您是否将开始新的开发工作,了解计算机的语言都将有一天获得回报。

致谢 (Acknowledgments)

This post could not have happened without the freeCodeCamp community, nor the CS50 team. I am grateful for their support.

没有freeCodeCamp社区或CS50团队,就不会发生这篇文章。 我感谢他们的支持。

Also, I’m grateful to Brandon Morelli and Scott Spence for writing these detailed guides Twitter Bot guides:

另外,我也感谢Brandon Morelli和Scott Spence撰写了以下详细指南Twitter Bot指南:

Build a simple Twitter Bot with Node.js in just 38 lines of codeTutorials don’t have to be complicated. Together we’ll build a simple Twitter favorite bot with Node.js in just 38…codeburst.ioWhy you should have your own Twitter bot, and how to build one in less than 30 minutesUPDATE 20171102: Since this story was originally posted back in January 2017 there have been a few things that have…medium.freecodecamp.org

仅需38行代码,即可使用Node.js构建一个简单的Twitter Bot。 教程不必 复杂。 我们一起将用38.使用Node.js构建一个简单的Twitter最喜欢的机器人…… codeburst.io 为什么要拥有自己的Twitter bot,以及如何在不到30分钟的时间内构建一个Twitter bot 更新20171102:因为这个故事最初被发布回来在2017年1月,发生了一些事情…… medium.freecodecamp.org

翻译自: https://www.freecodecamp.org/news/how-i-used-my-programming-skills-to-buy-a-stroller-2778cb85e8b2/

android编码技巧

android编码技巧_我如何使用编码技巧使航空公司取代丢失的婴儿车相关推荐

  1. python 字符编码处理_浅析Python 字符编码与文件处理

    Python字符编码 目前计算机内存的字符编码都是Unicode,目前国内的windows操作系统采用的是gbk. python2默认的字符编码方式是ASCII python3默认的字符编码方式是Un ...

  2. 国家职业标准职业编码查询_为什么我学会编码而不是从事金融职业

    国家职业标准职业编码查询 by Amir Ghafouri 通过阿米尔·加富里(Amir Ghafouri) 为什么我学会编码而不是从事金融职业 (Why I learned to code inst ...

  3. java url gbk编码转换_如何在一个utf-8编码的HTML中 在javascript中url跳转时把url中的汉字改为GBK编码...

    展开全部 html文件中私用32313133353236313431303231363533e78988e69d8331333337623465JavaScript将url的汉子转为为GBK编码,主要 ...

  4. pep8 python 编码规范_实用的python编码规范

    编码规范在程序开发中是一项很重要要求,良好的编码规范对程序的可读性.代码的可维护性都有很大的提高,从而提高开发效率.下面总结了python中一些实用的开发规范,供大家借鉴和参考. 1.每行不超过80个 ...

  5. mysql修改数据库编码级_修改mysql数据库编码

    修改my.ini文件 加上 default-character-set=gb2312 设定数据库字符集 alter database da_name default character set 'ch ...

  6. excel中的常用技巧_在Excel中控制技巧

    excel中的常用技巧 Last week I listed a few tricks with the Shift key in Excel, and in the comments, Jon Pe ...

  7. github高级搜索技巧_百度搜索引擎高级使用技巧

    通过搜索引擎对网络信息资源进行查找是获取网络信息资源的主要方式.搜索引擎是用来对网络信息资源管理和检索的一系列软件,实际上也是一些网页.查找信息资源时,在其中的搜索框中输入查找的关键词.短语,或者是其 ...

  8. pcb排版技巧_借鉴大师的排版技巧

    pcb排版技巧 I started "modernizing" the look of this blog last weekend. It's a mess^H^H^H^Hwor ...

  9. 数位板使用技巧_保护您的眼睛技巧,以帮助防止数位眼疲劳

    数位板使用技巧 重点 (Top highlight) If you happen to have a job that requires you to stare at a computer scre ...

最新文章

  1. 解题报告(二)C、(darkBZOJ 3771)Triple(生成函数 + FFT + 容斥原理)(3)
  2. DF-SLAM:一种深度特征提取方法
  3. bzoj 4753: [Jsoi2016]最佳团体
  4. linux可读可写为啥设置421
  5. 【android-tips】android xml布局总结篇
  6. C#为什么支持协变的参数只能用于方法的返回值?支持逆变的参数只能用于方法参数?...
  7. 先装VS 在装IIS遇到的问题
  8. cni k8s 插件安装_K8S 之 Flannel网络插件安装
  9. USE PDFCREATE TO CREATE A PDF FILE
  10. js获取用户当前所在城市(ip)
  11. 如何在linux下创建一个可运行shell脚本?
  12. 「干货」不逼自己一下不知道自己多牛逼[python篇]
  13. ActiveRecord 模式杂谈
  14. Permutations II
  15. java 并发_Java并发编程中断机制 so easy
  16. fasterrcnn论文_【每周CV论文推荐】 深度学习人脸检测入门必读文章
  17. 这样的AI技术实战方式,大boss都看不下去了!
  18. python struct pack_Python(12)教程11.标准库简介——第二部分
  19. 05Nginx动静分离、 URLRewrite
  20. SUCCEEDED 和 FAILED的作用和用法

热门文章

  1. 微软发布的 免费文件恢复工具
  2. 鲸探发布点评:9月1日发售《新石器黄玉猪龙形珮》数字藏品
  3. ItextSharp 坐标系转换
  4. PHP steam第三方登录,网站支持第三方STEAM登录了
  5. iOS-事件响应链、单例模式、工厂模式、观察者模式
  6. threejs camera.lookAt()的作用
  7. narwal机器人_省时省心才见真章!Narwal云鲸J1智能扫拖机器人国内上市
  8. 凭证 金蝶_5分钟学会金蝶软件凭证录入!
  9. html5导航栏向应折叠,超实用!网站导航栏设计形式总结
  10. 【python逻辑算法题】一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法