<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://blog.cgsphoto.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.cgsphoto.com/" rel="alternate" type="text/html" /><updated>2023-05-02T02:45:39+00:00</updated><id>https://blog.cgsphoto.com/feed.xml</id><title type="html">Carlos Saucedo</title><subtitle>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</subtitle><author><name>Carlos Saucedo</name></author><entry><title type="html">My Summer Internship Experience at CPS Products, Inc.</title><link href="https://blog.cgsphoto.com/career/hot%20take/cps-internship/" rel="alternate" type="text/html" title="My Summer Internship Experience at CPS Products, Inc." /><published>2019-08-25T00:00:00+00:00</published><updated>2019-08-25T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/career/hot%20take/cps-internship</id><content type="html" xml:base="https://blog.cgsphoto.com/career/hot%20take/cps-internship/">&lt;p&gt;This summer, I was an Engineering/Web Intern at CPS Products, Inc. Throughout my internship, I learned and refined lots of skills that I’ll be taking back and using in my career for years to come. The internship encompassed many different categories, including Web Development/WordPress Management, Software/Mobile App Development, Competitive Analysis and Research, and more. Over the course of the internship, I discovered TypeScript and added it to my skillset, and was able to refine and modernize my Apache Cordova experience with the newer Ionic framework, and was able to apply my skills to create a production-grade application that’s in the works of being deployed today. Additionally, with some of the knowledge I amassed throughout the internship, I was able to develop a standalone app that allows you to communicate with a BLE (Bluetooth Low Energy), device as a terminal. I also learned some helpful tools to optimize a WordPress Website, and even managed to increase PageSpeed Insights by more than 50 points on several sites.&lt;/p&gt;

&lt;h2 id=&quot;ionic-and-the-future-of-app-development&quot;&gt;Ionic and the Future of App Development&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/ionic-title.jpg&quot; alt=&quot;&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;Ionic has become my favorite tool for quickly creating desktop, web, and mobile apps beautifully and efficiently.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;One of the most impactful technologies I learned throughout the internship was Ionic, the new app development framework. I had some previous experience with Apache Cordova throughout my last internship, but overall, pure Cordova felt a bit dated and clunky. Ionic also has the advantage of having an incredible CLI, which allowed me to create projects, add components to my projects, generate resources such as splash screens and app icons, and compile and run on an emulator or connected device. Additionally, Ionic uses TypeScript and Angular by default, both of which I had to learn in order to create the apps I did this summer. Ionic is my favorite method to creating apps because it allows you to use web-heavy development to produce Native code on Android, iOS, and more. This summer I was assigned the task of developing an application that interfaces with BLE devices and sends and receives information that is gained from the sensors onboard the various Bluetooth Devices CPS Products uses.&lt;/p&gt;

&lt;p&gt;&lt;img width=&quot;300px&quot; src=&quot;/assets/images/bluetooth-terminal.jpg&quot; style=&quot;display: block; margin: 0 auto&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;My Bluetooth Terminal app running on Android.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;In order to learn the workflow of creating Ionic applications and handling BLE devices, I created a separate &lt;a href=&quot;https://github.com/LeoSaucedo/BluetoothTerminal&quot;&gt;BLE Terminal&lt;/a&gt; on my own time that actually became a really powerful tool I was able to use to test the subsequent apps I was developing. Though simple, the Terminal app proved to be extremely useful, and allows both sending and receiving of ASCII text to and from a BLE device with an optionally adjustable characteristic and service UUID sets. Learning how BLE works and applying it to my existing code was one of the most difficult tasks I had to undertake while on this internship, but once I was able to create a base class in TypeScript that performed all of the Bluetooth Functions, I was set.&lt;/p&gt;

&lt;p&gt;I ended up using Apache Cordova instead of the newer capacitor, because of my previous experience with Cordova and because of the increased plugin support. This ended up being just as efficient though, especially when creating an application with heavy third-party plugin requirements.&lt;/p&gt;

&lt;h2 id=&quot;making-wordpress-more-efficient&quot;&gt;Making WordPress More Efficient&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://cdn4.wpbeginner.com/wp-content/uploads/2019/02/wpspeedupguide.png&quot; style=&quot;display: block; margin: 0 auto&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;
&lt;a href=&quot;https://www.wpbeginner.com/wordpress-performance-speed/&quot;&gt;Source&lt;/a&gt;
&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;Another one of the useful takeaways from the internship was being able to learn some effective steps to make any WordPress site more efficient, through things such as &lt;a href=&quot;https://wordpress.org/plugins/wp-super-cache/&quot;&gt;WP Super Cache&lt;/a&gt;, &lt;a href=&quot;https://wordpress.org/plugins/autoptimize/&quot;&gt;Autoptimize&lt;/a&gt;, and using CDNs. Though I’d had previous experience managing WordPress websites, page speed wasn’t ever a priority, but I was able to really focus on it during this internship and was able to improve the &lt;a href=&quot;https://developers.google.com/speed/pagespeed/insights/&quot;&gt;PageSpeed Insight Score&lt;/a&gt; of all 3 CPS Products websites by 50 points or more.&lt;/p&gt;

&lt;p&gt;Another really important procedure I was able to develop was a workflow to automatically make uploaded images be resized, compressed, and served through a CDN instead of through the website itself. This dramatically increased website speeds and was by far the biggest improvement to the PageSpeed Insight Score. In the future, I hope to take this knowledge and be able to apply it to the improvement of many WordPress sites, especially those with high traffic that depend on low latency.&lt;/p&gt;

&lt;h2 id=&quot;competitive-analysis-for-research-and-development&quot;&gt;Competitive Analysis for Research and Development&lt;/h2&gt;

&lt;p&gt;The last big contribution I was able to make to the team, though not quite related to Software Engineering, was working with the Research and Development as well as the Marketing and Sales teams in order to conduct competitive analyses for different products that were in the pipeline for release or were being considered for development. This was an interesting insight on how similar companies compete to gain an improving market share, and provided lots of information on the HVAC/R industry as well as general business knowledge that gave me more information on how different sectors of a company I’m not traditinally working with directly operate and function, as well as integrate with engineering teams I tend to be more often a part of.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Over the summer, I did a wide variety of things and was able to dramatically improve my Software Engineer experience as well as my overall business fluency in an entirely new industry. I’m extremely thankful to CPS for having provided me this opportunity, and look forward to seeing where the experience I’ve gained takes me!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Career" /><category term="Hot Take" /><category term="JavaScript" /><category term="TypeScript" /><category term="Ionic" /><category term="WordPress" /><category term="Coding" /><summary type="html">This summer, I was an Engineering/Web Intern at CPS Products, Inc. Throughout my internship, I learned and refined lots of skills that I’ll be taking back and using in my career for years to come. The internship encompassed many different categories, including Web Development/WordPress Management, Software/Mobile App Development, Competitive Analysis and Research, and more. Over the course of the internship, I discovered TypeScript and added it to my skillset, and was able to refine and modernize my Apache Cordova experience with the newer Ionic framework, and was able to apply my skills to create a production-grade application that’s in the works of being deployed today. Additionally, with some of the knowledge I amassed throughout the internship, I was able to develop a standalone app that allows you to communicate with a BLE (Bluetooth Low Energy), device as a terminal. I also learned some helpful tools to optimize a WordPress Website, and even managed to increase PageSpeed Insights by more than 50 points on several sites. Ionic and the Future of App Development Ionic has become my favorite tool for quickly creating desktop, web, and mobile apps beautifully and efficiently. One of the most impactful technologies I learned throughout the internship was Ionic, the new app development framework. I had some previous experience with Apache Cordova throughout my last internship, but overall, pure Cordova felt a bit dated and clunky. Ionic also has the advantage of having an incredible CLI, which allowed me to create projects, add components to my projects, generate resources such as splash screens and app icons, and compile and run on an emulator or connected device. Additionally, Ionic uses TypeScript and Angular by default, both of which I had to learn in order to create the apps I did this summer. Ionic is my favorite method to creating apps because it allows you to use web-heavy development to produce Native code on Android, iOS, and more. This summer I was assigned the task of developing an application that interfaces with BLE devices and sends and receives information that is gained from the sensors onboard the various Bluetooth Devices CPS Products uses. My Bluetooth Terminal app running on Android. In order to learn the workflow of creating Ionic applications and handling BLE devices, I created a separate BLE Terminal on my own time that actually became a really powerful tool I was able to use to test the subsequent apps I was developing. Though simple, the Terminal app proved to be extremely useful, and allows both sending and receiving of ASCII text to and from a BLE device with an optionally adjustable characteristic and service UUID sets. Learning how BLE works and applying it to my existing code was one of the most difficult tasks I had to undertake while on this internship, but once I was able to create a base class in TypeScript that performed all of the Bluetooth Functions, I was set. I ended up using Apache Cordova instead of the newer capacitor, because of my previous experience with Cordova and because of the increased plugin support. This ended up being just as efficient though, especially when creating an application with heavy third-party plugin requirements. Making WordPress More Efficient Source Another one of the useful takeaways from the internship was being able to learn some effective steps to make any WordPress site more efficient, through things such as WP Super Cache, Autoptimize, and using CDNs. Though I’d had previous experience managing WordPress websites, page speed wasn’t ever a priority, but I was able to really focus on it during this internship and was able to improve the PageSpeed Insight Score of all 3 CPS Products websites by 50 points or more. Another really important procedure I was able to develop was a workflow to automatically make uploaded images be resized, compressed, and served through a CDN instead of through the website itself. This dramatically increased website speeds and was by far the biggest improvement to the PageSpeed Insight Score. In the future, I hope to take this knowledge and be able to apply it to the improvement of many WordPress sites, especially those with high traffic that depend on low latency. Competitive Analysis for Research and Development The last big contribution I was able to make to the team, though not quite related to Software Engineering, was working with the Research and Development as well as the Marketing and Sales teams in order to conduct competitive analyses for different products that were in the pipeline for release or were being considered for development. This was an interesting insight on how similar companies compete to gain an improving market share, and provided lots of information on the HVAC/R industry as well as general business knowledge that gave me more information on how different sectors of a company I’m not traditinally working with directly operate and function, as well as integrate with engineering teams I tend to be more often a part of. Conclusion Over the summer, I did a wide variety of things and was able to dramatically improve my Software Engineer experience as well as my overall business fluency in an entirely new industry. I’m extremely thankful to CPS for having provided me this opportunity, and look forward to seeing where the experience I’ve gained takes me!</summary></entry><entry><title type="html">Creating a Simple To-Do App with TypeScript, Node, SQLite, and ExpressJS</title><link href="https://blog.cgsphoto.com/tutorial/todo-app/" rel="alternate" type="text/html" title="Creating a Simple To-Do App with TypeScript, Node, SQLite, and ExpressJS" /><published>2019-08-09T00:00:00+00:00</published><updated>2019-08-09T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/tutorial/todo-app</id><content type="html" xml:base="https://blog.cgsphoto.com/tutorial/todo-app/">&lt;p&gt;Have you found yourself needing a place to keep a list of To-Dos, but don’t trust big companies with having all of your information? Need the most lightweight todo client possible that you can access from anywhere? Want to be able to share a To-Do list with anyone, without having them download fancy apps and set up accounts? I certainly have, and instead of scouring the internet to try to find a solution, I decided to build it myself. The product ended up being a Node server using ExpressJS to render the webpage, using TypeScript to handle backend requests, and storing the To-Dos on an SQLite server on the server. Though this was only truly intended as a tool to learn the technologies and putting them together, it technically is a fully functional To-Do list, and I might just plan to use it in the future for quick and dirty tasks to keep track of.&lt;/p&gt;

&lt;p class=&quot;notice--info&quot;&gt;This tutorial is heavily inspired by &lt;a href=&quot;https://github.com/missating&quot;&gt;missating&lt;/a&gt;’s &lt;a href=&quot;https://github.com/missating/nodejs-todo&quot;&gt;nodejs-todo&lt;/a&gt; project. Thanks!&lt;/p&gt;

&lt;h2 id=&quot;set-up-and-installation&quot;&gt;Set up and installation&lt;/h2&gt;

&lt;h3 id=&quot;node&quot;&gt;Node&lt;/h3&gt;

&lt;p&gt;Node is Server-Side JavaScript that you can use just as you would any other server-side language like Java or Python. Our application depends on this because we’ll be using several different Node packages, such as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqlite3&lt;/code&gt; package to store our data and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ejs&lt;/code&gt; (ExpressJS) package to server our front-end website. Getting it installed depends on your architecture; if you have Ubuntu/Debian, you can simply run&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;nodejs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Otherwise, you’ll want to look at the &lt;a href=&quot;https://nodejs.org/en/download/&quot;&gt;Node downloads page&lt;/a&gt; to install it.&lt;/p&gt;

&lt;p&gt;After you have it installed, you’ll want to check to make sure it works by opening a terminal and typing in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm -v&lt;/code&gt;. If you get a response, congratulations! You’ve got everything working.&lt;/p&gt;

&lt;h3 id=&quot;typescript&quot;&gt;TypeScript&lt;/h3&gt;

&lt;p&gt;As a developer with a higher concentration in strongly-typed languages, TypeScript is probably my favorite tool for modern, web-first programs and applications. TypeScript compiles directly to JavaScript, meaning that its use can be applied to any project that uses JavaScript, and it keeps things in check more so that pure JavaScript. To get it downloaded, you’ll have to install it within node:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; typescript
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;notice--primary&quot;&gt;This will install Express globally. If you would like to install it only for this project, you can do so with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install typescript --save&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;expressjs&quot;&gt;ExpressJS&lt;/h3&gt;

&lt;p&gt;ExpressJS is a lightweight Node.js web framework that’s going to get us up and running really quickly. In order to install it and add it to our project, we’re going to run the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm&lt;/code&gt; command, which is the Node Package Manager:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;express &lt;span class=&quot;nt&quot;&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;bodyparser&quot;&gt;BodyParser&lt;/h3&gt;

&lt;p&gt;BodyParser is a module we’ll need to help us handle values we transfer to and from the database. Install it with:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;body-parser &lt;span class=&quot;nt&quot;&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;sqlite&quot;&gt;SQLite&lt;/h3&gt;

&lt;p&gt;SQLite is our choice for databases here because of how light it is, how portable it is, and how easy it is to back up/migrate it whenever we need to, as it saves everything into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.db&lt;/code&gt; file. It uses a simplified SQL language version, and has &amp;lt;1ms response times!&lt;/p&gt;

&lt;p&gt;Like with Express, the installation goes as follows:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;sqlite3 &lt;span class=&quot;nt&quot;&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now that we have all of our dependencies, installed, we’re ready to create a new project and get coding!&lt;/p&gt;

&lt;h2 id=&quot;the-fun-stuff&quot;&gt;The Fun Stuff&lt;/h2&gt;

&lt;p class=&quot;notice--info&quot;&gt;&lt;a href=&quot;https://github.com/LeoSaucedo/todo-mini&quot;&gt;Here&lt;/a&gt; is the repository where I host the current iteration of the todo app. If you’d like to skip the following along part, you can just fork this repository.&lt;/p&gt;

&lt;p&gt;The first thing we’re going to do to start off our coding is some simple Node and Express things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a new directory named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo-mini&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Navigate to the directory in a terminal and run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm init&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Fill out the requested information in as much depth as you like, making sure to set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;main&quot;&lt;/code&gt; field to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.js&lt;/code&gt;because we’re using TypeScript.&lt;/li&gt;
  &lt;li&gt;Create a new file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt; and open it in your favorite text editor.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;configuring-typescript-for-node&quot;&gt;Configuring TypeScript for Node&lt;/h3&gt;

&lt;p&gt;Because we’re going to be using TypeScript instead of pure JavaScript for our Node app, we have to make some slight configuration changes to our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package.json&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;scripts&quot;&lt;/code&gt;, we’ll add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;tsc&quot;: &quot;tsc&quot;&lt;/code&gt; so that we can compile our TypeScript into JavaScript when we run our app.&lt;/li&gt;
  &lt;li&gt;We’ll double check that our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;main&quot;&lt;/code&gt; is set to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;index.ts&quot;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;notice--info&quot;&gt;&lt;em&gt;Note:&lt;/em&gt; We can also set this within the initial configuration.&lt;/p&gt;

&lt;h3 id=&quot;hello-world&quot;&gt;Hello World&lt;/h3&gt;

&lt;p&gt;Inside our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt;, we first import all of our dependencies:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import all of our dependencies&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bodyParser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;body-parser&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We’ll also be importing some TS files we’ll write ourselves, but we’ll do that later.&lt;/p&gt;

&lt;p&gt;Now, let’s configure Express to serve us some web:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Instantiating the Express object.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Handles whenever the root directory of the website is accessed.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Respond with Express&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Hello world!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Set app to listen on port 3000&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;updateValues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;server is running on port 3000&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once this is done, if we run our Node app with:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm run tsc &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; node build/index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and we navigate to the website we just hosted at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://localhost/4000&lt;/code&gt;, we should see it return &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hello World!&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;creating-our-to-do-list&quot;&gt;Creating our To-Do List&lt;/h3&gt;

&lt;p&gt;While really cool, this doesn’t really let us do anything with or to-dos! Let’s actually design the view that we’re going to be seeing:&lt;/p&gt;

&lt;h4 id=&quot;sql-module&quot;&gt;SQL Module&lt;/h4&gt;

&lt;p&gt;First, before we do anything, we need to create our SQLite database and create the appropriate tables we’ll be accessing later on within our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqlite3.ts&lt;/code&gt; file. The way you’ll do this varies depending on your development environment, but for me, using VSCode and the SQLite extension, I just have to open the command palette and type in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;New Quick Query&lt;/code&gt;, and write the following:&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;todo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We should now have two tables created, which store a text value of the task to do. That way, if we need to add more functions later on, it’s easy to add columns to each table.&lt;/p&gt;

&lt;p&gt;Now, we have to write the SQL module that creates the database and sets up the framework so that we can store our to-dos. Create a new folder named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modules&lt;/code&gt; and add a new file named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqlite3.ts&lt;/code&gt; inside it, and then import and initialize sqlite within our custom module.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqlite3.ts&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Importing SQLite3 to our project.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sqlite3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;sqlite3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;verbose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Setting up a database for storing data.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sqlite3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;database.db&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since this is a Node module, we’ll write it a little bit differently &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt;. We’ll encase all of our functions within &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;module.exports&lt;/code&gt;, like so:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;exports&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// All of our functions go here.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Inside of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;module.exports&lt;/code&gt;, we’re going to place functions that handle our requests from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt;, namely, an ability to add tasks, mark them as completed, and remove the ones that have already been completed. We’ll also add functions to fetch the incomplete and complete tasks so we can populate the website whenever we refresh the page.&lt;/p&gt;

&lt;p&gt;First, the function to get the incomplete tasks:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nx&quot;&gt;getTodoList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;SELECT * FROM todo&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Similarly, another function to get the incomplete tasks:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nx&quot;&gt;getDoneList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;SELECT * FROM done&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, functions to add, mark as complete, and clear completed tasks:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nx&quot;&gt;addTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;taskName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Add a task to the todo list.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;INSERT INTO todo VALUES ($task)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;$task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;taskName&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;completeTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;taskName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Delete the task from the todo list.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;DELETE FROM todo WHERE task=$task&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;$task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;taskName&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;INSERT INTO done VALUES ($task)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;$task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;taskName&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;clearComplete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Delete all cleared tasks.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;DELETE FROM done&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These are all pretty straightforward SQL commands that we just interface through the SQL plugin with. If you would like more background knowledge with SQL, w3schools provides a great set of &lt;a href=&quot;https://www.w3schools.com/sql/&quot;&gt;tutorials&lt;/a&gt; on SQL.&lt;/p&gt;

&lt;h4 id=&quot;typescript-1&quot;&gt;TypeScript&lt;/h4&gt;

&lt;p&gt;Before we can render HTML with Express, we’ll have to add these lines right after our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require&lt;/code&gt; statements. These settings allow us to use Express, our CSS, and the custom made HTML we’re about to write.&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Set up BodyParser.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bodyParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;urlencoded&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;extended&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}));&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Set the view engine to use Express.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;view engine&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ejs&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Custom-made SQLite module.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;./modules/sqlite3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Render the CSS Files&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After we’ve done that, we will change the default root directory action to access our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ejs&lt;/code&gt; file instead of printing “Hello World!”:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Render the ejs and display added task, completed task&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;updateValues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;complete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;complete&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;typescript-functions&quot;&gt;TypeScript Functions&lt;/h5&gt;

&lt;p&gt;Now, we’ll write the HTML request endpoints so that we can query information:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ts&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Adding a new task.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/addtask&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;newTask&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;newtask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Add the new task from the post route.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;newTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;redirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Removing a task.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/removetask&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;completeTask&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;completeTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;completeTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;redirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Clearing all complete tasks.&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/clearcomplete&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;clearComplete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;redirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We’ll also need a function to update the values of the tasks and their completion status every time the app refreshes:&lt;/p&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * Updates the todo/done lists.
 */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;updateValues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getTodoList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;sqlite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getDoneList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;complete&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, we should have all of the necessary components in the backend to handle all of our functionality. Now, to spice things up with HTML and CSS.&lt;/p&gt;

&lt;h4 id=&quot;html-ejs&quot;&gt;HTML (EJS)&lt;/h4&gt;

&lt;p&gt;To actually write the HTML contents of our app, we’re going to want to create a new EJS directory named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;views&lt;/code&gt; in our root directory, and create a new file titled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ejs&lt;/code&gt;. Though the extension isn’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.html&lt;/code&gt;, it will actually render as it, so hopefully your IDE highlights it as such.&lt;/p&gt;

&lt;p&gt;We’ll place the following in that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.ejs&lt;/code&gt; file:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/LeoSaucedo/de8b57872be6ad0f6107257dc9f38284.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;This places all of our necessary components, and defines all the necessary HTML requests so that we can access and insert information into our to-do list:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addtask&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Allows us to add a task.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;removetask&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Allows us to mark a task as completed (remove it from the to-do list)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clearcomplete&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Clears all of the completed tasks.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we’ve defined these requests in the HTML, we’ll move on to the TypeScript file and add some endpoints to them.&lt;/p&gt;

&lt;h4 id=&quot;css&quot;&gt;CSS&lt;/h4&gt;

&lt;p&gt;I won’t be going too much into detail with the CSS, because it’s a long thing to teach in one article that doesn’t focus too much on it, but I’ve made available my CSS Stylesheet for this project. You’ll want to download &lt;a href=&quot;https://github.com/LeoSaucedo/todo-mini/blob/master/public/styles.css&quot;&gt;this file&lt;/a&gt; and place it under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo-mini/public/&lt;/code&gt; to import this CSS to our project. You can mess with these settings as much as you’d like - the CSS I have written is a bit simplistic but you can tune it up a lot!&lt;/p&gt;

&lt;h2 id=&quot;running-the-program&quot;&gt;Running the program&lt;/h2&gt;

&lt;p&gt;That’s it! We’ve successfully employed SQLite, Node, TypeScript, and EJS to create a simple To-Do list with persistent storage. Go into a terminal and navigate to the directory of your project, and type:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm run tsc &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; node build/index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, navigate to the app:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://localhost:3000/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And revel at what you’ve accomplished.&lt;/p&gt;

&lt;p&gt;See you next time, and happy coding!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Tutorial" /><category term="JavaScript" /><category term="TypeScript" /><category term="Node" /><category term="SQLite" /><summary type="html">Have you found yourself needing a place to keep a list of To-Dos, but don’t trust big companies with having all of your information? Need the most lightweight todo client possible that you can access from anywhere? Want to be able to share a To-Do list with anyone, without having them download fancy apps and set up accounts? I certainly have, and instead of scouring the internet to try to find a solution, I decided to build it myself. The product ended up being a Node server using ExpressJS to render the webpage, using TypeScript to handle backend requests, and storing the To-Dos on an SQLite server on the server. Though this was only truly intended as a tool to learn the technologies and putting them together, it technically is a fully functional To-Do list, and I might just plan to use it in the future for quick and dirty tasks to keep track of. This tutorial is heavily inspired by missating’s nodejs-todo project. Thanks! Set up and installation Node Node is Server-Side JavaScript that you can use just as you would any other server-side language like Java or Python. Our application depends on this because we’ll be using several different Node packages, such as the sqlite3 package to store our data and the ejs (ExpressJS) package to server our front-end website. Getting it installed depends on your architecture; if you have Ubuntu/Debian, you can simply run sudo apt-get install nodejs Otherwise, you’ll want to look at the Node downloads page to install it. After you have it installed, you’ll want to check to make sure it works by opening a terminal and typing in npm -v. If you get a response, congratulations! You’ve got everything working. TypeScript As a developer with a higher concentration in strongly-typed languages, TypeScript is probably my favorite tool for modern, web-first programs and applications. TypeScript compiles directly to JavaScript, meaning that its use can be applied to any project that uses JavaScript, and it keeps things in check more so that pure JavaScript. To get it downloaded, you’ll have to install it within node: npm install -g typescript This will install Express globally. If you would like to install it only for this project, you can do so with npm install typescript --save. ExpressJS ExpressJS is a lightweight Node.js web framework that’s going to get us up and running really quickly. In order to install it and add it to our project, we’re going to run the npm command, which is the Node Package Manager: npm install express --save BodyParser BodyParser is a module we’ll need to help us handle values we transfer to and from the database. Install it with: npm install body-parser --save SQLite SQLite is our choice for databases here because of how light it is, how portable it is, and how easy it is to back up/migrate it whenever we need to, as it saves everything into a .db file. It uses a simplified SQL language version, and has &amp;lt;1ms response times! Like with Express, the installation goes as follows: npm install sqlite3 --save Now that we have all of our dependencies, installed, we’re ready to create a new project and get coding! The Fun Stuff Here is the repository where I host the current iteration of the todo app. If you’d like to skip the following along part, you can just fork this repository. The first thing we’re going to do to start off our coding is some simple Node and Express things: Create a new directory named todo-mini. Navigate to the directory in a terminal and run npm init. Fill out the requested information in as much depth as you like, making sure to set the &quot;main&quot; field to index.ts instead of index.jsbecause we’re using TypeScript. Create a new file called index.ts and open it in your favorite text editor. Configuring TypeScript for Node Because we’re going to be using TypeScript instead of pure JavaScript for our Node app, we have to make some slight configuration changes to our package.json: Under &quot;scripts&quot;, we’ll add &quot;tsc&quot;: &quot;tsc&quot; so that we can compile our TypeScript into JavaScript when we run our app. We’ll double check that our &quot;main&quot; is set to &quot;index.ts&quot;. Note: We can also set this within the initial configuration. Hello World Inside our index.ts, we first import all of our dependencies: // Import all of our dependencies var express = require(&quot;express&quot;); var bodyParser = require(&quot;body-parser&quot;); var app = express(); We’ll also be importing some TS files we’ll write ourselves, but we’ll do that later. Now, let’s configure Express to serve us some web: // Instantiating the Express object. var app = express(); // Handles whenever the root directory of the website is accessed. app.get(&quot;/&quot;, function(req, res) { // Respond with Express res.send(&quot;Hello world!&quot;); }); // Set app to listen on port 3000 app.listen(3000, function() { updateValues(function() { console.log(&quot;server is running on port 3000&quot;); }); }); Once this is done, if we run our Node app with: npm run tsc &amp;amp;&amp;amp; node build/index.js and we navigate to the website we just hosted at http://localhost/4000, we should see it return Hello World! Creating our To-Do List While really cool, this doesn’t really let us do anything with or to-dos! Let’s actually design the view that we’re going to be seeing: SQL Module First, before we do anything, we need to create our SQLite database and create the appropriate tables we’ll be accessing later on within our sqlite3.ts file. The way you’ll do this varies depending on your development environment, but for me, using VSCode and the SQLite extension, I just have to open the command palette and type in New Quick Query, and write the following: CREATE TABLE todo( task text ); CREATE TABLE done( task text ); We should now have two tables created, which store a text value of the task to do. That way, if we need to add more functions later on, it’s easy to add columns to each table. Now, we have to write the SQL module that creates the database and sets up the framework so that we can store our to-dos. Create a new folder named modules and add a new file named sqlite3.ts inside it, and then import and initialize sqlite within our custom module. sqlite3.ts: // Importing SQLite3 to our project. var sqlite3 = require(&quot;sqlite3&quot;).verbose(); // Setting up a database for storing data. var db = new sqlite3.Database(&quot;database.db&quot;); Since this is a Node module, we’ll write it a little bit differently index.ts. We’ll encase all of our functions within module.exports, like so: module.exports = { // All of our functions go here. }; Inside of module.exports, we’re going to place functions that handle our requests from index.ts, namely, an ability to add tasks, mark them as completed, and remove the ones that have already been completed. We’ll also add functions to fetch the incomplete and complete tasks so we can populate the website whenever we refresh the page. First, the function to get the incomplete tasks: getTodoList: function(callback:any){ db.all(&quot;SELECT * FROM todo&quot;, function(err:any, res:any){ callback(res); }); }, Similarly, another function to get the incomplete tasks: getDoneList: function(callback:any){ db.all(&quot;SELECT * FROM done&quot;, function(err:any, res:any){ callback(res); }); }, Then, functions to add, mark as complete, and clear completed tasks: addTask: function(taskName:string, callback:any){ // Add a task to the todo list. db.run(&quot;INSERT INTO todo VALUES ($task)&quot;, { $task: taskName }, function(){ callback(); }); }, completeTask: function(taskName:string, callback:any){ // Delete the task from the todo list. db.run(&quot;DELETE FROM todo WHERE task=$task&quot;, { $task: taskName }, function(){ db.run(&quot;INSERT INTO done VALUES ($task)&quot;, { $task: taskName }, function(){ callback(); }); }); }, clearComplete: function(callback:any){ // Delete all cleared tasks. db.run(&quot;DELETE FROM done&quot;, function(){ callback(); }); } These are all pretty straightforward SQL commands that we just interface through the SQL plugin with. If you would like more background knowledge with SQL, w3schools provides a great set of tutorials on SQL. TypeScript Before we can render HTML with Express, we’ll have to add these lines right after our require statements. These settings allow us to use Express, our CSS, and the custom made HTML we’re about to write. // Set up BodyParser. app.use(bodyParser.urlencoded({ extended: true })); // Set the view engine to use Express. app.set(&quot;view engine&quot;, &quot;ejs&quot;); // Custom-made SQLite module. var sqlite = require(&quot;./modules/sqlite3&quot;); // Render the CSS Files app.use(express.static(&quot;public&quot;)); After we’ve done that, we will change the default root directory action to access our index.ejs file instead of printing “Hello World!”: // Render the ejs and display added task, completed task app.get(&quot;/&quot;, function(req: any, res: any) { updateValues(function() { res.render(&quot;index&quot;, { task: task, complete: complete }); }); }); TypeScript Functions Now, we’ll write the HTML request endpoints so that we can query information: index.ts: // Adding a new task. app.post(&quot;/addtask&quot;, function(req: any, res: any) { var newTask = req.body.newtask; // Add the new task from the post route. sqlite.addTask(newTask, function() { res.redirect(&quot;/&quot;); }); }); // Removing a task. app.post(&quot;/removetask&quot;, function(req: any, res: any) { var completeTask = req.body.check; sqlite.completeTask(completeTask, function() { res.redirect(&quot;/&quot;); }); }); // Clearing all complete tasks. app.post(&quot;/clearcomplete&quot;, function(req: any, res: any) { sqlite.clearComplete(function() { res.redirect(&quot;/&quot;); }); }); We’ll also need a function to update the values of the tasks and their completion status every time the app refreshes: /** * Updates the todo/done lists. */ function updateValues(callback: any) { sqlite.getTodoList(function(result: any) { task = result; sqlite.getDoneList(function(result: any) { complete = result; callback(); }); }); } Now, we should have all of the necessary components in the backend to handle all of our functionality. Now, to spice things up with HTML and CSS. HTML (EJS) To actually write the HTML contents of our app, we’re going to want to create a new EJS directory named views in our root directory, and create a new file titled index.ejs. Though the extension isn’t .html, it will actually render as it, so hopefully your IDE highlights it as such. We’ll place the following in that index.ejs file: This places all of our necessary components, and defines all the necessary HTML requests so that we can access and insert information into our to-do list: addtask Allows us to add a task. removetask Allows us to mark a task as completed (remove it from the to-do list) clearcomplete Clears all of the completed tasks. Now that we’ve defined these requests in the HTML, we’ll move on to the TypeScript file and add some endpoints to them. CSS I won’t be going too much into detail with the CSS, because it’s a long thing to teach in one article that doesn’t focus too much on it, but I’ve made available my CSS Stylesheet for this project. You’ll want to download this file and place it under todo-mini/public/ to import this CSS to our project. You can mess with these settings as much as you’d like - the CSS I have written is a bit simplistic but you can tune it up a lot! Running the program That’s it! We’ve successfully employed SQLite, Node, TypeScript, and EJS to create a simple To-Do list with persistent storage. Go into a terminal and navigate to the directory of your project, and type: npm run tsc &amp;amp;&amp;amp; node build/index.js Then, navigate to the app: http://localhost:3000/ And revel at what you’ve accomplished. See you next time, and happy coding!</summary></entry><entry><title type="html">How to Use the Wolfram Alpha API in Python</title><link href="https://blog.cgsphoto.com/quick%20tip/wolfram-python/" rel="alternate" type="text/html" title="How to Use the Wolfram Alpha API in Python" /><published>2019-06-27T00:00:00+00:00</published><updated>2019-06-27T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/quick%20tip/wolfram-python</id><content type="html" xml:base="https://blog.cgsphoto.com/quick%20tip/wolfram-python/">&lt;p&gt;If you’re a Computer Scientist, Physicist, Mathematician, or just an analytical person that likes fast, accurate computation with a knowledge base that is unmatched anywhere else in the world, then you’ve probably worked with WolframAlpha before. Whether for computations, unit conversions, or word definitions, Wolfram seems to have an answer to pretty much every single important question out there, and being able to harness that ability and apply it to our own programs is perhaps one of the most powerful add-ons we can add to an AI or chatbot to enhance responses quickly and easily. In this Quick Tip, we’ll be going through how to integrate WolframAlpha into your Python program to instantly beef up your data power.&lt;/p&gt;

&lt;h1 id=&quot;api-authentication&quot;&gt;API Authentication&lt;/h1&gt;

&lt;h2 id=&quot;creating-an-account&quot;&gt;Creating an Account&lt;/h2&gt;

&lt;div class=&quot;notice&quot;&gt;
&lt;p&gt;In the free plan, we get access to 2,000 free queries per month, which so far has been enough for all of my applications (even those with 120,000+ users!). If you’re going to be having a small to medium-sized project, the free plan should suffice.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;First, you’ll need to &lt;a href=&quot;https://account.wolfram.com/auth/create&quot;&gt;create a WolframAlpha API account&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/wolfram_api_dashboard.png&quot; alt=&quot;&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;The WolframAlpha API Dashboard.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;When you verify your email address, you’ll be redirected to the dashboard, and you’ll be able to proceed to the next step!&lt;/p&gt;

&lt;h2 id=&quot;getting-your-api-key&quot;&gt;Getting Your API Key&lt;/h2&gt;
&lt;p&gt;In the dashboard, click the &lt;strong&gt;Get an AppID&lt;/strong&gt; button.&lt;/p&gt;

&lt;div style=&quot;text-align:center&quot;&gt;&lt;img src=&quot;/assets/images/wolfram_api_createid.png&quot; /&gt;&lt;/div&gt;
&lt;p&gt;&lt;i style=&quot;font-size:smaller&quot;&gt;Enter the relevant details for the app.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;When you click on &lt;strong&gt;create&lt;/strong&gt;, a new API key will be generated for your records. Store this token - it’s what you’ll need to authenticate with the Wolfram API! Once you write it down, we can move on to the next step - setting up our code to authenticate the key, and writing queries and getting responses!&lt;/p&gt;

&lt;div style=&quot;text-align:center&quot;&gt;&lt;img src=&quot;/assets/images/wolfram_api_id.png&quot; /&gt;&lt;/div&gt;
&lt;p&gt;&lt;i style=&quot;font-size:smaller&quot;&gt;Keep this API key for your records!&lt;/i&gt;&lt;/p&gt;

&lt;h1 id=&quot;installation&quot;&gt;Installation&lt;/h1&gt;

&lt;p&gt;First, you’ll need to install the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wolframalpha&lt;/code&gt; dependency:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;wolframalpha
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, you’ll be able to download or copy the gist I created for interfacing with Wolfram Alpha:
&lt;script src=&quot;https://gist.github.com/LeoSaucedo/d1f1d95e9e2f21d265719d511b9bc911.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Save this as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wolframapi.py&lt;/code&gt; in the root folder of your Python program. Then, in your main Python file, import the module:&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;wolframapi&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wolfram&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;usage&quot;&gt;Usage&lt;/h1&gt;

&lt;p&gt;Once you’ve imported all the necessary modules, you’ll be able to very easily create a new Wolfram Client object and interface with it.&lt;/p&gt;

&lt;p&gt;First, instantiate the Wolfram Client as a variable:&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wolfram&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;YOUR_CONFIG_KEY_HERE&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If no errors are returned, authentication succeeded! Now, you’ll be able to easily query responses like so:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Weather in Tallahassee, FL&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If everything is correct, you should get a detailed, multiline response:&lt;/p&gt;
&lt;div style=&quot;text-align:center&quot;&gt;&lt;img src=&quot;/assets/images/wolfram_response_example.png&quot; /&gt;&lt;/div&gt;
&lt;p&gt;&lt;i style=&quot;font-size:smaller&quot;&gt;A bit hot, don’t you think?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;And that’s it! You can now customize it to your heart’s desire. Feel free to implement any changes to my small API, as well as use this code on your programs of any scale whatsoever!&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;With WolframAlpha, you’ll be able to create extremely intelligent responses to almost any prompt, from weather, to unit conversions, to Calculus. It’s something that I consider essential to all of my AI applications, and sometimes use it for quick conversions so as not to install loads of different modules. I hope you found my Quick Tip interesting, and happy coding!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Quick Tip" /><category term="Python" /><category term="Tutorial" /><category term="Coding" /><summary type="html">If you’re a Computer Scientist, Physicist, Mathematician, or just an analytical person that likes fast, accurate computation with a knowledge base that is unmatched anywhere else in the world, then you’ve probably worked with WolframAlpha before. Whether for computations, unit conversions, or word definitions, Wolfram seems to have an answer to pretty much every single important question out there, and being able to harness that ability and apply it to our own programs is perhaps one of the most powerful add-ons we can add to an AI or chatbot to enhance responses quickly and easily. In this Quick Tip, we’ll be going through how to integrate WolframAlpha into your Python program to instantly beef up your data power. API Authentication Creating an Account In the free plan, we get access to 2,000 free queries per month, which so far has been enough for all of my applications (even those with 120,000+ users!). If you’re going to be having a small to medium-sized project, the free plan should suffice. First, you’ll need to create a WolframAlpha API account. The WolframAlpha API Dashboard. When you verify your email address, you’ll be redirected to the dashboard, and you’ll be able to proceed to the next step! Getting Your API Key In the dashboard, click the Get an AppID button. Enter the relevant details for the app. When you click on create, a new API key will be generated for your records. Store this token - it’s what you’ll need to authenticate with the Wolfram API! Once you write it down, we can move on to the next step - setting up our code to authenticate the key, and writing queries and getting responses! Keep this API key for your records! Installation First, you’ll need to install the wolframalpha dependency: pip install wolframalpha Next, you’ll be able to download or copy the gist I created for interfacing with Wolfram Alpha: Save this as wolframapi.py in the root folder of your Python program. Then, in your main Python file, import the module: import wolframapi as wolfram Usage Once you’ve imported all the necessary modules, you’ll be able to very easily create a new Wolfram Client object and interface with it. First, instantiate the Wolfram Client as a variable: client = wolfram.Client(&quot;YOUR_CONFIG_KEY_HERE&quot;) If no errors are returned, authentication succeeded! Now, you’ll be able to easily query responses like so: print(client.ask(&quot;Weather in Tallahassee, FL&quot;)); If everything is correct, you should get a detailed, multiline response: A bit hot, don’t you think? And that’s it! You can now customize it to your heart’s desire. Feel free to implement any changes to my small API, as well as use this code on your programs of any scale whatsoever! Conclusion With WolframAlpha, you’ll be able to create extremely intelligent responses to almost any prompt, from weather, to unit conversions, to Calculus. It’s something that I consider essential to all of my AI applications, and sometimes use it for quick conversions so as not to install loads of different modules. I hope you found my Quick Tip interesting, and happy coding!</summary></entry><entry><title type="html">Exploring the New Microsoft Terminal</title><link href="https://blog.cgsphoto.com/hot%20take/microsoft-terminal-review/" rel="alternate" type="text/html" title="Exploring the New Microsoft Terminal" /><published>2019-06-25T00:00:00+00:00</published><updated>2019-06-25T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/hot%20take/microsoft-terminal-review</id><content type="html" xml:base="https://blog.cgsphoto.com/hot%20take/microsoft-terminal-review/">&lt;p&gt;It’s officially summertime, and with that comes the hottest-anticipated programming product for Windows users: the Windows Terminal! In this post, I’ll be running through my quick thoughts about it, and how it will be affecting my programming workflow, as well as the specific settings that I modified it to give it the “Carlos Way” touch.&lt;/p&gt;

&lt;h1 id=&quot;preface&quot;&gt;Preface&lt;/h1&gt;

&lt;p&gt;The Windows Terminal is still in early alpha, and many of its features will be changing. This is definitely not anything near what the final product will look like, and shouldn’t be your final judgement on whether you should be using it or not. However, it does provide a good insight into what your workflow might look like if you end up using it, so it’s still worth a look!&lt;/p&gt;

&lt;h1 id=&quot;interface&quot;&gt;Interface&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/ms-terminal-cmd.png&quot; alt=&quot;&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;The Windows Terminal with an active CMD tab.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;I’m actually quite pleased with how the terminal looks. Aside from a couple of design discrepancies, in my own opinion, the Windows Terminal is a &lt;em&gt;huge&lt;/em&gt; improvement over the traditional command prompt, and has some impressive theming options that bring it to the 21st century. It has an optional, customizable transparency setting, which, just like the new Calculator app, glosses over the contents behind it in a sleek, modern style. It also has a nice, tabbed interface that reminds me more of a Google Chrome dark theme than a terminal interface. It has the ability to display emoji, and has hyperlinks you can click on, like the terminal in VSCode.&lt;/p&gt;

&lt;h2 id=&quot;tabs&quot;&gt;Tabs&lt;/h2&gt;

&lt;p&gt;One of the most acclaimed new features of the Windows Terminal, the tabbed interface is just that - the ability to have more than one instance within a Windows Terminal window. Unlike other terminal programs for Windows and Unix, however, the Windows Terminal allows tabs of different environments and operating systems within one window, a new feature I will be using greatly.&lt;/p&gt;

&lt;p&gt;When you click on the new tab button, a new tab from the default profile appears, but if you want to open a tab in another profile, you can select it from the dropdown button right next to it:&lt;/p&gt;

&lt;div style=&quot;text-align:center&quot;&gt;&lt;img src=&quot;/assets/images/ms-terminal-selector.png&quot; /&gt;&lt;/div&gt;
&lt;p&gt;&lt;i style=&quot;font-size:smaller&quot;&gt;The tabs selector is fully customizable with profiles in the settings menu.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;Every aspect of these dropdown options is able to be customized, from the titles and icons to the precise shell they are running. Your existing shells, both WSL and Microsoft, should be automatically populated, but they are easy to add if for some reason they have not been.&lt;/p&gt;

&lt;h2 id=&quot;customization&quot;&gt;Customization&lt;/h2&gt;

&lt;p&gt;In my opinion, the customization process is probably what needs the most work so far. However, much to the style of Visual Studio Code, almost everything about the Windows Terminal can be customized. When clicking on the settings button in the dropdown, as shown above, you are met with a Visual Studio Code instance of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSON&lt;/code&gt; settings file, and can edit it just as you would any other text file:&lt;/p&gt;

&lt;div style=&quot;text-align:center&quot;&gt;&lt;img src=&quot;/assets/images/ms-terminal-settings.png&quot; /&gt;&lt;/div&gt;
&lt;p&gt;&lt;i style=&quot;font-size:smaller&quot;&gt;The settings dialogue.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;While more hardened programmers will find this a possible positive change, more casual terminal users might find this slightly difficult to work with, especially those not so familiar with JSON. For my purposes, VSCode with a &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=bierner.color-info&quot;&gt;Color Info Plugin&lt;/a&gt; did an amazing job at letting me adjust theming and organize everything the way I needed it to. When opening the JSON file, your first relevant find will be all of the keybindings. I chose to leave them be for the time being, but it’s good to know that they’re all completely modular. Second, the list of profiles defines what kinds of tabs you can open:&lt;/p&gt;

&lt;h3 id=&quot;profiles&quot;&gt;Profiles&lt;/h3&gt;

&lt;p&gt;Profiles should be initially generated for you when you first install and run Windows Terminal. However, if you ever need to edit them to fit your specific needs - I adjusted the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fontSize&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cursorShape&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;colorScheme&lt;/code&gt; to a custom scheme I created just for my Ubuntu instance, which you’ll see below. The settings are pretty self explanatory, but if you don’t know what you’re doing you probably don’t want to be prodding around and accidentally break your terminal.&lt;/p&gt;

&lt;p&gt;When designing my Ubuntu profile, I was aiming for making it as similar to the Ubuntu Unity color scheme, with a little bit of transparency for an added touch of modernity.&lt;/p&gt;

&lt;p&gt;Here’s my final adjusted Ubuntu profile:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nl&quot;&gt;&quot;profiles&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;acrylicOpacity&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;closeOnExit&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;colorScheme&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Ubuntu&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;commandline&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;wsl.exe -d Ubuntu-18.04&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;cursorColor&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#DCDFE4&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;cursorShape&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;filledBox&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;fontFace&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Ubuntu Mono&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;fontSize&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;guid&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;historySize&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9001&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;icon&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Ubuntu-18.04&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;padding&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;0, 0, 0, 0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;snapOnInput&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;useAcrylic&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;themes&quot;&gt;Themes&lt;/h3&gt;

&lt;p&gt;Themes are also one of the hottest features new to the Windows Terminal. While the antiquated Command Prompt did have some limited theming options, I always found it underwhelming and lacking in color displays. However, since it was so ingrained into my Windows instance, there was no choice but to use it - and I had to resort to flimsy&lt;/p&gt;

&lt;p&gt;If you want a profile to use with your Ubuntu instance, here are the settings I adapted from the &lt;a href=&quot;https://medium.com/@jgarijogarde/make-bash-on-ubuntu-on-windows-10-look-like-the-ubuntu-terminal-f7566008c5c2&quot;&gt;internet&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nl&quot;&gt;&quot;schemes&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;background&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#300A24&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;black&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#0C0C0C&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#729FCF&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightBlack&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#555753&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightBlue&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#61AFEF&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightCyan&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#34E2E2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightGreen&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#8AE234&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightPurple&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#AD7FA8&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightRed&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#EF2929&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightWhite&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#D3D7D9&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;brightYellow&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#FCE94F&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;cyan&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#06989A&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;foreground&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#EEEEEE&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#4E9A06&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Ubuntu&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;purple&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#AD7FA8&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#CC0000&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;white&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#DCDFE4&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;yellow&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;#C4A000&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;performance&quot;&gt;Performance&lt;/h1&gt;

&lt;p&gt;Because this is a pre-alpha release, I found several bugs that were quite finnicky and caused things to crash. Every time I closed all of the tabs in the terminal, a clear window would hang for several seconds before finally closing. Only the small white section in the top right allowed the window to be properly dragged as well, which gets a lot more irritating than you think after a while. The app would stop responding ever time I closed a PowerShell session, forcing me to lose all of my progress made in the other tabs of the window. And miscellaneously, I would experience flickers on the window and slow minmization, maximization, resizing, and moving of the windows. I truly would not recommend you to use Windows Terminal as your main terminal emulator just yet, but since it will be an Open Source Windows product, I’m confident that it will eventually become just as stable as your old-school CMD. That’s the struggles of being a bleeding-edge early adopter, however, and we sign up for this!&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;The Windows Terminal is definitely something I’m going to have to keep an eye on. I’m already using it little by little in my less important projects, and just to pull up &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;htop&lt;/code&gt; on my VPS instances to make sure that everything is running smoothly. My go-to for programming is still the VSCode terminal, but since that can’t pop out or be opened in a new window, it is still fairly difficult to integrate to a multi-monitor workflow. Thanks for reading, and happy coding!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Hot Take" /><category term="Windows Terminal" /><category term="Microsoft" /><category term="Ubuntu" /><summary type="html">It’s officially summertime, and with that comes the hottest-anticipated programming product for Windows users: the Windows Terminal! In this post, I’ll be running through my quick thoughts about it, and how it will be affecting my programming workflow, as well as the specific settings that I modified it to give it the “Carlos Way” touch. Preface The Windows Terminal is still in early alpha, and many of its features will be changing. This is definitely not anything near what the final product will look like, and shouldn’t be your final judgement on whether you should be using it or not. However, it does provide a good insight into what your workflow might look like if you end up using it, so it’s still worth a look! Interface The Windows Terminal with an active CMD tab. I’m actually quite pleased with how the terminal looks. Aside from a couple of design discrepancies, in my own opinion, the Windows Terminal is a huge improvement over the traditional command prompt, and has some impressive theming options that bring it to the 21st century. It has an optional, customizable transparency setting, which, just like the new Calculator app, glosses over the contents behind it in a sleek, modern style. It also has a nice, tabbed interface that reminds me more of a Google Chrome dark theme than a terminal interface. It has the ability to display emoji, and has hyperlinks you can click on, like the terminal in VSCode. Tabs One of the most acclaimed new features of the Windows Terminal, the tabbed interface is just that - the ability to have more than one instance within a Windows Terminal window. Unlike other terminal programs for Windows and Unix, however, the Windows Terminal allows tabs of different environments and operating systems within one window, a new feature I will be using greatly. When you click on the new tab button, a new tab from the default profile appears, but if you want to open a tab in another profile, you can select it from the dropdown button right next to it: The tabs selector is fully customizable with profiles in the settings menu. Every aspect of these dropdown options is able to be customized, from the titles and icons to the precise shell they are running. Your existing shells, both WSL and Microsoft, should be automatically populated, but they are easy to add if for some reason they have not been. Customization In my opinion, the customization process is probably what needs the most work so far. However, much to the style of Visual Studio Code, almost everything about the Windows Terminal can be customized. When clicking on the settings button in the dropdown, as shown above, you are met with a Visual Studio Code instance of the JSON settings file, and can edit it just as you would any other text file: The settings dialogue. While more hardened programmers will find this a possible positive change, more casual terminal users might find this slightly difficult to work with, especially those not so familiar with JSON. For my purposes, VSCode with a Color Info Plugin did an amazing job at letting me adjust theming and organize everything the way I needed it to. When opening the JSON file, your first relevant find will be all of the keybindings. I chose to leave them be for the time being, but it’s good to know that they’re all completely modular. Second, the list of profiles defines what kinds of tabs you can open: Profiles Profiles should be initially generated for you when you first install and run Windows Terminal. However, if you ever need to edit them to fit your specific needs - I adjusted the fontSize, cursorShape, and colorScheme to a custom scheme I created just for my Ubuntu instance, which you’ll see below. The settings are pretty self explanatory, but if you don’t know what you’re doing you probably don’t want to be prodding around and accidentally break your terminal. When designing my Ubuntu profile, I was aiming for making it as similar to the Ubuntu Unity color scheme, with a little bit of transparency for an added touch of modernity. Here’s my final adjusted Ubuntu profile: &quot;profiles&quot; : [ { &quot;acrylicOpacity&quot; : 0.75, &quot;closeOnExit&quot; : true, &quot;colorScheme&quot; : &quot;Ubuntu&quot;, &quot;commandline&quot; : &quot;wsl.exe -d Ubuntu-18.04&quot;, &quot;cursorColor&quot; : &quot;#DCDFE4&quot;, &quot;cursorShape&quot; : &quot;filledBox&quot;, &quot;fontFace&quot; : &quot;Ubuntu Mono&quot;, &quot;fontSize&quot; : 16, &quot;guid&quot; : &quot;{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}&quot;, &quot;historySize&quot; : 9001, &quot;icon&quot; : &quot;ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png&quot;, &quot;name&quot; : &quot;Ubuntu-18.04&quot;, &quot;padding&quot; : &quot;0, 0, 0, 0&quot;, &quot;snapOnInput&quot; : true, &quot;useAcrylic&quot; : true } ] Themes Themes are also one of the hottest features new to the Windows Terminal. While the antiquated Command Prompt did have some limited theming options, I always found it underwhelming and lacking in color displays. However, since it was so ingrained into my Windows instance, there was no choice but to use it - and I had to resort to flimsy If you want a profile to use with your Ubuntu instance, here are the settings I adapted from the internet: &quot;schemes&quot;: [ { &quot;background&quot; : &quot;#300A24&quot;, &quot;black&quot; : &quot;#0C0C0C&quot;, &quot;blue&quot; : &quot;#729FCF&quot;, &quot;brightBlack&quot; : &quot;#555753&quot;, &quot;brightBlue&quot; : &quot;#61AFEF&quot;, &quot;brightCyan&quot; : &quot;#34E2E2&quot;, &quot;brightGreen&quot; : &quot;#8AE234&quot;, &quot;brightPurple&quot; : &quot;#AD7FA8&quot;, &quot;brightRed&quot; : &quot;#EF2929&quot;, &quot;brightWhite&quot; : &quot;#D3D7D9&quot;, &quot;brightYellow&quot; : &quot;#FCE94F&quot;, &quot;cyan&quot; : &quot;#06989A&quot;, &quot;foreground&quot; : &quot;#EEEEEE&quot;, &quot;green&quot; : &quot;#4E9A06&quot;, &quot;name&quot; : &quot;Ubuntu&quot;, &quot;purple&quot; : &quot;#AD7FA8&quot;, &quot;red&quot; : &quot;#CC0000&quot;, &quot;white&quot; : &quot;#DCDFE4&quot;, &quot;yellow&quot; : &quot;#C4A000&quot; } ] Performance Because this is a pre-alpha release, I found several bugs that were quite finnicky and caused things to crash. Every time I closed all of the tabs in the terminal, a clear window would hang for several seconds before finally closing. Only the small white section in the top right allowed the window to be properly dragged as well, which gets a lot more irritating than you think after a while. The app would stop responding ever time I closed a PowerShell session, forcing me to lose all of my progress made in the other tabs of the window. And miscellaneously, I would experience flickers on the window and slow minmization, maximization, resizing, and moving of the windows. I truly would not recommend you to use Windows Terminal as your main terminal emulator just yet, but since it will be an Open Source Windows product, I’m confident that it will eventually become just as stable as your old-school CMD. That’s the struggles of being a bleeding-edge early adopter, however, and we sign up for this! Conclusion The Windows Terminal is definitely something I’m going to have to keep an eye on. I’m already using it little by little in my less important projects, and just to pull up htop on my VPS instances to make sure that everything is running smoothly. My go-to for programming is still the VSCode terminal, but since that can’t pop out or be opened in a new window, it is still fairly difficult to integrate to a multi-monitor workflow. Thanks for reading, and happy coding!</summary></entry><entry><title type="html">How to Monitor Your Program’s Status with Pushbullet</title><link href="https://blog.cgsphoto.com/quick%20tip/pushbullet/" rel="alternate" type="text/html" title="How to Monitor Your Program’s Status with Pushbullet" /><published>2019-06-18T00:00:00+00:00</published><updated>2019-06-18T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/quick%20tip/pushbullet</id><content type="html" xml:base="https://blog.cgsphoto.com/quick%20tip/pushbullet/">&lt;p&gt;&lt;a href=&quot;https://www.pushbullet.com/&quot;&gt;Pushbullet&lt;/a&gt; has always been a service essential to my tech life. It allows you to send and receive SMS messages from any android device within just about any internet-connected device, allows you to sync Android notifications with chrome or Windows, and even lets you easily transfer files to and from your phone and computer. I always knew Pushbullet had an API, but I’d never put two and two together to successfully make a notification system every time my Discord bot, Rikka, gets an error or restarts. In this quick tip, I’ll walk you through how I added Pushbullet notifications that notify me of the error, traceback, and timestamp.&lt;/p&gt;

&lt;h1 id=&quot;requirements&quot;&gt;Requirements&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Python 3&lt;/li&gt;
  &lt;li&gt;A Pushbullet account&lt;/li&gt;
  &lt;li&gt;Basic Knowledge of Python and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;setup&quot;&gt;Setup&lt;/h1&gt;

&lt;h2 id=&quot;python-installation&quot;&gt;Python Installation&lt;/h2&gt;

&lt;p&gt;First, install the Python module &lt;a href=&quot;https://github.com/rbrcsk/pushbullet.py&quot;&gt;Pushbullet.py&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;obtaining-the-pushbullet-api-key&quot;&gt;Obtaining the Pushbullet API Key&lt;/h2&gt;

&lt;p&gt;Then, you’ll need to get your API Key from Pushbullet. This is actually a really simple process.&lt;/p&gt;

&lt;p&gt;Navigate to your &lt;a href=&quot;https://www.pushbullet.com/#settings&quot;&gt;Pushbullet Settings&lt;/a&gt; and click on &lt;em&gt;Create Access Token&lt;/em&gt;. You’ll need to copy the key and save it somewhere.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/Pushbullet_Access_Key.JPG&quot; alt=&quot;&quot; /&gt;
&lt;i style=&quot;font-size:smaller&quot;&gt;The Pushbullet Access Key Token screen&lt;/i&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;pushbullet.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;quick-examples&quot;&gt;Quick Examples&lt;/h1&gt;

&lt;h2 id=&quot;pushing-text-notes&quot;&gt;Pushing Text Notes&lt;/h2&gt;

&lt;p&gt;In order to test your API key and make sure that everything works, you’ll first want to run a couple of tests in the python console.&lt;/p&gt;

&lt;p&gt;First, import Pushbullet and authenticate using the access key you got in the previous step:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pushbullet&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pushbullet&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pushbullet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;api_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, you can easily push a text note using:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_note&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Quick Tip&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;This is the best blog ever!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And, the output should show in your Pushbullet window, like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/push_example.JPG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;pushing-files&quot;&gt;Pushing Files&lt;/h2&gt;

&lt;p&gt;Pushing files is a bit of a more complex process, but it’s still really easy to learn!&lt;/p&gt;

&lt;p&gt;First, we’ll create a small text file and write something to it:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;touch &lt;/span&gt;hi.txt
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; hi.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, we’ll push it to Pushbullet:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hi.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Open the log as a file
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# and push it to yourself.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upload_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;hi.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should receive this in your Pushbullet:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/pb_file_test.JPG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you’ve gotten up to this point, you’re halfway there! Now, let’s look at how to fit this into our current programs.&lt;/p&gt;

&lt;h1 id=&quot;pushbullet-error-handling&quot;&gt;Pushbullet Error Handling&lt;/h1&gt;

&lt;h2 id=&quot;api-approach&quot;&gt;API Approach&lt;/h2&gt;

&lt;p&gt;Since my use case was with my Discord bot, &lt;a href=&quot;https://cgsphoto.com/rikka-bot/&quot;&gt;Rikka&lt;/a&gt;, I was able to use the &lt;a href=&quot;https://github.com/Rapptz/discord.py&quot;&gt;Discord.py API&lt;/a&gt; to find a function, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;on_error&lt;/code&gt;, that would catch all of the errors that occurred during the runtime of the program. When I overrode it, I was able to not only print the error to the console, but also create a text log with all of the errors, and notify myself:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;on_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Print out a message indicating there was an error.
&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error.txt for details...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# Print out any error details.
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Create or append to error log if it exits.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;a+&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;===== ERROR SUMMARY =====&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Add timestamp of the error occurring.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Timestamp: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d.%b %Y %H:%M:%S&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Write the exception that occurred.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Exception in {}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;===== TRACEBACK =====&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Print out the traceback of the error.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traceback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;# Once the file is created and all of the information
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# is printed, push it to Pushbullet.
&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Open the error log as a file
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# and push it to yourself.
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upload_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;push&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;try-catch-approach&quot;&gt;Try-Catch Approach&lt;/h2&gt;

&lt;p&gt;If you don’t have the fortune to be working with a great API that gives you an error-handling API, you can &lt;em&gt;sort of&lt;/em&gt; write one yourself by placing everything in a try-catch:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;yourFunctionHere&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Print out a message indicating there was an error.
&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error.txt for details...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ERROR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# Print out any error details.
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Create or append to error log if it exits.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;a+&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;===== ERROR SUMMARY =====&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Add timestamp of the error occurring.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Timestamp: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d.%b %Y %H:%M:%S&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Write the exception that occurred.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Exception in {}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;===== TRACEBACK =====&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Print out the traceback of the error.
&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traceback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;# Once the file is created and all of the information
&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# is printed, push it to Pushbullet.
&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Open the error log as a file
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# and push it to yourself.
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upload_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;error.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;push&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;No matter what approach you take, you should get a handy little file in your Pushbullet every time an error is thrown:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/push_error.JPG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;And that’s it! You’ve connected your Pushbullet account to your error handling in Python. Whether you’re a SysAdmin, or a bot developer like me, you will now be able to be notified whenever an error is caused, and get a nice text message with timestamp and a log to see what could have caused the problem. Since implementing this change, I have become much less paranoid, and now I can live my life knowing my code works in the background. Thanks for reading, and happy coding!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Quick Tip" /><category term="Python" /><category term="Tutorial" /><category term="Coding" /><summary type="html">Pushbullet has always been a service essential to my tech life. It allows you to send and receive SMS messages from any android device within just about any internet-connected device, allows you to sync Android notifications with chrome or Windows, and even lets you easily transfer files to and from your phone and computer. I always knew Pushbullet had an API, but I’d never put two and two together to successfully make a notification system every time my Discord bot, Rikka, gets an error or restarts. In this quick tip, I’ll walk you through how I added Pushbullet notifications that notify me of the error, traceback, and timestamp. Requirements Python 3 A Pushbullet account Basic Knowledge of Python and pip Setup Python Installation First, install the Python module Pushbullet.py. Obtaining the Pushbullet API Key Then, you’ll need to get your API Key from Pushbullet. This is actually a really simple process. Navigate to your Pushbullet Settings and click on Create Access Token. You’ll need to copy the key and save it somewhere. The Pushbullet Access Key Token screen pip install pushbullet.py Quick Examples Pushing Text Notes In order to test your API key and make sure that everything works, you’ll first want to run a couple of tests in the python console. First, import Pushbullet and authenticate using the access key you got in the previous step: from pushbullet import Pushbullet pb = Pushbullet(api_key) Now, you can easily push a text note using: pb.push_note(&quot;Quick Tip&quot;, &quot;This is the best blog ever!&quot;) And, the output should show in your Pushbullet window, like this: Pushing Files Pushing files is a bit of a more complex process, but it’s still really easy to learn! First, we’ll create a small text file and write something to it: touch hi.txt echo &quot;Hello World!&quot; &amp;gt; hi.txt Next, we’ll push it to Pushbullet: with open(&quot;hi.txt&quot;, &quot;r&quot;) as file: # Open the log as a file # and push it to yourself. file_data = pb.upload_file(file, &quot;hi.txt&quot;) pb.push_file(**file_data) You should receive this in your Pushbullet: If you’ve gotten up to this point, you’re halfway there! Now, let’s look at how to fit this into our current programs. Pushbullet Error Handling API Approach Since my use case was with my Discord bot, Rikka, I was able to use the Discord.py API to find a function, on_error, that would catch all of the errors that occurred during the runtime of the program. When I overrode it, I was able to not only print the error to the console, but also create a text log with all of the errors, and notify myself: @client.event async def on_error(self, event_method, *args, **kwargs): # Print out a message indicating there was an error. print(&quot;Error.txt for details...&quot;) print(file=sys.stderr) # Print out any error details. # Create or append to error log if it exits. f = open(&quot;error.txt&quot;, &quot;a+&quot;) f.write(&quot;===== ERROR SUMMARY =====\n&quot;) # Add timestamp of the error occurring. f.write(&quot;Timestamp: &quot; + str(datetime.datetime.now().strftime(&quot;%d.%b %Y %H:%M:%S&quot;)) + &quot;\n&quot;) # Write the exception that occurred. f.write(&quot;Exception in {}&quot;.format(event_method) + &quot;\n&quot;) f.write(&quot;===== TRACEBACK =====\n&quot;) # Print out the traceback of the error. f.write(traceback.format_exc() + &quot;\n\n&quot;) # Once the file is created and all of the information # is printed, push it to Pushbullet. with open(&quot;error.txt&quot;, &quot;r&quot;) as file: # Open the error log as a file # and push it to yourself. file_data = pb.upload_file(f, &quot;error.txt&quot;) push = pb.push_file(**file_data) Try-Catch Approach If you don’t have the fortune to be working with a great API that gives you an error-handling API, you can sort of write one yourself by placing everything in a try-catch: try: yourFunctionHere() except: # Print out a message indicating there was an error. print(&quot;Error.txt for details...&quot;, ERROR) print(file=sys.stderr) # Print out any error details. # Create or append to error log if it exits. f = open(&quot;error.txt&quot;, &quot;a+&quot;) f.write(&quot;===== ERROR SUMMARY =====\n&quot;) # Add timestamp of the error occurring. f.write(&quot;Timestamp: &quot; + str(datetime.datetime.now().strftime(&quot;%d.%b %Y %H:%M:%S&quot;)) + &quot;\n&quot;) # Write the exception that occurred. f.write(&quot;Exception in {}&quot;.format(event_method) + &quot;\n&quot;) f.write(&quot;===== TRACEBACK =====\n&quot;) # Print out the traceback of the error. f.write(traceback.format_exc() + &quot;\n\n&quot;) # Once the file is created and all of the information # is printed, push it to Pushbullet. with open(&quot;error.txt&quot;, &quot;r&quot;) as file: # Open the error log as a file # and push it to yourself. file_data = pb.upload_file(f, &quot;error.txt&quot;) push = pb.push_file(**file_data) No matter what approach you take, you should get a handy little file in your Pushbullet every time an error is thrown: Conclusion And that’s it! You’ve connected your Pushbullet account to your error handling in Python. Whether you’re a SysAdmin, or a bot developer like me, you will now be able to be notified whenever an error is caused, and get a nice text message with timestamp and a log to see what could have caused the problem. Since implementing this change, I have become much less paranoid, and now I can live my life knowing my code works in the background. Thanks for reading, and happy coding!</summary></entry><entry><title type="html">Java, The Carlos Way - Lesson 2</title><link href="https://blog.cgsphoto.com/java/lesson-2" rel="alternate" type="text/html" title="Java, The Carlos Way - Lesson 2" /><published>2019-06-11T00:00:00+00:00</published><updated>2019-06-11T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/java/java-2</id><content type="html" xml:base="https://blog.cgsphoto.com/java/lesson-2">&lt;p&gt;Welcome back to &lt;em&gt;Java, the Carlos Way&lt;/em&gt;! I hope my first lesson got your feet wet and your curiosity piqued enough to want to come back and learn some more. This time around, we’ll be going through some other basics, how to set up a development environment, and finally get your feet wet!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/java/lesson-1&quot;&gt;&lt;strong&gt;&lt;em&gt;Previous Lesson&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;your-first-java-program&quot;&gt;Your First Java Program&lt;/h1&gt;

&lt;p&gt;The time has finally come to program your first Java project. In the spirit of programming culture, the first program that we will write together will do a very simple thing: output the words &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hello World!&lt;/code&gt;. This is many programmers’ first code, and it will be yours in a very short amount of time.&lt;/p&gt;

&lt;p&gt;Try to follow along, not by copying and pasting, but by typing everything out. That way, you know exactly what you’re doing and you get a better feel for your programming environment.&lt;/p&gt;

&lt;p&gt;Let’s dive right in:&lt;/p&gt;

&lt;p&gt;Main.java&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// First, we declare the class Main.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Next, we declare the function, main, inside Main.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// &quot;void&quot; means that we will not be returning any values&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// At the conclusion of our function.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Next, we print out the words &quot;Hello World!&quot;.&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Always check your brackets and semicolons!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;more-java-101&quot;&gt;More Java 101&lt;/h1&gt;
&lt;p&gt;We’ll need to learn a little bit more about what we’re doing in order to understand the code that we just typed. Bear with me, there will be more code coming soon!&lt;/p&gt;

&lt;h2 id=&quot;java-data-types&quot;&gt;Java Data Types&lt;/h2&gt;

&lt;p&gt;In Java, information is stored in a variety of &lt;em&gt;types&lt;/em&gt;. a &lt;em&gt;type&lt;/em&gt; is like a container of storage, and a limited amount of information fits in each of the storage containers. You want to be as storage-efficient as possible, so you’ll choose a smaller container if possible, if you know that your information won’t take up that much space, which makes your code faster and more efficient.&lt;/p&gt;

&lt;p&gt;There are a lot of data types in Java, but I’ll just go through the most popular ones:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Integer&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Boolean&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;notice&quot;&gt;
&lt;p&gt;&lt;strong&gt;Quick Tip:&lt;/strong&gt; Integers can be written as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt; interchangeably, which is why you’ll often see me substitute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Integer&lt;/code&gt;!&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;string&quot;&gt;String&lt;/h3&gt;

&lt;p&gt;A string is a datatype that represents an array of characters. These characters can be anything, from numbers, to letters, to emoji. Strings in Java are very powerful, and have many embedded functions that allow you to perform many operations. I often find myself casting (converting) other data types to Strings in order to perform specific operations on them, like getting the number of digits in a certain number, or getting the last &lt;em&gt;n&lt;/em&gt; digits of a number/decimal. A drawback of this data type is that it takes up lots of memory space, and inability to perform arithmetic.&lt;/p&gt;

&lt;h3 id=&quot;integer&quot;&gt;Integer&lt;/h3&gt;
&lt;p&gt;An integer is a much more lean data type, sitting at only 4 bytes. This means, of course, that it can store values from -2,147,483,648 to 2,147,483,647 -  which, for most cases, should be enough for any numerical value. This data type contains all of the operations you think you’ll need, such as addition, subtraction, multiplication, and division.&lt;/p&gt;

&lt;h3 id=&quot;double&quot;&gt;Double&lt;/h3&gt;
&lt;p&gt;A double is very similar to an Integer, but it holds twice as many bytes (8). While this is more storage, and will take up more RAM, doubles have a unique capability - to store decimal values. Because it is impossible to store &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.5&lt;/code&gt; into an Integer, the most used data type for this kind of value is a double.&lt;/p&gt;

&lt;h3 id=&quot;boolean&quot;&gt;Boolean&lt;/h3&gt;
&lt;p&gt;Perhaps the most useful data type is the Java boolean. This grants the ability to store binary values, namely &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;False&lt;/code&gt;. You’ll be using these a lot of the time without even declaring them, as many functions in Java return a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True&lt;/code&gt; when an operation is successfully completed.&lt;/p&gt;

&lt;h3 id=&quot;other-types&quot;&gt;Other Types&lt;/h3&gt;
&lt;p&gt;There are many other types that you might find yourself using when you become a more successful programmer and want to worry about memory allocation, such as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;short&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;long&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, the classes you write yourself act just like data types, which you will learn more about later on. When we make functions, we will also be employing data types, as we can return them at the conclusion of our functions.&lt;/p&gt;

&lt;h2 id=&quot;declaring-variables&quot;&gt;Declaring variables&lt;/h2&gt;
&lt;p&gt;Now that we know all about data types and what they store, let’s look into how to create them and use them in our code.&lt;/p&gt;

&lt;p&gt;The general structure for declaring variables is as follows:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;datatype&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;variableName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;datatype&lt;/code&gt; is the name of the datatype we are declaring.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;variableName&lt;/code&gt; is the name of the variable that we will be using in the rest of our code.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt; is the actual value being stored inside of the variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s go through an actual example that we can use to rewrite our “Hello World” program:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// We declare a new String called message that stores&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// the value &quot;Hello World!&quot;&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// We print out the message instead of the text.&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: Hello World!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As you can see, the output is the exact same, but this time, we created a variable and printed it out instead of placing the content of the message inside of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.out.println();&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;casting-between-data-types&quot;&gt;Casting Between Data Types&lt;/h2&gt;
&lt;p&gt;Oftentimes you’ll find yourself wanting to convert between data types, such as from integers to Strings, as mentioned &lt;a href=&quot;#string&quot;&gt;above&lt;/a&gt;, or between more abstract data types to Strings in order to visualize them easily. The process of converting a variable from one data type to another is called &lt;strong&gt;Casting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The general format of casting from one type to another is as follows:&lt;/p&gt;

&lt;p&gt;There are two kinds of casting:&lt;/p&gt;

&lt;h3 id=&quot;lossless-casting&quot;&gt;Lossless Casting&lt;/h3&gt;
&lt;p&gt;Lossless casting is casting in which no information is lost. When an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Integer&lt;/code&gt; is converted into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt;, no information is lost, because all of the integer’s values can be placed within the double. Here’s an example of that process:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
We first declare the variable, &quot;num&quot; as an integer,
and assign the value of 420.
**/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;420&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// We print out the value that we just created.&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output at this point: 420&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
We create a new double, &quot;dec&quot;, and cast &quot;num&quot; to &quot;dec&quot;.
**/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// We print out &quot;dec&quot;.&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: 420.00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As you can see, no information is lost, because doubles can hold any and all values of integers.&lt;/p&gt;

&lt;h3 id=&quot;lossy-casting&quot;&gt;Lossy Casting&lt;/h3&gt;
&lt;p&gt;Lossy casting involves converting an object of greater data capacity into one with less data capacity. For example, the reverse of the previous example would be considered a lossy cast, because a double is 8 bytes and an integer is 4 bytes, and information could be lost. Let’s show an example:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;420.69&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: 420.69&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Information is lost because integers do not have decimals.&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: 420&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the above example, you can see that the new integer we created did not have the decimal value that was after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;420&lt;/code&gt;. It is important to remember that this occurs so that you will not make any mistakes in math or your code in general!&lt;/p&gt;

&lt;div class=&quot;notice&quot;&gt;
&lt;p&gt;&lt;strong&gt;Quick Tip:&lt;/strong&gt; By default and when casting, Java does &lt;em&gt;NOT&lt;/em&gt; round up or down. It truncates, which means it just chops off whatever information it needs to from the numerical value.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;automatic-casting&quot;&gt;Automatic Casting&lt;/h3&gt;
&lt;p&gt;Since lossless casting does not result in the loss of information, Java will do it automatically, if prompted for a datatype that is higher in storage than the one that is given. This actually happens all the time, most importantly for beginners when we use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.out.println();&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 11 is being casted to a String and then printed out.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: 11&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.out.println();&lt;/code&gt; takes in a String as its parameter (the variable between the parentheses), Java automatically casts the integer to a String and then uses it as-is. This will also work with doubles, and the other data types I mentioned.&lt;/p&gt;

&lt;h3 id=&quot;tostring&quot;&gt;toString&lt;/h3&gt;
&lt;p&gt;Another form of automatic casting is what is called the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toString()&lt;/code&gt; function. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toString()&lt;/code&gt; is a function that is embedded by default in all classes, and is actually what is being called in the function above, and whenever we convert any of the default data type into a String. When we write a Class, which you will be doing a lot of later, you will also have the opportunity to write your own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toString()&lt;/code&gt; function, and with that, you’ll be able to easily write text outputs for your functions.&lt;/p&gt;

&lt;p&gt;Let’s try an example of a type that already exists though:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Num is declared as an integer.&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;420&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// It is converted into a string with toString.&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// A string is printed out.&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Output: 420&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;summary&quot;&gt;Summary&lt;/h1&gt;
&lt;p&gt;In this lesson, you learned:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The standard &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Hello World!&quot;&lt;/code&gt; Java program&lt;/li&gt;
  &lt;li&gt;Basic Java data types&lt;/li&gt;
  &lt;li&gt;How to print things to the Java console&lt;/li&gt;
  &lt;li&gt;Casting (Converting between data types)
    &lt;ul&gt;
      &lt;li&gt;Lossy Casting (Data is lost)&lt;/li&gt;
      &lt;li&gt;Lossless Casting (No data is lost)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Automatic casting&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toString&lt;/code&gt; function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next time, we’ll go into creating Java projects in my favorite editor, VSCode, logical statements, and basic inheritance. Stay tuned!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Java" /><category term="Java" /><category term="Tutorial" /><category term="Coding" /><summary type="html">Welcome back to Java, the Carlos Way! I hope my first lesson got your feet wet and your curiosity piqued enough to want to come back and learn some more. This time around, we’ll be going through some other basics, how to set up a development environment, and finally get your feet wet! Previous Lesson Your First Java Program The time has finally come to program your first Java project. In the spirit of programming culture, the first program that we will write together will do a very simple thing: output the words Hello World!. This is many programmers’ first code, and it will be yours in a very short amount of time. Try to follow along, not by copying and pasting, but by typing everything out. That way, you know exactly what you’re doing and you get a better feel for your programming environment. Let’s dive right in: Main.java // First, we declare the class Main. public class Main{ // Next, we declare the function, main, inside Main. // &quot;void&quot; means that we will not be returning any values // At the conclusion of our function. public static void main(String[] args){ // Next, we print out the words &quot;Hello World!&quot;. System.out.println(&quot;Hello World!&quot;); } } // Always check your brackets and semicolons! More Java 101 We’ll need to learn a little bit more about what we’re doing in order to understand the code that we just typed. Bear with me, there will be more code coming soon! Java Data Types In Java, information is stored in a variety of types. a type is like a container of storage, and a limited amount of information fits in each of the storage containers. You want to be as storage-efficient as possible, so you’ll choose a smaller container if possible, if you know that your information won’t take up that much space, which makes your code faster and more efficient. There are a lot of data types in Java, but I’ll just go through the most popular ones: String Integer Double Boolean Quick Tip: Integers can be written as int interchangeably, which is why you’ll often see me substitute int for Integer! String A string is a datatype that represents an array of characters. These characters can be anything, from numbers, to letters, to emoji. Strings in Java are very powerful, and have many embedded functions that allow you to perform many operations. I often find myself casting (converting) other data types to Strings in order to perform specific operations on them, like getting the number of digits in a certain number, or getting the last n digits of a number/decimal. A drawback of this data type is that it takes up lots of memory space, and inability to perform arithmetic. Integer An integer is a much more lean data type, sitting at only 4 bytes. This means, of course, that it can store values from -2,147,483,648 to 2,147,483,647 - which, for most cases, should be enough for any numerical value. This data type contains all of the operations you think you’ll need, such as addition, subtraction, multiplication, and division. Double A double is very similar to an Integer, but it holds twice as many bytes (8). While this is more storage, and will take up more RAM, doubles have a unique capability - to store decimal values. Because it is impossible to store 1.5 into an Integer, the most used data type for this kind of value is a double. Boolean Perhaps the most useful data type is the Java boolean. This grants the ability to store binary values, namely True or False. You’ll be using these a lot of the time without even declaring them, as many functions in Java return a True when an operation is successfully completed. Other Types There are many other types that you might find yourself using when you become a more successful programmer and want to worry about memory allocation, such as: short long float Additionally, the classes you write yourself act just like data types, which you will learn more about later on. When we make functions, we will also be employing data types, as we can return them at the conclusion of our functions. Declaring variables Now that we know all about data types and what they store, let’s look into how to create them and use them in our code. The general structure for declaring variables is as follows: datatype variableName = value datatype is the name of the datatype we are declaring. variableName is the name of the variable that we will be using in the rest of our code. value is the actual value being stored inside of the variable. Now, let’s go through an actual example that we can use to rewrite our “Hello World” program: public class Main{ public static void main(String[] args){ // We declare a new String called message that stores // the value &quot;Hello World!&quot; String message = &quot;Hello World!&quot;; // We print out the message instead of the text. System.out.println(message); } } // Output: Hello World! As you can see, the output is the exact same, but this time, we created a variable and printed it out instead of placing the content of the message inside of System.out.println(); Casting Between Data Types Oftentimes you’ll find yourself wanting to convert between data types, such as from integers to Strings, as mentioned above, or between more abstract data types to Strings in order to visualize them easily. The process of converting a variable from one data type to another is called Casting. The general format of casting from one type to another is as follows: There are two kinds of casting: Lossless Casting Lossless casting is casting in which no information is lost. When an Integer is converted into a Double, no information is lost, because all of the integer’s values can be placed within the double. Here’s an example of that process: /** We first declare the variable, &quot;num&quot; as an integer, and assign the value of 420. **/ int num = 420; // We print out the value that we just created. System.out.println(num); // Output at this point: 420 /** We create a new double, &quot;dec&quot;, and cast &quot;num&quot; to &quot;dec&quot;. **/ double dec = (double)num; // We print out &quot;dec&quot;. System.out.println(dec); // Output: 420.00 As you can see, no information is lost, because doubles can hold any and all values of integers. Lossy Casting Lossy casting involves converting an object of greater data capacity into one with less data capacity. For example, the reverse of the previous example would be considered a lossy cast, because a double is 8 bytes and an integer is 4 bytes, and information could be lost. Let’s show an example: double dec = 420.69; System.out.println(dec); // Output: 420.69 // Information is lost because integers do not have decimals. int num = (int)dec; System.out.println(num); // Output: 420 In the above example, you can see that the new integer we created did not have the decimal value that was after 420. It is important to remember that this occurs so that you will not make any mistakes in math or your code in general! Quick Tip: By default and when casting, Java does NOT round up or down. It truncates, which means it just chops off whatever information it needs to from the numerical value. Automatic Casting Since lossless casting does not result in the loss of information, Java will do it automatically, if prompted for a datatype that is higher in storage than the one that is given. This actually happens all the time, most importantly for beginners when we use System.out.println();. For instance: System.out.println(11); // 11 is being casted to a String and then printed out. // Output: 11 Since System.out.println(); takes in a String as its parameter (the variable between the parentheses), Java automatically casts the integer to a String and then uses it as-is. This will also work with doubles, and the other data types I mentioned. toString Another form of automatic casting is what is called the toString() function. toString() is a function that is embedded by default in all classes, and is actually what is being called in the function above, and whenever we convert any of the default data type into a String. When we write a Class, which you will be doing a lot of later, you will also have the opportunity to write your own toString() function, and with that, you’ll be able to easily write text outputs for your functions. Let’s try an example of a type that already exists though: // Num is declared as an integer. int num = 420; // It is converted into a string with toString. String numString = num.toString(); // A string is printed out. System.out.println(numString); // Output: 420 Summary In this lesson, you learned: The standard &quot;Hello World!&quot; Java program Basic Java data types How to print things to the Java console Casting (Converting between data types) Lossy Casting (Data is lost) Lossless Casting (No data is lost) Automatic casting The toString function Next time, we’ll go into creating Java projects in my favorite editor, VSCode, logical statements, and basic inheritance. Stay tuned!</summary></entry><entry><title type="html">10 VSCode Extensions Every CS Student Needs</title><link href="https://blog.cgsphoto.com/top%2010/vscode-plugins/" rel="alternate" type="text/html" title="10 VSCode Extensions Every CS Student Needs" /><published>2019-06-05T00:00:00+00:00</published><updated>2019-06-05T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/top%2010/vscode-plugins</id><content type="html" xml:base="https://blog.cgsphoto.com/top%2010/vscode-plugins/">&lt;p&gt;Are you a Computer Science student that’s just starting to kick off their interest for programming, or just downloaded VSCode because the code editor you were taught before college was last updated in the 90’s? No matter your situation, these Visual Studio Code extensions will get your feet wet in this new, futuristic IDE, and impress your fellow students.&lt;/p&gt;

&lt;h2 id=&quot;10-material-theme&quot;&gt;10. Material Theme&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://material-theme.site/images/screens.jpg&quot; alt=&quot;Material Theme&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
These days, it seems like there’s an infinite amount of theme extensions for Visual Studio. Personally, I think the default dark theme is quite nice, but after a couple of months of programming I found myself wanting a little bit of a darker theme. Enter Material Theme. Right off the bat, it has several color schemes, and allows you to switch between them from a quick switch of the command palette, as well as select an accent color. The current configuration I’m using involves the base high contrast dark theme, with several settings changed within &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;editor.tokenColorCustomizations&lt;/code&gt; to make it exactly the way I want it to be. Whether you want to heavily edit your theme, or just want something that looks great right off the bat, Material Theme is your best bet.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://material-theme.site/&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Material Theme&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;9-code-spell-checker&quot;&gt;9. Code Spell Checker&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/streetsidesoftware/vscode-spell-checker/master/packages/client/images/example.gif&quot; alt=&quot;Code Spell Checker&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Ever spill hours into your code without knowing what’s wrong, until you realize you spelled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message&lt;/code&gt; as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mesage&lt;/code&gt; in one part of code, which subsequently broke everything else? Code spell checker aims to prevent just that. It has support for multiple languages, and even allows you to have a custom dictionary for things like your last name or custom product names. It’s simple and straight to the point, but I don’t know what I would do without it (especially considering I blog inside of VSCode!)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Code Spell Checker&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;8-rainbow-brackets&quot;&gt;8. Rainbow Brackets&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn.shopify.com/s/files/1/0533/2089/files/the-best-vscode-extensions-2017-rainbow-brackets.gif?v=1504615078&quot; alt=&quot;Rainbow Brackets&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Gone are the days of having to count each bracket to make sure you have an even number, or trying to figure out which set of brackets is which. With Rainbow Brackets, you’ll instantly color your IDE with each pair of brackets and parentheses you employ in your code. I can’t say how much of a difference this lone extension has made in my development process - and I hope that you can have the same experience as well!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Rainbow Brackets&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;7-indent-rainbow&quot;&gt;7. indent-rainbow&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://i.ytimg.com/vi/dlq62ALmLJI/maxresdefault.jpg&quot; alt=&quot;indent-rainbow&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Following the vein of making our code editor colorful, another essential extension to my development process is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indent-rainbow&lt;/code&gt;. This is also one of the extensions I installed early on in the beginning, and completely forgot that it was an optional extension because of how essential it became to my workflow. Especially when working with spaces for indentation, this extension will come in handy in telling you when you’re not using the correct number of spaces for a line, or to see whether you’re inside of a particular coding block when programming in an indentation-aware language, like Python.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow&quot;&gt;&lt;strong&gt;&lt;em&gt;Download indent-rainbow&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;6-prettier---code-formatter&quot;&gt;6. Prettier - Code formatter&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://www.wisdomgeek.com/wp-content/uploads/2018/02/prettier-730x410.png&quot; alt=&quot;Prettier&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Prettier is one of the extensions that I didn’t know I was going to need when I switched over to VSCode from Eclipse and IntelliJ IDEA. Sometimes different programmers have completely distinct formatting preferences, and Prettier is an extension that aims to fix the problem in the best way. Instead of forcing you to follow a particular syntax, Prettier will standardize your language’s formatting with a simple right click command once you’re done programming. This is definitely useful when programming on a GitHub repo with a team or just to fix programming errors to make your code look a lot more professional. Give it a shot - you never know when it might come in a pinch!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Prettier - Code formatter&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;5-vim&quot;&gt;5. Vim&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/74th/vscode-vim/master/tutorial/tutorial1.gif&quot; alt=&quot;Vim&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Now, this sounds like an unconventional addition to the list, doesn’t it? Hear me out – using a mouse/touchpad is boring. Why not use decades’ old technology anew and navigate the entirety of your code editor with your keyboard! I stumbled upon this extension when I was learning Unix editors for class, and figured I’d kill two birds with one stone and practice my Vim skills while doing my other programming work. Pretty neat, huh? If you like Vim (Which is admittedly pretty rare nowadays), be sure to check it out!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=vscodevim.vim&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Vim&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;4-discord-presence&quot;&gt;4. Discord Presence&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://i.ytimg.com/vi/ROzDbK1gA4k/maxresdefault.jpg&quot; alt=&quot;Discord Presence&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
This extension, while not necessarily falling into the “productivity” category, is definitely interesting to use, because I am a frequent user of Discord. Where this extension comes in handy is that it will actually fill in your discord presence indicator to show what project you’re working on, how much time you have elapsed on it, and more, with a highly customizable interface. Definitely give it a try if you’d like to show how much of a dedicated programmer you are to your Discord friends!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=icrawl.discord-vscode&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Discord Presence&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;3-vscode-spotify&quot;&gt;3. vscode-spotify&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/1106995/49531873-38aefc00-f889-11e8-9fbf-69f8dbc28849.png&quot; alt=&quot;vscode-spotify&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
When I discovered that this extension existed, I realized that VSCode was not a code editor do be reckoned with. If programmers are able to implement every feature you’ve never thought of, even an in-editor Spotify controller, then it’s definitely something worth giving a shot. Ever since I downloaded one of the first public versions of this extension, I’ve never gone back. when “in the zone”, you don’t want to be held back and waste precious seconds by having to tab into your Spotify player to change the song. Instead, you can do so through your handy status bar in the bottom of the editor. Better yet: be a pro and assign music controls to commands using your keybinding settings. Give it a try and never tab out for music again!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=shyykoserhiy.vscode-spotify&quot;&gt;&lt;strong&gt;&lt;em&gt;Download vscode-spotify&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;2-better-comments&quot;&gt;2. Better Comments&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://github.com/aaron-bond/better-comments/raw/master/images/better-comments.PNG&quot; alt=&quot;Better Comments&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
Now nearing towards the end of our list, come some of the most remarkably useful extensions that VSCode has. Enter better comments. Ever want to distinguish your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TODO&lt;/code&gt; comments, your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEBUG&lt;/code&gt;s, or more? Look no further than this extension! It is completely customizable to fit any colors you want to use, and has extremely useful functions such as displaying commented out code as crossed out and greyed out so you can focus on what matters. This one is worth digging into its configurations for, however - so don’t hesitate to get your hands dirty in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Better Comments&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;1-code-runner&quot;&gt;1. Code Runner&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://github.com/formulahendry/vscode-code-runner/raw/master/images/usage.gif&quot; alt=&quot;Code Runner&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;
One of the biggest drawbacks I initially experienced when making the switch from traditional IDEs to the more “text-editor” style VSCode was the ability to click run, or use a quick keybinding to run my current program. This was actually something that prevented me from making the switch to VSCode for an entire year, after my colleagues repeatedly suggested using it, but were not able to respond how to run code in place without having to open a terminal. Code Runner is also extremely customizable, and supports both WSL and the Command Prompt, regardless of your desired programming environment. It also supports practically any language you’ll be programming in. You are supplied with several commands in the command palette, and also a run button on the top right of your editor to run your code when the language is supported, which incredibly speeds up debug and testing time. Give it a try!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner&quot;&gt;&lt;strong&gt;&lt;em&gt;Download Code Runner&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I hope you’ve found these extensions to be useful. All of these are extensions I inevitably find myself using every single day I program, and hope you are able to make your programming experience more pleasurable and easier through these and other extensions. Let me know in the comments below if you have any extension recommendations, I’m always excited to try to find new workflows for my code editor!&lt;/p&gt;

&lt;p&gt;Until next time!&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Top 10" /><category term="VSCode" /><summary type="html">Are you a Computer Science student that’s just starting to kick off their interest for programming, or just downloaded VSCode because the code editor you were taught before college was last updated in the 90’s? No matter your situation, these Visual Studio Code extensions will get your feet wet in this new, futuristic IDE, and impress your fellow students. 10. Material Theme These days, it seems like there’s an infinite amount of theme extensions for Visual Studio. Personally, I think the default dark theme is quite nice, but after a couple of months of programming I found myself wanting a little bit of a darker theme. Enter Material Theme. Right off the bat, it has several color schemes, and allows you to switch between them from a quick switch of the command palette, as well as select an accent color. The current configuration I’m using involves the base high contrast dark theme, with several settings changed within editor.tokenColorCustomizations to make it exactly the way I want it to be. Whether you want to heavily edit your theme, or just want something that looks great right off the bat, Material Theme is your best bet. Download Material Theme 9. Code Spell Checker Ever spill hours into your code without knowing what’s wrong, until you realize you spelled message as mesage in one part of code, which subsequently broke everything else? Code spell checker aims to prevent just that. It has support for multiple languages, and even allows you to have a custom dictionary for things like your last name or custom product names. It’s simple and straight to the point, but I don’t know what I would do without it (especially considering I blog inside of VSCode!) Download Code Spell Checker 8. Rainbow Brackets Gone are the days of having to count each bracket to make sure you have an even number, or trying to figure out which set of brackets is which. With Rainbow Brackets, you’ll instantly color your IDE with each pair of brackets and parentheses you employ in your code. I can’t say how much of a difference this lone extension has made in my development process - and I hope that you can have the same experience as well! Download Rainbow Brackets 7. indent-rainbow Following the vein of making our code editor colorful, another essential extension to my development process is indent-rainbow. This is also one of the extensions I installed early on in the beginning, and completely forgot that it was an optional extension because of how essential it became to my workflow. Especially when working with spaces for indentation, this extension will come in handy in telling you when you’re not using the correct number of spaces for a line, or to see whether you’re inside of a particular coding block when programming in an indentation-aware language, like Python. Download indent-rainbow 6. Prettier - Code formatter Prettier is one of the extensions that I didn’t know I was going to need when I switched over to VSCode from Eclipse and IntelliJ IDEA. Sometimes different programmers have completely distinct formatting preferences, and Prettier is an extension that aims to fix the problem in the best way. Instead of forcing you to follow a particular syntax, Prettier will standardize your language’s formatting with a simple right click command once you’re done programming. This is definitely useful when programming on a GitHub repo with a team or just to fix programming errors to make your code look a lot more professional. Give it a shot - you never know when it might come in a pinch! Download Prettier - Code formatter 5. Vim Now, this sounds like an unconventional addition to the list, doesn’t it? Hear me out – using a mouse/touchpad is boring. Why not use decades’ old technology anew and navigate the entirety of your code editor with your keyboard! I stumbled upon this extension when I was learning Unix editors for class, and figured I’d kill two birds with one stone and practice my Vim skills while doing my other programming work. Pretty neat, huh? If you like Vim (Which is admittedly pretty rare nowadays), be sure to check it out! Download Vim 4. Discord Presence This extension, while not necessarily falling into the “productivity” category, is definitely interesting to use, because I am a frequent user of Discord. Where this extension comes in handy is that it will actually fill in your discord presence indicator to show what project you’re working on, how much time you have elapsed on it, and more, with a highly customizable interface. Definitely give it a try if you’d like to show how much of a dedicated programmer you are to your Discord friends! Download Discord Presence 3. vscode-spotify When I discovered that this extension existed, I realized that VSCode was not a code editor do be reckoned with. If programmers are able to implement every feature you’ve never thought of, even an in-editor Spotify controller, then it’s definitely something worth giving a shot. Ever since I downloaded one of the first public versions of this extension, I’ve never gone back. when “in the zone”, you don’t want to be held back and waste precious seconds by having to tab into your Spotify player to change the song. Instead, you can do so through your handy status bar in the bottom of the editor. Better yet: be a pro and assign music controls to commands using your keybinding settings. Give it a try and never tab out for music again! Download vscode-spotify 2. Better Comments Now nearing towards the end of our list, come some of the most remarkably useful extensions that VSCode has. Enter better comments. Ever want to distinguish your TODO comments, your DEBUGs, or more? Look no further than this extension! It is completely customizable to fit any colors you want to use, and has extremely useful functions such as displaying commented out code as crossed out and greyed out so you can focus on what matters. This one is worth digging into its configurations for, however - so don’t hesitate to get your hands dirty in config.json! Download Better Comments 1. Code Runner One of the biggest drawbacks I initially experienced when making the switch from traditional IDEs to the more “text-editor” style VSCode was the ability to click run, or use a quick keybinding to run my current program. This was actually something that prevented me from making the switch to VSCode for an entire year, after my colleagues repeatedly suggested using it, but were not able to respond how to run code in place without having to open a terminal. Code Runner is also extremely customizable, and supports both WSL and the Command Prompt, regardless of your desired programming environment. It also supports practically any language you’ll be programming in. You are supplied with several commands in the command palette, and also a run button on the top right of your editor to run your code when the language is supported, which incredibly speeds up debug and testing time. Give it a try! Download Code Runner Conclusion I hope you’ve found these extensions to be useful. All of these are extensions I inevitably find myself using every single day I program, and hope you are able to make your programming experience more pleasurable and easier through these and other extensions. Let me know in the comments below if you have any extension recommendations, I’m always excited to try to find new workflows for my code editor! Until next time!</summary></entry><entry><title type="html">Java, The Carlos Way - Lesson 1</title><link href="https://blog.cgsphoto.com/java/lesson-1" rel="alternate" type="text/html" title="Java, The Carlos Way - Lesson 1" /><published>2019-06-04T00:00:00+00:00</published><updated>2019-06-04T00:00:00+00:00</updated><id>https://blog.cgsphoto.com/java/java-1</id><content type="html" xml:base="https://blog.cgsphoto.com/java/lesson-1">&lt;p&gt;Welcome to &lt;em&gt;Java, the Carlos Way!&lt;/em&gt; Over the course of this series, I’m going to try to teach you Java in the easiest way possible. There’s a lot of content, so be sure to take things slowly and at your own pace. I’ll do my best to link to a lot of different tutorials for more in-depth review. Now that I’ve got your attention, let’s get started!&lt;/p&gt;

&lt;h2 id=&quot;why-this-exists&quot;&gt;Why This Exists&lt;/h2&gt;
&lt;p&gt;When I was 12 years old, I decided to tackle my first programming language, Python. I did so without any prior knowledge, without any formal textbooks or teachers: completely on my own. In the same way that I was able to learn from volunteers for free and on blogs and YouTube sites from people around the world, so too I want to impart my knowledge. I hope you are able to learn a great deal from this, and if you do, please consider passing on what you learn as a programmer. Soon, we will make the world full of people who know programming!&lt;/p&gt;

&lt;p&gt;Now, let’s get started…&lt;/p&gt;

&lt;h1 id=&quot;java-101-the-boring-stuff&quot;&gt;Java 101 (The Boring Stuff)&lt;/h1&gt;

&lt;hr /&gt;

&lt;p&gt;I call this “The Boring Stuff” because I know you want to get dirty with code! However, there are some central things you must understand before jumping into a development environment and writing code…&lt;/p&gt;

&lt;h2 id=&quot;what-is-oop&quot;&gt;What Is OOP?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;OOP&lt;/strong&gt;, or &lt;a href=&quot;https://en.wikipedia.org/wiki/Object-oriented_programming&quot;&gt;Object Oriented Programming&lt;/a&gt;, is a method of programming in which a programmer writes &lt;strong&gt;classes&lt;/strong&gt;, and &lt;strong&gt;functions&lt;/strong&gt; for those classes, and develops a hierarchical structure in order to achieve his or her programming goals. There are many different programming languages: Python, Java, C++, and more, and each has their own separate use case. Java is primarily used for developing &lt;strong&gt;cross-platform&lt;/strong&gt; applications, or programs that can run on more than one system, such as Android, Windows, Mac, and iOS.&lt;/p&gt;

&lt;h3 id=&quot;the-java-hierarchy&quot;&gt;The Java Hierarchy&lt;/h3&gt;
&lt;p&gt;In Java, as well as in other programming languages, there is a general hierarchy that dictates the way we use the language.&lt;/p&gt;

&lt;p&gt;I have created a handy diagram in order to illustrate the Java Hierarchy:
&lt;img src=&quot;https://github.com/LeoSaucedo/blog/raw/master/assets/images/TheJavaHierarchy.png&quot; alt=&quot;The Java Hierarchy.&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;levels-of-hierarchy&quot;&gt;Levels of Hierarchy&lt;/h4&gt;
&lt;p&gt;The levels of hierarchy go as follows:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Packages
    &lt;ul&gt;
      &lt;li&gt;A package is the highest level that can be imported into a Java program. Some of the most popular Java packages are:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.util&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.lang&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Every class in Java is contained into packages.&lt;/li&gt;
      &lt;li&gt;It is possible to create your own package when designing a project, but this is only recommended when it is a very big project and requires developing entire classes from scratch.&lt;/li&gt;
      &lt;li&gt;Package names are denoted by a lowercase letter.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Classes
    &lt;ul&gt;
      &lt;li&gt;Classes are contained within packages, and are usually the most often written by programmers when designing a program.&lt;/li&gt;
      &lt;li&gt;Some popular Java classes are:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.lang.Math&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.util.Random&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Class names should begin with a capital letter.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Objects
    &lt;ul&gt;
      &lt;li&gt;Objects are what we call &lt;em&gt;instances&lt;/em&gt; of a class, in which one &lt;em&gt;instantiates&lt;/em&gt; a class in order to use it in our program. Instantiating is like “materializing” it, and allows us to use its member functions/variables.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Code (Functions and Variables)
    &lt;ul&gt;
      &lt;li&gt;Inside of every class lie functions and variables that are relevant to its name. Though there may be many &lt;em&gt;instances&lt;/em&gt; of a single class, it is these member functions and variables that separate them from each other.&lt;/li&gt;
      &lt;li&gt;Member functions use &lt;em&gt;camelCase&lt;/em&gt;, which will be explained later.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;the-java-api&quot;&gt;The Java API&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.oracle.com/en/java/javase/11/docs/api/index.html&quot;&gt;The Java API&lt;/a&gt; is the number one website you’ll be referencing and bookmarking throughout your studies. It contains the list of all of the packages, classes, objects, and methods that are embedded into the base version of Java that is shipped onto millions of devices. Few languages have as good a documentation as Java, which is why it’s a favorite for many programmers.&lt;/p&gt;

&lt;h2 id=&quot;syntax&quot;&gt;Syntax&lt;/h2&gt;
&lt;p&gt;What distinguishes Java from any other language its &lt;em&gt;syntax&lt;/em&gt;. Just like any written language, programming languages each have their own set of syntax, and to learn the syntax by heart and to be able to use it seamlessly is truly to &lt;strong&gt;know&lt;/strong&gt; the programming language. There are two categories to programming syntax:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Syntax that the language interprets.
    &lt;ul&gt;
      &lt;li&gt;This has to be exact, or else the computer will not know what telling it to do.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Syntax that is used by programmers to make it readable to other programmers.
    &lt;ul&gt;
      &lt;li&gt;This is not technically necessary, but a good programmer will always use common programming conventions.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this course, we’ll be going over both of these.&lt;/p&gt;

&lt;h3 id=&quot;camelcase&quot;&gt;CamelCase&lt;/h3&gt;
&lt;p&gt;One of the most important building blocks of naming structures in Java is the use of camelCase. Whether working with classes or variables, the way we distinguish between words in Java is using camelCase. This practice involves capitalizing the first letter of each word that’s composed in the Class, variable or method name. Here are a couple of examples:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Class Name
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public class DogFood&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Right off the bat, even without seeing the class declaration, we already know it is a class because it begins with a capital letter.&lt;/li&gt;
      &lt;li&gt;This follows the convention explained &lt;a href=&quot;#levels-of-hierarchy&quot;&gt;above&lt;/a&gt;, which is why this is so important.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Variable/Method Name
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public void getFood(){}&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Since this method name begins with a lowercase, we already know that it is either a variable or a method.&lt;/li&gt;
      &lt;li&gt;This is also in accordance with the levels of hierarchy conventions.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Technically, the Java &lt;strong&gt;compiler&lt;/strong&gt; doesn’t care about your naming conventions, but using them will help you and others reading your code to understand what you’re doing. &lt;em&gt;This is something I started off not caring about, and I had to learn to do it the hard way, because I ended up not being able to understand my own code. Don’t be a Carlos!&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;brackets-parentheses-and-semicolons&quot;&gt;Brackets, Parentheses, and Semicolons&lt;/h3&gt;
&lt;p&gt;Another important element of Java is the use of brackets and parentheses. Almost all programming languages use these in one form or another, but the ones in Java are particularly essential because that is the way that Java knows what you are writing.&lt;/p&gt;

&lt;h4 id=&quot;brackets&quot;&gt;Brackets&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;All content inside of a class or function is placed inside of brackets.&lt;/li&gt;
  &lt;li&gt;There are always an even number of brackets in any code that will correctly compiled.&lt;/li&gt;
  &lt;li&gt;Always count your brackets to make sure you have the correct number!&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;parentheses&quot;&gt;Parentheses&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Parentheses can be used to separate arguments when using arithmetic.&lt;/li&gt;
  &lt;li&gt;In methods, parameters are placed inside of parentheses, whether defining or calling the function.&lt;/li&gt;
  &lt;li&gt;There should also always be an even number of these, so be sure to count them!&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;semicolons&quot;&gt;Semicolons&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Semicolons are placed at the end of every “code” function, or when calling a method.&lt;/li&gt;
  &lt;li&gt;Semicolons do not have to go on lines where you are opening or closing a class or method definition, or where there is a bracket.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-putting-it-all-together&quot;&gt;Example (Putting it all together)&lt;/h2&gt;
&lt;p&gt;Here is a small example of code you’ll be able to understand soon, that implements everything that you learned today! We’ll go into more detail about everything in the snippet as you learn more about &lt;strong&gt;Classes&lt;/strong&gt; and the generic Java program.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Dog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;bark&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;makeSound&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next time, we’ll go into the use of data types, programming environments, and finally start your first program!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/java/lesson-2&quot;&gt;&lt;strong&gt;&lt;em&gt;Next Lesson&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;</content><author><name>Carlos Saucedo</name></author><category term="Java" /><category term="Java" /><category term="Lesson" /><category term="Coding" /><summary type="html">Welcome to Java, the Carlos Way! Over the course of this series, I’m going to try to teach you Java in the easiest way possible. There’s a lot of content, so be sure to take things slowly and at your own pace. I’ll do my best to link to a lot of different tutorials for more in-depth review. Now that I’ve got your attention, let’s get started! Why This Exists When I was 12 years old, I decided to tackle my first programming language, Python. I did so without any prior knowledge, without any formal textbooks or teachers: completely on my own. In the same way that I was able to learn from volunteers for free and on blogs and YouTube sites from people around the world, so too I want to impart my knowledge. I hope you are able to learn a great deal from this, and if you do, please consider passing on what you learn as a programmer. Soon, we will make the world full of people who know programming! Now, let’s get started… Java 101 (The Boring Stuff) I call this “The Boring Stuff” because I know you want to get dirty with code! However, there are some central things you must understand before jumping into a development environment and writing code… What Is OOP? OOP, or Object Oriented Programming, is a method of programming in which a programmer writes classes, and functions for those classes, and develops a hierarchical structure in order to achieve his or her programming goals. There are many different programming languages: Python, Java, C++, and more, and each has their own separate use case. Java is primarily used for developing cross-platform applications, or programs that can run on more than one system, such as Android, Windows, Mac, and iOS. The Java Hierarchy In Java, as well as in other programming languages, there is a general hierarchy that dictates the way we use the language. I have created a handy diagram in order to illustrate the Java Hierarchy: Levels of Hierarchy The levels of hierarchy go as follows: Packages A package is the highest level that can be imported into a Java program. Some of the most popular Java packages are: Java.util Java.lang Every class in Java is contained into packages. It is possible to create your own package when designing a project, but this is only recommended when it is a very big project and requires developing entire classes from scratch. Package names are denoted by a lowercase letter. Classes Classes are contained within packages, and are usually the most often written by programmers when designing a program. Some popular Java classes are: Java.lang.Math Java.util.Random Class names should begin with a capital letter. Objects Objects are what we call instances of a class, in which one instantiates a class in order to use it in our program. Instantiating is like “materializing” it, and allows us to use its member functions/variables. Code (Functions and Variables) Inside of every class lie functions and variables that are relevant to its name. Though there may be many instances of a single class, it is these member functions and variables that separate them from each other. Member functions use camelCase, which will be explained later. The Java API The Java API is the number one website you’ll be referencing and bookmarking throughout your studies. It contains the list of all of the packages, classes, objects, and methods that are embedded into the base version of Java that is shipped onto millions of devices. Few languages have as good a documentation as Java, which is why it’s a favorite for many programmers. Syntax What distinguishes Java from any other language its syntax. Just like any written language, programming languages each have their own set of syntax, and to learn the syntax by heart and to be able to use it seamlessly is truly to know the programming language. There are two categories to programming syntax: Syntax that the language interprets. This has to be exact, or else the computer will not know what telling it to do. Syntax that is used by programmers to make it readable to other programmers. This is not technically necessary, but a good programmer will always use common programming conventions. In this course, we’ll be going over both of these. CamelCase One of the most important building blocks of naming structures in Java is the use of camelCase. Whether working with classes or variables, the way we distinguish between words in Java is using camelCase. This practice involves capitalizing the first letter of each word that’s composed in the Class, variable or method name. Here are a couple of examples: Class Name public class DogFood Right off the bat, even without seeing the class declaration, we already know it is a class because it begins with a capital letter. This follows the convention explained above, which is why this is so important. Variable/Method Name public void getFood(){} Since this method name begins with a lowercase, we already know that it is either a variable or a method. This is also in accordance with the levels of hierarchy conventions. Technically, the Java compiler doesn’t care about your naming conventions, but using them will help you and others reading your code to understand what you’re doing. This is something I started off not caring about, and I had to learn to do it the hard way, because I ended up not being able to understand my own code. Don’t be a Carlos! Brackets, Parentheses, and Semicolons Another important element of Java is the use of brackets and parentheses. Almost all programming languages use these in one form or another, but the ones in Java are particularly essential because that is the way that Java knows what you are writing. Brackets All content inside of a class or function is placed inside of brackets. There are always an even number of brackets in any code that will correctly compiled. Always count your brackets to make sure you have the correct number! Parentheses Parentheses can be used to separate arguments when using arithmetic. In methods, parameters are placed inside of parentheses, whether defining or calling the function. There should also always be an even number of these, so be sure to count them! Semicolons Semicolons are placed at the end of every “code” function, or when calling a method. Semicolons do not have to go on lines where you are opening or closing a class or method definition, or where there is a bracket. Example (Putting it all together) Here is a small example of code you’ll be able to understand soon, that implements everything that you learned today! We’ll go into more detail about everything in the snippet as you learn more about Classes and the generic Java program. import java.util.*; public class Dog{ public void bark(int noise){ makeSound(5); } } Next time, we’ll go into the use of data types, programming environments, and finally start your first program! Next Lesson</summary></entry></feed>