<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ante Barić on Medium]]></title>
        <description><![CDATA[Stories by Ante Barić on Medium]]></description>
        <link>https://medium.com/@capJavert?source=rss-843ff866a149------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g2uIJFBKSFe1BxXtOXacPA.jpeg</url>
            <title>Stories by Ante Barić on Medium</title>
            <link>https://medium.com/@capJavert?source=rss-843ff866a149------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:40:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@capJavert/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How single message broke all our monitoring and dashboards]]></title>
            <link>https://medium.com/@capJavert/how-single-message-broke-all-our-monitoring-and-dashboards-d5d7816da868?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5d7816da868</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Thu, 02 May 2024 15:31:26 GMT</pubDate>
            <atom:updated>2024-05-02T15:51:27.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Funny image of a man throwing a PC in the garbage" src="https://cdn-images-1.medium.com/max/888/0*5d1vnqU6xZkUkx4T.jpg" /><figcaption>Image from <a href="https://imgflip.com/memegenerator">ImgFlip</a></figcaption></figure><p><strong>So.. this just happened (or depending on when you are reading, it happened some time ago) and while I look at my beautiful dashboards working again I am contemplating, despite all the modern tech, how fragile software can be these days…</strong></p><p>For the last 1.5 years, I have been using <a href="https://axiom.co/">Axiom</a> for all of my logs ingestion, querying, and monitoring needs. It is a great product and I never had one issue with it in my time using it. Spoiler alert, even today, when it failed it was actually my fault, but let’s see what happened.</p><p>Axiom has a feature called <a href="https://axiom.co/docs/query-data/virtual-fields">virtual fields</a> that allows you to compute log properties on the fly from other properties. One use case is parsing JSON payloads in logs and then expanding them with fields from that parsed JSON. For example, if I have the log entry:</p><pre>{<br>  &quot;path&quot;: &quot;/example&quot;,<br>  &quot;message&quot;: &quot;{\&quot;event\&quot;:\&quot;impression\&quot;,\&quot;id\&quot;:\&quot;jhfdsf334j24j\&quot;}&quot;<br>}</pre><p>I can use the virtual field to extract event property from that log entry and then filter over it as with any other “real” log field. Virtual fields are (like other queries) created in Axiom Processing Language (<a href="https://axiom.co/docs/apl/introduction">APL</a>).</p><p>It looks something like this:</p><pre>[&#39;dataset&#39;]<br>| extend event = iff(isnotnull(parse_json(message)), parse_json(message)[&quot;event&quot;], &quot;&quot;)</pre><p>To explain it quickly:</p><ul><li>iff returns first non null value (value of event or empty string)</li><li>isnotnull checks if the value is null , to avoid parsing fields that are not JSON</li><li>parse_json parses value as JSON</li></ul><p>With the above I could query all of my logs in Axiom by event field which was great, up until today. I got an email from Axiom saying that one of my monitors was auto-disabled. This was due to query, that monitor was using, failing multiple times. I opened it to see what was going on and quickly closed it because I was doing something else. A few minutes passed and I noticed one of the dashboards I was using was broken, I refreshed the page thinking it was a temporary error, but it did not help. The error said, “<strong>cannot index value of type string”.</strong></p><figure><img alt="Image of dashboard screen showing errors instead of data." src="https://cdn-images-1.medium.com/max/1024/1*ve7a9etIzan7bMq9CpKIQw.jpeg" /><figcaption>My dashboard being broken…</figcaption></figure><p>Since I did not change the dashboard or any setup on my side for weeks and after checking Axiom status page I reported an issue on their Discord server. I quickly got a reply that all systems were green from their end. One thing that Axiom representative said is to try and change the query time to something else eg. query logs from yesterday instead of the last X hours how I had it set up. To my surprise changing it to yesterday made my dashboard work again. At this point, I figured that it must be some specific log entry in some period that is causing an error. I played with FROM and TO dates and narrowed it down to the period of 1s containing 40 log entries. And yep, you read it right, in millions of logs it was down to 40 entries in the span of less than a second. Now I had to go in and look up which one of them was faulty.</p><figure><img alt="Table of log entries showing different messages." src="https://cdn-images-1.medium.com/max/1024/1*FU2M2K64FKMwq30XRrgBmA.png" /><figcaption>One of these logs messages broke all of my monitoring</figcaption></figure><p><strong>Before continuing try and guess which one of the above was a culprit?</strong></p><p>Knowing one of them was a culprit I quickly opened JavaScript console in Chrome, pipped the entries, and executed JSON.parse on them. All of them returned SyntaxError except for one entry. It was the &quot;email” entry. If you parse that string (with double quotes) as JSON you get back a string email (without double quotes). Which perfectly matched the error from my dashboard saying “<strong>cannot index value of type string</strong>”. My virtual field was trying to extract event property from string email , something like that is a no-op. Since I am using those virtual fields in almost all the places it broke literally everything. What a mess right?</p><p>To fix this I had to replace my isnotnull check with something else since it did not cover the above case. Browsing Axiom docs I found <a href="https://axiom.co/docs/apl/scalar-functions/string-functions#gettype()">gettype</a> utility function that returns the type of data passed to it. I also found exact example in their docs that parse_json can return a string .</p><figure><img alt="Examples of parse_json usage for Axiom Processing Language showing the function can return string in certain case." src="https://cdn-images-1.medium.com/max/1024/1*kngS6VSK3HEG1E9hnZcrLw.png" /><figcaption><a href="https://axiom.co/docs/apl/scalar-functions/string-functions#gettype()">https://axiom.co/docs/apl/scalar-functions/string-functions#gettype()</a></figcaption></figure><p>By using the above function my <strong>fixed</strong> virtual field now extracts the value only if the parsed JSON value is a dictionary (or object in JavaScript terms). It looks like this:</p><pre>[&#39;dataset&#39;]<br>| extend event = iff(gettype(parse_json(message)) == &quot;dictionary&quot;, parse_json(message)[&quot;event&quot;], &quot;&quot;)</pre><p>And just like that, everything was working again, and he lived happily ever after…</p><p>Thanks for reading! 🙈</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXQf2LxzdXBt8yo6NcA%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExOWh0dDV3YjFuMjU5dzMxbjJla2J5bjdlbTZycmp0NGt5YmJ4bDM3aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FXQf2LxzdXBt8yo6NcA%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMXpqM3plb3Z6dHNhbDZpbDhycXE4MGhqbDB5dG9uam12czZkcXZsMSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FXQf2LxzdXBt8yo6NcA%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/28903a17dc1babbfbaa14348686f9e6f/href">https://medium.com/media/28903a17dc1babbfbaa14348686f9e6f/href</a></iframe><p>If you enjoyed this post I would appreciate the like or share and if you are interested here are some of my other posts/projects:</p><ul><li><a href="https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f">How I did 100,000 push-ups in a year 💪</a></li><li><a href="https://javascript.plainenglish.io/integrating-rust-into-next-js-how-to-developer-guide-10e533470d71">Integrating Rust into Next.js: How-To Developer Guide</a></li><li><a href="https://get.komfy.app/">Get Komfy App</a> — Stream your favorite video content from your phone directly to your PC or Mac 📺</li><li><a href="https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344">How I hacked the most popular game in the world</a> ⌨️</li><li><a href="https://jawa.sh/">Jawa — Visual Scraper companion</a> 🤖</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5d7816da868" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Rust into Next.js: How-To Developer Guide]]></title>
            <link>https://javascript.plainenglish.io/integrating-rust-into-next-js-how-to-developer-guide-10e533470d71?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/10e533470d71</guid>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 14:11:28 GMT</pubDate>
            <atom:updated>2024-03-15T01:13:29.150Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Rust programming language logo on the right and Next.js logo on the right." src="https://cdn-images-1.medium.com/max/1024/1*z4N3Yyh7GoKfo-Vp1LFEpg.jpeg" /><figcaption>Photo by Mariia Марія from <a href="https://www.pexels.com/photo/woman-hands-on-keyboard-20343066/">Pexels</a></figcaption></figure><p><strong>Rust is one of the latest languages that got a lot of spotlight in the developer community. When talking performance it rivals C/C++ but it is also accessible enough to be used for a wide range of tasks and can run on many different platforms. One of those platforms is, of course, the web. In this post we will dive into how you can start using Rust in your web projects and platforms you are already familiar with.</strong></p><p>Web development was caught in the Rust storm and so far it looks like a great fit. Rust entered on a high note with standard JavaScript tooling like bundlers, compilers, test runners, and even runtimes being (re)written in Rust with massive performance gains. As a long-time programmer who worked in production projects with a bunch of different languages like PHP, Python, Objective C, Swift, and JavaScript my goal with learning a new language is always to start writing production code as soon as possible. Don’t get me wrong, fundamentals are important but where you see and learn the nuances of the language is solving real problems.</p><p>Recently my focus has been on the backend and APIs so my goal with Rust was to start writing new API endpoints for my projects in Rust instead of the usual JavaScript/Node.js. If you read any of my articles you might already know that I use Vercel to host most of my projects. I like the versatility it provides, allows me to deploy a bunch of different frameworks and mostly forget about the hurdle of managing infrastructure for the apps I am working on and just focus on delivering features. Naturally, I was curious if it is possible to build, deploy, and run Rust code on the Vercel platform and if I can integrate it into my current (mostly) JavaScript-based projects.</p><p>To my delight, there are multiple ways to deploy Rust code on Vercel. We will go through different options and then go into details with the option I chose to go with.</p><ul><li><strong>Using WebAssembly (Wasm) at the Edge.</strong> This allows us to write Rust code which we can then compile into .wasm binary which we can import as any other package/file into our JavaScript code.</li><li><strong>Using custom Rust runtime.</strong> Aside from deploying Node.js and frameworks such as Next.js, Vercel supports a range of custom runtimes that allow the deployment of native code compiled from other languages like Go, Python, and also Rust. Some of those runtimes are Vercel-maintained and some, like Rust runtime, are community-maintained. Both work pretty well (I used PHP and Python runtimes before).</li><li><strong>Using Rust runtime in the Next.js project.</strong> While using Rust runtime with Vercel is great, a lot of my projects are actually on frameworks like Next.js. To boost the number of projects in which I can use Rust I decided to integrate a template using Rust runtime with Next.js. That way I could gradually implement some features for my projects in Rust. It will also allow me to learn Rust more by using it each day.</li></ul><p><strong>Setup</strong></p><p>We are going to start with a fresh <a href="https://nextjs.org/docs/pages/api-reference/create-next-app">create-next-app</a> project to show the modifications needed to make this work. This will also provide you with steps you can take to do it in your project as well. Of course, I also have my template linked on GitHub below.</p><p>When you have your Next.js project up and running we can start to put Rust in the mix. If you were wondering this should all work on Next.js version 12.x, 13.x and 14.x and also with pages or app directory. To make use of custom runtimes we need to add vercel.json configuration file to our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2b32f8e99bcfb3781bd546050c16e98/href">https://medium.com/media/d2b32f8e99bcfb3781bd546050c16e98/href</a></iframe><p>We are also going to run npm install vercel -D to add vercel CLI to our dev dependencies. We will use it to run a local server for our Rust API endpoints. What this will do is tell Vercel to deploy any of our .rs files as serverless API functions with Rust runtime. The next thing is to create top-level api/ directory inside of our project. This differs from pages/api/ directory that you might already have in your Next.js project. If you have any code inside pages/api/ just keep it there as is and proceed to create top-level /api directory for our Rust runtime functions.</p><p>You will also need to have Rust installed on your local machine. The quickest way is with <a href="https://rustup.rs/">rustup</a>, so you can go ahead and install it if you don’t have it already. Rust uses <a href="https://github.com/rust-lang/cargo">cargo</a> as a package manager and build system. We get everything we need to build and run our Rust code locally with a single command. To enable cargo we need to create Cargo.toml configuration file in the root of our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff345f58d3d5ed2a748ed16940fc369b/href">https://medium.com/media/ff345f58d3d5ed2a748ed16940fc369b/href</a></iframe><p>If you are familiar with package.json it has some similarities. We add some general metadata like name and version, and we then add dependencies we need to build our API endpoints. In Rust dependencies are called “crates” and are hosted on <a href="https://crates.io/">crates.io</a> We use <a href="https://tokio.rs/">tokio</a> as async runtime, serde_json for JSON parsing/transform and vercel_runtime which is Rust equivalent of Vercel or Next.js APIs to manipulate requests and responses. Also, if you are using VSCode you can install <a href="https://rust-analyzer.github.io/">rust-analyzer</a> extension which will enable all the Rust language features and give you some more help and context when writing code.</p><p>Next, we are going to create our first Rust API endpoint. We will name it api/crab.rs as we wrote in our cargo config file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9d53c070c0ebafd62ad067011a91928/href">https://medium.com/media/e9d53c070c0ebafd62ad067011a91928/href</a></iframe><p>Now, if you never wrote a line of code in Rust this might not be 100% clear but if you used Vercel or some HTTP server in any language it should be mostly readable. We create a handler function that will be called to respond when API request is made to GET /api/crab . It responds with 200 OK status code and returns a message in JSON format.</p><p>We are going to quickly test it by running npx vercel dev . If you created a new project this will prompt you to set up your Vercel project, just follow the prompts to set it up. When it goes through it will say something like “Ready! Available at http://localhost:3000”. If you open <a href="http://localhost:3000/api/crab">http://localhost:3000/api/crab</a> in your browser after a few seconds you should see the response.</p><figure><img alt="Browser window with JSON response from our Rust API endpoint." src="https://cdn-images-1.medium.com/max/1000/1*amJWa-RzUB8yJNz-H_MZOw.png" /><figcaption>Response from our Rust API endpoint</figcaption></figure><p>If you refresh again you will see the response comes back almost instantly. That is because vercel dev under the hood used cargo to build and run our Rust file on the fly. This also automatically detects changes so it will only recompile when you change something in the code. So just write code and enjoy. You might have noticed there is a target/ folder in your root directory now, this is the standard output folder for Rust binaries so you want to add it to your .gitignore file. You can also add those to your .vercelignore (check the template at the end for reference).</p><p>Now that we have everything up and running let’s clean it up a bit and run it with the rest of our Next.js codebase. Rust runtime will take care of running our Rust code when deployed to Vercel but for dev, we will modify or npm run dev command a bit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a327b031b8c4464e8edefc692a250786/href">https://medium.com/media/a327b031b8c4464e8edefc692a250786/href</a></iframe><p>What we do here is that we run Rust API on different port with new dev:rust script. Then in addition to running next dev we also add it to our standard dev script. Now we can run everything in a single command that we are used to in Next.js projects.</p><p>Another thing is that we don’t want to go to localhost:3001 for our Rust endpoints which will be a different port than the default localhost:3000 for Next.js. We will fix it by adding a rewrite inside our next.config.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddd9df2354f712e4d37fde4595204b3f/href">https://medium.com/media/ddd9df2354f712e4d37fde4595204b3f/href</a></iframe><p>We apply rewrite only in development. On Vercel it will all be deployed to the same deployment so no need for a rewrite. Now you can go to <a href="http://localhost:3000/api/crab">http://localhost:3000/api/crab</a> again and it will work the same way even though it is running on a different dev server. Adding rewrite to fallback also makes sure that any of your existing pages/api endpoints do not get overwritten by Rust API endpoints in development.</p><p>Now that we have everything up and running let’s take a look at some common patterns you might need (or would use) in day-to-day API development.</p><p><strong>Caching</strong></p><p>Any production-ready API uses some kind of caching. When deploying on Vercel we can use their <a href="https://vercel.com/docs/edge-network/overview">Edge Network (CDN)</a> to cache API responses. It works with standard cache-control headers and s-maxage directives in response. To cache our API endpoint to 1 hour we can do the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bb3740f4640dfe748178aa9be0b4fd2/href">https://medium.com/media/6bb3740f4640dfe748178aa9be0b4fd2/href</a></iframe><p><strong>Reading request parameters</strong></p><p>vercel_runtime allows us to read data from incoming requests. Here are some common examples.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f15f326f23d7b1ac15bca111fc15edf0/href">https://medium.com/media/f15f326f23d7b1ac15bca111fc15edf0/href</a></iframe><p><strong>Common utils/libs</strong></p><p>With bigger projects, you would probably have a set of utils that are used across different API endpoints. With Rust, we can also register local crates in our Cargo config.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10b0d8aecc40967635828eebbaa9864e/href">https://medium.com/media/10b0d8aecc40967635828eebbaa9864e/href</a></iframe><p>I decided to put all of my shared Rust code inside src/rs directory to separate from other JavaScript files. In this crate I can define functions and macros to be reused in my Rust API endpoints. To use these functions just import them as from any other Rust crate. If you installed <a href="https://rust-analyzer.github.io/">rust-analyzer</a> or similar language integration in your IDE just starting to type the function name will allow you to auto-import.</p><p><strong>Environment variables</strong></p><p>You can access all of your env variables from a local .env file or your Vercel deployment. I recommend <a href="https://crates.io/crates/dotenv">dotenv</a> crate which is nice and easy to use.</p><p><strong>Error handling</strong></p><p>You don’t want your JSON APIs to crash with ugly unhandled exceptions. Rust has a specific way of <a href="https://doc.rust-lang.org/book/ch09-00-error-handling.html">handling errors</a> but to catch or throw structured errors in my API endpoints I added a macro to my utils which I use all around the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9c376fed4e2d324c6b2e0f607a4692a/href">https://medium.com/media/a9c376fed4e2d324c6b2e0f607a4692a/href</a></iframe><p>It accepts message, error, and HTTP status code which then get logged and return a response with the nice error message and status code that was provided. In addition, few macros are available for common cases like throwing generic 500 errors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203663f910769cf2608167202f8b6366/href">https://medium.com/media/203663f910769cf2608167202f8b6366/href</a></iframe><p><strong>Different request methods</strong></p><p>You can support different request methods like POST , PUT and DELETE. Each API function can handle multiple request methods so let’s see how to validate and limit which methods API endpoint accepts. First, we will define a separate function for each of our request methods. For example for POST method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7964bd6514c23c24edd9ddbc1e2e084a/href">https://medium.com/media/7964bd6514c23c24edd9ddbc1e2e084a/href</a></iframe><p>Then in our handler, we validate and map correct functions to request methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b0816980ad5af3a1a738c069b35fead/href">https://medium.com/media/0b0816980ad5af3a1a738c069b35fead/href</a></iframe><p><strong>Communicating with other services</strong></p><p>API endpoints can communicate with other services over different protocols. Most of the time it is over HTTP and for that, I recommend <a href="https://crates.io/crates/reqwest">reqwest</a> crate which works well with other packages we already use. You can see some examples inside my linked template project.</p><p><strong>Cold boot and startup</strong></p><p>Deploying serverless comes with a cost. Sometimes your users will hit an endpoint without a prepared instance and will have to experience a cold boot delay. One of the factors affecting cold boots is the size. From my testing compiled serverless functions on Vercel with Rust runtime are smaller than Node.js functions with a similar amount of code but larger than Edge functions.</p><figure><img alt="Breakdown of serverless function size for Node.js, Rust and Edge runtimes. From worse to best in that order." src="https://cdn-images-1.medium.com/max/1024/1*063AQL0mOTDOxXvltQVFng.png" /><figcaption>Cold boots vary between Node.js and Edge runtimes on Vercel</figcaption></figure><p>As for cold boot performance I measured it ranges from 500–1000ms. When hitting warm/ready instance performance is great and if your project gets a lot of requests (together with caching) you will not have any issues with your Rust-implemented API endpoints.</p><p>I have been using this setup in some of my projects successfully for the past few months. One of those <a href="https://shareimdb.com/">https://shareimdb.com/</a> is fully run on Rust runtime in terms of API and I am using JavaScript/React only for pages needing HTML rendering. The project profited a lot by doing underlying scraping and parsing with Rust instead of Node.js. For example, I would have trouble fitting headless browser runtime in a severless function 50mb limit, but with Rust, it was not an issue since the size was smaller. The most important thing is to pick the right tool for the job. Anyone who worked on any kind of long-term production project will know that the “rewrite everything mindset” is not viable. With that in mind this kind of partial integration and usage of different technologies/languages on a single project is perfect because they can co-exist and if picked correctly can make the project better.</p><p><strong>Issues</strong></p><p>I want to end this by pointing out some issues that I encountered while using Rust in production on Vercel. As said, I have been running this successfully for the last few months but I want to point out some pain points I had and bugs I encountered to hopefully save you some time in decisions and debugging.</p><p>One issue that I noticed is that sometimes vercel dev running Rust runtime functions would just crash for no obvious reason. For example, when you add specific dependencies through cargo it might require restart of vercel dev. Sometimes when adding a new file to the cargo config or as a lib I would also need to re-run my dev command or kill node process that is running the server. While this is a community runtime (acknowledged by Vercel) I hope in the future they also add Rust as an official runtime.</p><p>Another bigger issue is that there is a problem with Vercel when deploying dynamic routes with any custom runtime (not just Rust). You can read the details on the <a href="https://github.com/vercel/next.js/issues/56869">bug report I opened on Vercel GitHub</a>. There are also some alternatives to how to avoid this inside the ticket.</p><p>All in all, I loved that I was able to add Rust to my existing development stack and projects. <strong>You can take a look at my </strong><a href="https://github.com/capJavert/next-rust"><strong>Next.js + Rust template</strong></a><strong> created from this blog post for more code and examples. You can also use it as a template for your new projects.</strong></p><p>If you enjoyed this post I would appreciate the like or share and if you are interested in learning more about this subject here are some links to continue reading.</p><ul><li><a href="https://github.com/vercel-community/rust">Rust runtime for Vercel (community)</a></li><li><a href="https://vercel.com/docs/functions/runtimes">Vercel-supported custom runtimes</a></li><li><a href="https://doc.rust-lang.org/book/">Rust Book — a crucial resource for learning rust fundamentals</a></li><li><a href="https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_Wasm">Web Assembly for Rust</a> and <a href="https://vercel.com/docs/functions/wasm">Wasm on Vercel</a></li><li>My <a href="https://github.com/capJavert/next-rust">Next.js + Rust template</a></li></ul><p>And some of my other posts/projects:</p><ul><li><a href="https://jawa.sh/">https://jawa.sh</a>— Visual scraper interface, exports to puppeteer script which you can run anywhere and scrape anything 🤖</li><li><a href="https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f">https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f</a> — How I did 100,000 push-ups in a year 💪</li><li><a href="https://get.komfy.app/">https://get.komfy.app</a> — Stream your favorite video content from your phone directly to your PC or Mac 📺</li><li><a href="https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344">https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344</a> — How I hacked the most popular game in the world ⌨️</li></ul><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10e533470d71" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/integrating-rust-into-next-js-how-to-developer-guide-10e533470d71">Integrating Rust into Next.js: How-To Developer Guide</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seamless emoji creation on Discord with bots and Vercel]]></title>
            <link>https://medium.com/@capJavert/seamless-emoji-creation-on-discord-with-bots-and-vercel-6272f597477f?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/6272f597477f</guid>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[emoji]]></category>
            <category><![CDATA[discord]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[discord-bot]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Wed, 03 Jan 2024 13:07:46 GMT</pubDate>
            <atom:updated>2024-01-04T15:56:13.144Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image showing person holding a phone on the left and different emojis on the right including Discord logo." src="https://cdn-images-1.medium.com/max/1024/1*m9bh879pZ4z-0R4YrkOxZQ.jpeg" /><figcaption>Photo by Zen Chung from <a href="https://www.pexels.com/photo/faceless-male-entrepreneur-using-smartphone-against-white-background-5745183/">Pexels</a></figcaption></figure><p><strong>Custom emojis are a great way to add identity and a sense of fellowship to any Discord server. Users quickly get ideas for new emojis from messages shared in the server but the most common issue is that it takes some work to transfer those ideas and images to emojis. Discord has restrictions on the resolution, type, and size of an image that is required to create an emoji. But, people are lazy, and with those restrictions and additional work required to create them, many cool emojis are left as just ideas…</strong></p><p>If you have ever been a part of Discord server you will know that many of them have different bots installed to help with various tasks. Bots can send messages to channels, perform moderation, embed remote content like tweets, and also reply and react to commands from users. The last feature, commands, is especially interesting because it allows users to perform advanced and custom actions inside the Discord server. For example, we could develop a command to create emoji from any image.</p><p>Since my (and many other) servers already have a custom bot I decided to try and add a new command that would do just that. The idea sounded great in my head but at first, I was not sure what would take to actually develop it. Manipulating images usually requires some processing power, a dedicated server, and storage. To entertain this idea let&#39;s see what would be required for this feature to be added to our server:</p><ul><li>Discord bot (my server already had one but if you want to create your own take a look at <a href="https://discordjs.guide/#before-you-begin">https://discordjs.guide</a>)</li><li>A way for users to input an image and some data like emoji name</li><li>Server or application capable of processing the image and adjusting it to given Discord restrictions</li><li>Uploading adjusted emoji image to Discord as new emoji</li></ul><p>As mentioned above, my Discord bot is implemented in Node.js with the help of <a href="https://discordjs.guide/">Discord.js</a> package. Their guide has an in-depth instructions on how to set up a basic bot, register it for use on Discord, and also some ideas on where and how to deploy it. I won’t be going into those details in this blog post but will provide a basic skeleton of it using the above package.</p><p>Once I had my Discord bot up and running the first thing was to solve the handling of user input. Users usually have an image they would like to convert to an emoji so we can start with that. Also, each emoji needs a unique name with which it can be used in messages and reactions, it is an alphanumeric phrase (_ is also allowed) without spaces or special characters. If you speak regex this would match:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f30ebb20d66a5190c70ff1a1fb47981/href">https://medium.com/media/0f30ebb20d66a5190c70ff1a1fb47981/href</a></iframe><p>Luckily Discord command can accept text and images as input so we can collect all the data needed to create an emoji from our user right from Discord interface. Discord.js exports <a href="https://discordjs.guide/creating-your-bot/slash-commands.html#individual-command-files">SlashCommandBuilder</a> class which allows us to define what inputs our command accepts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56cdb25b9e70c2bc23f9dacfe144171e/href">https://medium.com/media/56cdb25b9e70c2bc23f9dacfe144171e/href</a></iframe><p>What we need now is to handle the above input. The most important thing is the image and its conversion. To convert the image we will use the cool feature of Vercel which is called <a href="https://vercel.com/docs/functions/edge-functions/og-image-generation">Open Graph (OG) Image Generation</a>. This feature is available as a standalone package and also inside Next.js framework. Since I used Next.js for my general purpose server and API I decided to add a new API endpoint to handle image adjustment. The above image generation package uses JSX to create images from HTML and CSS markup or even custom React components. So to adjust the image all I needed to do was to render &lt;img /&gt; tag inside JSX and set style attribute to correct size and fit values. This is how my request handler looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06e4bc81f03ba6827af7a03fdb303f59/href">https://medium.com/media/06e4bc81f03ba6827af7a03fdb303f59/href</a></iframe><p>I also added the fit param to allow further customization of how image should be fitted to square dimension of the emoji. If the image aspect ratio is 16:9 with fit: cover we can cut it in the middle and alternatively with fit: contain we can resize it to fit 1:1 aspect. If you don’t use Next.js you should still be able to use @vercel/og package with your Node.js framework of choice. It is a great way to adjust the image per Discord requirements without using any heavy image processing or requiring additional storage.</p><p>Now that we have our image ready we can connect it with the rest of the data and create a handler for our slash command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4383a9cc04659e5fc996df5b6e885c12/href">https://medium.com/media/4383a9cc04659e5fc996df5b6e885c12/href</a></iframe><p>In the above command, we take options from <a href="https://discordjs.guide/creating-your-bot/command-handling.html#receiving-command-interactions">Interaction</a> object passed from our slash command. We then take the original image URL from Discord and pass it to our API endpoint together with fit option. The response of our endpoint (which is an image) is then parsed as ArrayBuffer and then passed to Discord.js function which registers new emoji in the Discord server that our bot is currently running in. ✅</p><p>Here is a sneak peek of how all of this works together inside Discord app:</p><figure><img alt="GIF showing usage of created command inside Discord interface" src="https://cdn-images-1.medium.com/max/600/1*yKjfZirfzGIP-1f0iCGX_g.gif" /><figcaption>Done and done.</figcaption></figure><p>The above is also a good example of how an image with a wide aspect ratio fits perfectly in the square emoji after conversion. <a href="https://emojipedia.org/raising-hands">🙌</a></p><p>Thats it! This was a pretty cool usage of different services and technologies to create something new and a great example of what is possible with the tools we have available today. If you want to learn more about Discord and the different integrations it offers for developers you can also check out their <a href="https://discord.com/developers/docs/intro">developer portal</a>.</p><p>P.S. More complete code snippet with validation and additional command for removing an emoji <a href="https://gist.github.com/capJavert/fec7156378e5bc0d95cbf954b2fcb999"><strong>can be found here</strong></a>.</p><p>If you are interested in programming, tech or want to see some of my other side projects check below:</p><ul><li><a href="https://get.komfy.app/">https://get.komfy.app</a> — Stream your favorite video content from your phone directly to your PC or Mac 📺</li><li><a href="https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f">https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f</a> — How I did 100,000 push-ups in a year 💪</li><li><a href="https://jawa.sh/">https://jawa.sh</a>— Visual scraper interface, exports to puppeteer script which you can run anywhere and scrape anything 🤖</li><li><a href="https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344">https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344</a> — How I hacked the most popular game in the world ⌨️</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6272f597477f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save bandwidth on Vercel with Cloudflare]]></title>
            <link>https://medium.com/@capJavert/save-bandwidth-on-vercel-with-cloudflare-462bec444865?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/462bec444865</guid>
            <category><![CDATA[bandwidth]]></category>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 12:00:09 GMT</pubDate>
            <atom:updated>2023-02-09T02:18:19.505Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*LWRRT6uP0kG0yPUV4xrjbQ.jpeg" /><figcaption>Let’s save some bandwidth!</figcaption></figure><p><a href="https://vercel.com/">Vercel</a> free tier is a great way to deploy projects of low to middle scale almost without any costs. Usage limits are generous but when deploying projects with more requests/sec or lots of media content (eg. images/videos) the first usage limit you will likely cross is 100 GB of bandwidth. If you want to know how to save some bandwidth and stay on the free tier for most of your projects, read on…</p><p>So few years back I created <a href="https://clippy.kickass.website/">Clippy browser extension</a>. It is a goofy feel good extension that brings back old MS Word assistant Clippy back to your browser to help (annoy) you with his tips &amp; tricks.</p><figure><img alt="Screenshot showing Clippy inside of the browser. He is on the Google website and saying “Maybe try Bing?”" src="https://cdn-images-1.medium.com/max/640/0*QBIILzZVKuY31Z1P" /><figcaption>Clippy inside of your browser!</figcaption></figure><p>So what does Clippy has to do with hosting and bandwidth? Well, in my browser extension all the things that Clippy can say are located inside of <a href="https://github.com/capJavert/clippy-dictionary">word dictionary hosted on GitHub</a>. Anyone can contribute with additional phrases for different websites through PRs and after merge the new phrases will be automatically pulled into all of the extensions and Clippy will be able to say even more. Throughout the years extension amassed thousands of users across Chrome, Firefox and Opera extension stores so number of requests to my dictionary endpoint grew quite a lot.</p><h4>The setup</h4><p>This is how I used to host and manage Clippy dictionary.</p><ul><li>Content is hosted on GitHub and it changes any time someone opens a PR and I merge it after review #checkcode</li><li>When content changes it is automatically built (JSON is parsed and minified)</li><li>After build the dictionary contents are automatically deployed on Vercel as single static file</li><li>It is made available on <a href="https://clippy-dictionary.kickass.website/">https://clippy-dictionary.kickass.website</a></li><li>Browser extension instances automatically fetch dictionary contents when user opens a new tab</li><li>This then hits my dictionary endpoint and costs me bandwidth</li></ul><h4>The problem</h4><p>So with thousands of users you can see how this ramps up pretty quickly, for example in November (2022) my Clippy endpoint amassed 10GB of bandwidth (which is 10% of 100GB allowed bandwidth in Vercel free tier).</p><figure><img alt="Chart showing bandwidth usage for dictionary in November 2022, usage is 10GB." src="https://cdn-images-1.medium.com/max/1024/1*Cppx2dLt4MAv8fuxoEf7pw.png" /><figcaption>Bandwidth usage for dictionary in November 2022</figcaption></figure><p>Also this accounted for 84.9% of bandwidth across all of my 30+ other projects that I host on Vercel. It was just wild to see that!</p><figure><img alt="Chart showing bandwidth usage across all of my projects. Usage for dictionary is 84.9%" src="https://cdn-images-1.medium.com/max/1024/1*nm-rWTmNK3MMpLfTnzSVsw.png" /><figcaption>Bandwidth usage across all of my projects in November 2022</figcaption></figure><p>One thing that I immediately did after I have seen this was to check cache hit ratio for my deployment. This was because for most of the time dictionary does not change so I should have a very good cache hit ratio.</p><p>After checking my usage dashboard on Vercel I was right! Even better my cache hit ratio was 97.3%</p><figure><img alt="Chart showing cache hit/miss ratio for dictionary in November 2022. Ratio is 97.3%" src="https://cdn-images-1.medium.com/max/1024/1*Tdfe0cP27YefXXw7Zv23Kg.png" /><figcaption>Cache hit/miss ratio for dictionary in November 2022</figcaption></figure><p>This of course was expected as I was hosting my dictionary as static JSON file which is automatically cached by Vercel Edge Network. The real problem is that <a href="https://vercel.com/docs/concepts/limits/usage#requests">Vercel bills you for all bandwidth</a> (cached or uncached). From the their docs:</p><blockquote>As a Vercel customer, you will be billed for both Cached and Uncached requests.</blockquote><p>I wrongly assumed that cached requests would be free, my logic was, if there is no compute there is no costs. But again Vercel is serving millions of customers every day so I can not blame them for this, they have a great service overall 👏 … but still It was crazy that hosting a single file would occur this much bandwidth. I needed to do something about that.</p><h4>The solution</h4><p>Fortunately there is another provider that also offers a generous free tier but their main service is content delivery and bandwidth. Of course I am talking about <a href="https://www.cloudflare.com/">Cloudflare</a>.</p><p>Cloudflare <a href="https://community.cloudflare.com/t/cdn-bandwidth-limits/300965">does not have a bandwidth limit</a> on their free tier. Which is wild because they are probably serving even more users then Vercel, but as a company whose core business is content delivery I guess it makes sense.</p><p>As I was already using Cloudflare to manage all of my domains DNS records the solution for me was as simple as to <a href="https://vercel.com/guides/using-cloudflare-with-vercel#with-proxy">enable proxy in front of my Vercel deployments</a>. If you are using other DNS providers you can check with them if they support DNS proxy and caching. If your current provider does not have these capabilities or you are using Vercel as your domain DNS provider you can switch to Cloudflare at no costs pretty easily. Check the following links for more info:</p><ul><li><a href="https://developers.cloudflare.com/fundamentals/get-started/setup/">https://developers.cloudflare.com/fundamentals/get-started/setup</a></li><li><a href="https://developers.cloudflare.com/fundamentals/get-started/setup/add-site/">https://developers.cloudflare.com/fundamentals/get-started/setup/add-site</a></li></ul><p>The above mostly involves changing nameservers of your domain to Cloudflare nameservers.</p><p>When you have your domain up and running with Cloudflare you can now customize caching behaviour for different paths of your website.</p><p>This is how I added caching rule for my dictionary endpoint:</p><ol><li>Select your site from <a href="https://dash.cloudflare.com/">https://dash.cloudflare.com</a></li><li>Select Caching → Cache Rules → Create rule</li><li>Set the name for your Rule and matching expression:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*64HGtxEZ2WVZm3XmMgudMA.png" /></figure><p>As I serve my dictionary on a subdomain I selected <strong><em>Hostname</em></strong> match and put in my subdomain. What that means is that any requests coming to my subdomain will now firstly go through Cloudflare and if cache is a hit it will be served from Cloudflare’s Edge network without ever touching Vercel servers (thus saving bandwidth).</p><p>You can also choose different matching fields eg. <strong>Path</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSd5NrDdRbh6PJKMeTqsXg.png" /></figure><p>You can also use different operators as <strong>contains</strong> or <strong>starts-with </strong>or even regex (regex is available only in paid tiers).</p><p>4. The last thing is to set a cache TTL for deployment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kz8BAirIXPmlmhaOySKr4g.png" /></figure><p>I have set my TTL to 1 day because I get PRs for dictionary changes every other week or so. Even if I got new PR every day this would be more then enough.</p><p>Also make sure you set Edge TTL as this is the one that is server side controlled and will protect your origin server/app, Browser TTL only controls browser/network proxy caching and is suitable to invalidation if user requests your page with Cache-Control: no-cache header.</p><p>I deployed my caching rule on Cloudflare and after few weeks I went back and checked bandwidth usage inside of my Vercel dashboard. It was a clear win! 🎊</p><figure><img alt="Chart showing Bandwidth usage for dictionary after adding Cloudflare proxy and caching. Usage is now only 6.23 megabytes." src="https://cdn-images-1.medium.com/max/1024/1*f4aCU-dZaZ9bv1co09YACg.png" /><figcaption>Bandwidth usage for dictionary after adding Cloudflare proxy and caching</figcaption></figure><p>In the month of January (2023) my bandwidth usage for dictionary was <strong>only 6.23MB</strong>. Which is wild when just a month before it was 1600 times larger at ~10GB.</p><p>With all of that bandwidth saved we will be able to host many more projects with this Vercel + Cloudflare combination for years to come ✅</p><p>If you are interested in Clippy or some of my other side project check below:</p><ul><li><a href="https://www.youtube.com/watch?v=d_OnTmRSohg">https://www.youtube.com/watch?v=d_OnTmRSohg</a> - My talk about browser extensions and Clippy at Halfstack London 2022 📽</li><li><a href="https://get.komfy.app/">https://get.komfy.app</a> - Stream your favorite video content from your phone directly to your PC or Mac 📺</li><li><a href="https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f">https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f</a> - How I did 100,000 push-ups in a year 💪</li><li><a href="https://jawa.kickass.codes/">https://jawa.kickass.codes</a> - Visual scraper interface, exports to puppeteer script which you can run anywhere and scrape anything 🤖</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=462bec444865" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Komfy: Couch streaming]]></title>
            <link>https://medium.com/@capJavert/komfy-couch-streaming-4f8b22ec034c?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f8b22ec034c</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[komfy]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 11:29:02 GMT</pubDate>
            <atom:updated>2022-07-19T11:35:26.125Z</atom:updated>
            <content:encoded><![CDATA[<p>Copy link from your favorite apps like Youtube, Twitch or Vimeo and cast it directly to your desktop. With Komfy any PC or Mac can become the center of your home entertainment without any additional hardware. This is a story of how Komfy was created and where are we heading. <a href="https://get.komfy.app/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=launch&amp;utm_content=intro">Download here</a></p><figure><img alt="Komfy promo poster reading: Stream your favorite video content from your phone directly to your PC or Mac." src="https://cdn-images-1.medium.com/max/1024/1*ZEugLRl4SUtftzMRHAKwfg.jpeg" /></figure><p>Hello world!</p><p>I am Ante, Software developer from Croatia. Almost 2 years ago I was living in a small apartment and most of my time indoors I would spend just lying on the bed and watching Youtube, Twitch and other videos from my laptop that was connected to my external monitor. The problem I had was that every time video ended or I wanted to watch something else I had to get up to my laptop, find the next video and press play. Solutions like Airplay did not work because Youtube does not allow it without additional payment and casting to TV did not really work because some TVs do not support some platforms like Twitch. Also switching between different apps on the phone and on the laptop/TV was also a hassle.</p><p>One night I got tired of it and created a POC (Proof of concept) where I could paste any link from Youtube and it would automatically play on my laptop through the desktop app I also developed. It worked great and I enjoyed that I could just get nice and comfy in my bad and watch all of the videos I wanted. Quickly I added support for Twitch and few more platforms and just like that <strong>Komfy was born!</strong></p><figure><img alt="Komfy promo poster reading: Copy video link from your favorite apps like Youtube, Twitch or Vimeo and cast it directly to your desktop." src="https://cdn-images-1.medium.com/max/1024/1*rVkb2GLqmDpRZCGln1--PQ.jpeg" /></figure><p>Now, almost 2 years later Komfy is a full fledged video player with playback and volume controls, previews, connection management and also has a fresh coat of paint (courtesy of our designer Denis) to make you even more Komfy :)</p><p>Komfy also currently supports even more video &amp; audio platforms like Vimeo, Soundcloud and Facebook. If interested you can find the full list on our website.</p><p>What makes Komfy different from the competition?</p><ul><li>works across all platform interchangeably</li><li>yes, this means that you can finally connect your Android phone to your Mac 😆</li><li>you can watch content from different platforms without changing the app or device</li><li>multiple people can connect to the same device and control playback, volume etc. 🤝</li><li>It is <strong>free</strong> 💸</li><li>makes you more Komfy ✅</li></ul><p>Even though Komfy is out now, its story is just beginning. We want to add even more platforms, add new features like playlists and history and make video casting experience even better. To achieve all of that we need real users and feedback. Komfy was used by dozens of people so far during testing and development and while they all loved using Komfy they also contributed with even more great ideas and gave valuable feedback.</p><p>So… if you wish to be more Komfy head to <a href="https://get.komfy.app/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=launch&amp;utm_content=outro">https://get.komfy.app</a> and try Komfy now for free! We (the whole Komfy team) are looking forward to all of you and we can’t wait to see what do you think about Komfy.</p><p>Also feel free to ping us on social media <a href="http://twitter.com/getkomfyapp">@getkomfyapp</a> or <a href="http://twitter.com/capjavert">@capjavert</a> with your stories, questions and ideas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JlDLb357z8ViFtp3lWrpnA.jpeg" /></figure><p><strong>Are you Komfy yet?</strong></p><ul><li><a href="https://apps.apple.com/app/komfy-couch-streaming/id1531587269">Download iOS</a></li><li><a href="https://play.google.com/store/apps/details?id=app.komfy.get">Download Android</a></li><li><a href="https://get.komfy.app/?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=launch&amp;utm_content=outro#desktop">Download Desktop</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f8b22ec034c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Re-Hacking Wordle]]></title>
            <link>https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/114ba75d1344</guid>
            <category><![CDATA[wordle]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Fri, 15 Jul 2022 09:37:59 GMT</pubDate>
            <atom:updated>2022-11-14T15:46:37.090Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>You all know about that game that flooded Twitter and the rest of the internet a few weeks ago. Like many others, I also started playing but my streak was longer than the Golden Gate Bridge and each day I would guess the word on the first try. Wanna know how? Read on…</p><p><strong>DISCLAIMER: This is a follow-up to my original article </strong><a href="https://medium.com/@capJavert/hacking-wordle-6889101eab73"><strong>Hacking Wordle</strong></a><strong>. Since then Wordle changed its source code quite a bit. Due to this the old method no longer works.. but worry not we can crack it again…</strong></p><figure><img alt="Wordle highscore. Max streak is 78. 100% win rate." src="https://cdn-images-1.medium.com/max/1024/0*G6H37mlVwHlbBTII.png" /><figcaption>Not bad, right?</figcaption></figure><p>When I first looked at the game I thought it was really smart and interesting. My mind would just immediately start working on so many words that I know and want to try. Also choosing a word for your first guess is really hard because there are so many options.</p><p>As I am Software Developer (primarily using JavaScript) I was interested to open up Chrome DevTools and look at the Wordle code and maybe find the way to help myself working out the solution for each day.</p><p>The first thing I did was open the game in Incognito window and started playing. I was expecting to see network requests that would check if solution/word was correct on the server-side. But to my surprise there were none. I said ok, maybe when you win the final answer is sent to the server, and validation is somehow encrypted/obfuscated in client-side (JavaScript) code — but no, even when I won there were no network requests so now it was clear that solutions actually had to be embedded and available on the client-side and all those JavaScript files.</p><p>Now that I knew the control flow of the game I found out that after the page loads there is a “solutions” variable that gets initialised. It was pulling the value from a single function that would get the current day index and then would look at the specific array for word. <strong>Yes, I found all the words that were available and will be available in further days for the Wordle game</strong>.</p><figure><img alt="Screenshot showing Wordle source code and the available words." src="https://cdn-images-1.medium.com/max/1024/0*Slxvm57fchaxnyXA.png" /><figcaption>All of the words above were already in the past days so do not worry about the spoilers 😉</figcaption></figure><p>So nice, success… just by knowing the word for the next day ahead of time I could even now win every day on the first try. But I wanted more…</p><p>So the last time I was doing this the solution variable was actually stored on the game-app HTML element (web component). I could just do document.querySelector(&#39;game-app&#39;).solution and that would print out the solution for the current day to the JavaScript console.</p><p>But due to changes made to the Wordle codebase this was no longer the case so I had to employ some new methods.</p><p>As I still knew that all of the solutions are contained in the JavaScript file that gets loaded when the website loads – my first step was to get the contents of that file through the JavaScript console. The file is called wordle.{hash}.js . I tried querying the script tag through document.querySelector but it looks like that the script tag is removed after JavaScript loads. Not an issue, I used fetch to get the initial HTML contents of the page by fetch(window.location.href) — after that querying the script was just a matter of parsing the HTML string with DOMParser and doing query select on that new document.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/463f0042012eb6f4b62d1d657fbca1da/href">https://medium.com/media/463f0042012eb6f4b62d1d657fbca1da/href</a></iframe><p>The next step was to actually load the JavaScript file from the script src . I fetched the contents of wordle.{hash}.js file. I first tried executing the code with eval but as the code is wrapped inside the <a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE">IIFE</a> (Immediately Invoked Function Expression) I could not get the variable with solutions as it was private inside that expression. I decided to go another route. Just load up the JavaScript file text content and search the part of the code with Regex.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/595f04e5976c00467202862f1a0b2196/href">https://medium.com/media/595f04e5976c00467202862f1a0b2196/href</a></iframe><p>So with this we are actually back at the point where we have all the solutions inside the array. The tricky part is that we need to actually pick which solution is the right one for the current day. Fortunately from the last time I knew exactly where is the function inside the JavaScript file that actually picks the right solution based on the offset. This is the slightly modified function from the original Wordle codebase:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1622a15cb3fec3a896a6307ed68137ec/href">https://medium.com/media/1622a15cb3fec3a896a6307ed68137ec/href</a></iframe><p>So this function accepts two arguments. First one e is the initial Wordle date (I call it <strong>Wordle Magic Number</strong>). And it is Sat Jun 19 2021 00:00:00 GMT+0200. The second argument t is just the current day.</p><p>And that’s it, the above function gets us the index that we put inside the solutions array solutions[offset] and voilà.. this prints out the solution for the current day.</p><p>As I practically had the solution (like the last time) I was thinking.. what if I could actually automate the pressing of keys and solution submission? Short answer, I just copied the original code that was pressing the keys…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fa7yVQvApqIjRhZE13D%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fa7yVQvApqIjRhZE13D%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fa7yVQvApqIjRhZE13D%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="337" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c476b8b7a3d4d7cb29dc2434e5733af/href">https://medium.com/media/7c476b8b7a3d4d7cb29dc2434e5733af/href</a></iframe><p>Nice, right? That is about it for this article. Feel free to use it on days when you are having a hard time guessing the word or just need a mental break and wish to continue your streak. That is what cheats are for 😉. Also, I know that this takes all the fun out of the game. I personally did not care and had more fun re-reverse engineering and working on this hack (again). But that is me. I would like to say kudos to the Wordle creator for the fun game, and also a fun challenge for us who like to tinker with the code 😄. Cheers!</p><p>If you wish to take a closer look at the final script here is a pretty version with comments below 👇, and if you want to check out my original article here it is <a href="https://medium.com/@capJavert/hacking-wordle-6889101eab73">Hacking Wordle</a>.</p><p>Below script has different logic then what was referenced above in the article because Wordle changed its codebase again.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/788213c45bdb823b505ed1f11373507b/href">https://medium.com/media/788213c45bdb823b505ed1f11373507b/href</a></iframe><p>P.S. There is also a minified version 😉</p><p>P.S. I also added a catch block to warn you if Wordle changes the codebase again so you can contact me and I can create a new hack ✅</p><p>FYI: I also re-hacked <a href="https://www.lewdlegame.com/">https://www.lewdlegame.com/</a> so if you want to see that leave a clap or let me know on Twitter. 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=114ba75d1344" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking Wordle]]></title>
            <link>https://medium.com/@capJavert/hacking-wordle-6889101eab73?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/6889101eab73</guid>
            <category><![CDATA[wordle]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 12:20:54 GMT</pubDate>
            <atom:updated>2022-07-15T09:43:12.754Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>You all know about that game that flooded Twitter and the rest of the internet a few weeks ago. Like many others, I also started playing but my streak was longer than the Golden Gate Bridge and each day I would guess the word on the first try. Wanna know how? Read on…</p><p><strong>DISCLAIMER: This hack is outdated. Wordle changed its source code quite a bit. Due to this the old method no longer works. You can check out the latest hack at </strong><a href="https://medium.com/@capJavert/re-hacking-wordle-114ba75d1344"><strong>Re-Hacking Wordle</strong></a><strong>.</strong></p><figure><img alt="Wordle highscore. Max streak is 78. 100% win rate." src="https://cdn-images-1.medium.com/max/1024/1*MLiJxZCndOptV4KFd1zN5w.png" /><figcaption>Not bad, right?</figcaption></figure><p>When I first looked at the game I thought it was really smart and interesting. My mind would just immediately start working on so many words that I know and want to try. Also choosing a word for your first guess is really hard because there are so many options.</p><p>On my first try, I got it in 4 tries + I used an online word dictionary to find the right word that matched the letters I guessed so far.</p><p>After that, I went on Twitter to share my score and I saw a guy did it in a single try. He was so happy and said that there is a really small chance he will do it ever again. That got me thinking, is it possible to somehow win every time.. is it possible to cheat the game?</p><p>I went on Google and found some interesting topics. There are many helpers for finding the word based on the parameters. Eg. 5 letter words with letters “H, A, K”. Which is similar to how I did it by hand when I first played. Here are a few examples.</p><ul><li><a href="https://wordfinderx.com/wordle/">https://wordfinderx.com/wordle/</a></li><li><a href="https://www.thewordfinder.com/wordle-solver/">https://www.thewordfinder.com/wordle-solver/</a></li><li><a href="https://word.tips/wordle/">https://word.tips/wordle/</a></li></ul><p><strong>Each of those is great and will help an average Joe to do better or extend their streak but that was not enough, I wanted perfection.</strong></p><p>As I am Software Developer (primarily using JavaScript) I was interested to open up Chrome DevTools and look at the Wordle code.</p><p>The first thing I did was open the game in Incognito window and started playing. I was expecting to see network requests that would check if solution/word was correct on the server-side. But to my surprise there were none. I said ok, maybe when you win the final answer is sent to the server, and validation is somehow encrypted/obfuscated in client-side (JavaScript) code — but no, even when I won there were no network requests so now it was clear that solutions actually has to be embedded and available on the client-side and all those JavaScript files.</p><p>So I moved to Sources tab of Chrome DevTools and started looking at the code. JavaScript was minified but that was no problem because Chrome has an integrated prettifier that formats the code.</p><figure><img alt="Screenshot showing Google Chrome user interface. Arrow pointing to the “Pretty print” CTA." src="https://cdn-images-1.medium.com/max/1024/1*B8QSJLgJSBv6uBMFtgAdUw.png" /><figcaption>This is where the pretty print button is located</figcaption></figure><p>Now I was able to get a better look. Again to my surprise the code was not even obfuscated in any way. It was only minified (condensed in a single line). Also, it wasn’t using React or any kind of frontend framework, at least my extensions did not detect it.</p><p>Because code was not obfuscated I was able to catch the flow of the game by placing a few breakpoints and just playing the game. Each time I wrote a letter or tried the word or even won/lost different pieces of code would execute.</p><p>Now that I knew the control flow of the game I found out that after the page loads there is a solution variable that gets initialized. It was pulling the value from a single function that would get the current day index and then would look at the specific array for word. <strong>Yes, I found all the words that were available and will be available in further days for the Wordle game</strong>. Then I found the word I guessed on that day and just by looking at the array (because days were used as an index) I could see the word (solution) for the next day.</p><figure><img alt="Screenshot showing Wordle source code and the available words." src="https://cdn-images-1.medium.com/max/1024/1*zZisfyCF2n8rwshTN90L_w.png" /><figcaption>All of the words above were already in the past days so do not worry about the spoilers 😉</figcaption></figure><p>So nice, success… just by knowing the word for the next day ahead of time I could even now win every day on the first try. But I wanted more…</p><p>It was kinda clunky to look at the source code each day and find the answer. I looked at the code some more and I noticed that the game saves a solution variable on its instance. this.solution = solution . When I looked at what this variable is in a current context I found out (to my surprise) that it is actually game-app HTML element (web component).</p><p>So just by opening JavaScript console on Wordle website and executing this piece of code, I was able to console.log solution for the current day.</p><figure><img alt="Image showing JavaScript console and piece of the code to get the solution from the Wordle website." src="https://cdn-images-1.medium.com/max/992/1*wkNH_NhITRL5wFPtaKk9EQ.png" /></figure><p>Nice, right? Now I no longer need to look at the code but I can just execute this little snippet. Also in Chrome if you press the arrow up in JavaScript console it will find the snippet in history so it is even faster. But I wanted more…</p><p>As I practically had the solution I was thinking.. what if I could actually automate the pressing of keys and solution submission? Short answer, I could…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fa7yVQvApqIjRhZE13D%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fa7yVQvApqIjRhZE13D%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fa7yVQvApqIjRhZE13D%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="337" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c476b8b7a3d4d7cb29dc2434e5733af/href">https://medium.com/media/7c476b8b7a3d4d7cb29dc2434e5733af/href</a></iframe><p>Nice, right? That is about it for this article. Feel free to use it on days when you are having a hard time guessing the word or just need a mental break and wish to continue your streak. That is what cheats are for 😉. Also, I know that this takes all the fun out of the game. I personally did not care and had more fun reverse engineering and working on this hack. But that is me. I would like to say kudos to the Wordle creator for the fun game, and also a fun challenge for us who like to tinker with the code 😄. Cheers!</p><p>FYI: I also managed to hack <a href="https://www.lewdlegame.com/">https://www.lewdlegame.com/</a> so if you want to see that leave a clap or let me know on Twitter. 👋</p><p>If you wish to take a closer look at the final script here is a pretty version with comments:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8bcb4a9194e2d4b6f4bff122a9b9ef0/href">https://medium.com/media/b8bcb4a9194e2d4b6f4bff122a9b9ef0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6889101eab73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Doing 100,000 push-ups this year with the help of Siri]]></title>
            <link>https://medium.com/@capJavert/doing-100-000-push-ups-this-year-with-the-help-of-siri-605c3c8eb18f?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/605c3c8eb18f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[siri]]></category>
            <category><![CDATA[voice-assistant]]></category>
            <category><![CDATA[shortcuts]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Fri, 04 Feb 2022 10:48:33 GMT</pubDate>
            <atom:updated>2022-12-31T11:57:25.550Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*54zEc-HO4arFYZdl4rHMfw.jpeg" /><figcaption>Photo by Ketut Subiyanto from <a href="https://www.pexels.com/photo/a-man-doing-push-up-in-the-park-4803730/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p><strong>Update/Spoiler: I did it! </strong><a href="https://pushups.dev/"><strong>https://pushups.dev/</strong></a><strong> 💪 💪 💪</strong></p><p>As a New Year resolution I challenged myself to do 100,000 (one hundred thousand) push-ups until the end of the year. As most people know new year resolutions are often abandoned so I did not lose any time with fancy counters and instead I opened Google Sheet and started logging my progress.</p><figure><img alt="My pushups logging sheet" src="https://cdn-images-1.medium.com/max/1024/1*uOVqOveinFt2F3_I8OW8hw.png" /><figcaption>My push-ups logging sheet</figcaption></figure><p>I basically have:</p><ul><li>cell A1 (sum of total push-ups this year)</li><li>cell B1 (goal for this year)</li><li>cell C1 (push-ups left to do, B1 minus A1)</li></ul><p>And then in the column A i just log my sets as I do them throughout the day.</p><p>There is also Google Sheets mobile app so I was able to log my push-ups throughout the day but if you ever tried editing sheet on your phone you would see it is not the best experience.</p><p>Then one day as I was doing a set of 20 push-ups I heard my girlfriend asking Siri to set some reminder for her work. As I was doing the last 2 push-ups my brain I guess got a little bit more blood so I got an awesome idea.. What if I can make Siri keep count of my push-ups throughout the day?</p><p>I already knew about <a href="https://support.apple.com/en-gb/guide/shortcuts/welcome/ios">Shortcuts</a>, Apple automation app (available for iOS, iPadOS and macOS) that lets you do all kinds of task by using other apps and functions on your iPhone. So after a few more push-ups I decided to give it a try that afternoon.</p><p>Basically what I needed was:</p><ul><li>Access data inside my Google Sheet.</li><li>Update data inside my Google Sheet, same as I was doing manually after each push-ups set that I did.</li><li>Let Siri know how to react when I say “I did some push-ups” and update my Google Sheet automatically</li></ul><p>First I checked <a href="https://www.npmjs.com/package/googleapis">googleapis package on npm</a>. It provides a client with methods to access all features of Google REST API. As Google Sheets are available through that API I was on the right track.</p><p>First I needed to authenticate, I tried few options but creating a service account proved to be the easiest. I followed <a href="https://github.com/googleapis/google-api-nodejs-client#service-account-credentials">these steps</a>. Basically you go to Google Cloud Console, create a service account that has “Editor” role for you account and download JSON file which you then push inside the auth constructor with correct scope.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec6ed831600f3401d97a1286bba1e249/href">https://medium.com/media/ec6ed831600f3401d97a1286bba1e249/href</a></iframe><p>After that I was ready to actually query data from my sheet. This proved to be an easy step, a simple range like string (as you would write in sheets expressions) and we get the cells data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f54b48c43255d16154a70f2c0cf53038/href">https://medium.com/media/f54b48c43255d16154a70f2c0cf53038/href</a></iframe><p>Now that I had the data (my push-up sets) it is time to update the cells, there are multiple ways of doing that but I found that the easiest was to take current values for range and then just append another cell at the end with the number of push-ups I just did.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8331721ff699a33136ed7624cdc7b68/href">https://medium.com/media/d8331721ff699a33136ed7624cdc7b68/href</a></iframe><p>Ok, so I managed to programatically read and update data inside my sheet. When I run my script the Google Sheet inside my browser automatically syncs and shows new data. Let me quickly do 10 more push-ups and then jump on the final part.</p><p>So now I needed to find a way to run my JavaScript code through Siri. Luckily Siri has plenty of options for running code, programs or scripts through Shortcut actions, let’s take a look at the actions that are available:</p><ul><li><strong>Run a bash script</strong> - I managed to run my code through node but then I realised that running a bash script is only supported on macOS Shortcuts so this was a no go.</li><li><strong>Run a bash script through SSH</strong> - managed to do this but I was not in the mood of setting up a whole server or exposing my Mac through ngrok just so I can run one script through SSH.</li><li><strong>Run JavaScript through Safari</strong> - I was already stuck with Node and this was a deal breaker because it would actually open up a website when I called “Hey Siri” and would need to use Browser APIs.</li><li><strong>Run a HTTP server and making an API call - this proved to be solution I went with and here is why…</strong></li></ul><p>There is this thing called <a href="https://vercel.com/docs/concepts/functions/serverless-functions">Serverless Functions</a> on <a href="https://vercel.com/about">Vercel</a>. As I host most of my static sites through them I decided to give serverless a try. This is my serverless function (or lambda).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0555328d101835b7a8cf8085de4d6e0/href">https://medium.com/media/e0555328d101835b7a8cf8085de4d6e0/href</a></iframe><p>If you ever worked with express routes or middlewares this should be pretty familiar syntax without going into much detail to what lambdas actually are and how they work. Basically function gets reqand res objects and then you can send response after it executes your logic. Inside Vercel project you can put files like this inside /api folder and Vercel will automatically expose it on POST /api/pushups endpoint for new deployment. If you wish to read more about the setup you should check <a href="https://vercel.com/docs/get-started">Get Started</a> guide on Vercel. Only note here is that in free tier on Vercel max execution time for single lambda is 5 seconds, but that is plenty for 2 Google API calls I needed to do.</p><p>Now that we have everything ready, let’s assemble it into our first Shortcut. I opened Shortcuts app on my Mac. The interface is pretty straightforward and consists of few building blocks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vu3WD0ocBnOLZ1zyFD1Y6g.png" /><figcaption>Shortcuts app interface on macOS showing my Shortcut</figcaption></figure><p>On the left we have a toolbar where you can search for different actions. I used:</p><ul><li><strong>Ask for input</strong> action which triggers Siri to prompt you for some input, you can even write what do you want her to say. Also you can define type for you input (by selecting <strong>Number</strong> Siri language processor can know what to expect and be more precise).</li><li><strong>Get contents of URL </strong>action<strong> </strong>is basically JavaScript <strong>fetch</strong> equivalent in Shortcuts, It lets you do HTTP requests and works great, you can see the options above. This is where I call POST /api/pushups endpoint to update data inside my Google Sheet.</li><li><strong>Speak</strong> action which lets you use Siri voice feature to make her say something, the input for that can also be dynamic but let’s keep it simple for now.</li></ul><p>Ok, so creating a Shortcut was actually pretty easy, but how do we actually connect it with Siri? Well, you may notice that name of my Shortcut is “I did some push-ups”. By default the name itself is a trigger for you shortcut. So when I say “Hey Siri I did some push-ups” Siri will first look at my shortcuts and if any one of them matches it will trigger actions defined inside. This is the result:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F7WLSpolfbprP0tdT4R%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F7WLSpolfbprP0tdT4R%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F7WLSpolfbprP0tdT4R%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a940d856c3323e0cf351a80d100dc5e/href">https://medium.com/media/8a940d856c3323e0cf351a80d100dc5e/href</a></iframe><p>Pretty neat right? She even made me do even more push-ups because while I was testing this I swear I did like 100 of them 😰 💪</p><p>Later I made Siri responses random by adding few alternative cheers to make things fun. I also added few more Shortcuts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5iJIjqxSBK1-WXhQ0QnQg.png" /><figcaption>Apple also automatically syncs shortcuts across all you devices.</figcaption></figure><p>They were implemented with the same 3 actions and now I can also check my current progress for the day or how much more I need to do in total until end of the year.. actually let’s check right now…</p><p>Me: “Hey Siri How many push-ups left”<br>Siri: 97590 <br>I better do some more push-ups…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl2JdXfSXfh0QPGJH2%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl2JdXfSXfh0QPGJH2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl2JdXfSXfh0QPGJH2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/537a7569da9463724b0b99da51bdd65f/href">https://medium.com/media/537a7569da9463724b0b99da51bdd65f/href</a></iframe><p>Thanks for reading!</p><p>If you are interested in more advanced Shortcut examples and how you can actually do programming in them — check out the links below:</p><ul><li><a href="https://www.reddit.com/r/adventofcode/comments/e5q63j/2019_day_1_did_someone_say_siri/">https://www.reddit.com/r/adventofcode/comments/e5q63j/2019_day_1_did_someone_say_siri/</a></li><li><a href="https://www.reddit.com/r/adventofcode/comments/k5jwgd/2020_day_2_shortcuts_did_someone_say_siri/">https://www.reddit.com/r/adventofcode/comments/k5jwgd/2020_day_2_shortcuts_did_someone_say_siri/</a></li><li><a href="https://www.reddit.com/r/adventofcode/comments/k4vtj6/2020_day_1_did_someone_say_siri/">https://www.reddit.com/r/adventofcode/comments/k4vtj6/2020_day_1_did_someone_say_siri/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=605c3c8eb18f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I was “forced” to HTTPS?!]]></title>
            <link>https://medium.com/@capJavert/how-i-was-forced-to-https-e5a3401da485?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a3401da485</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Tue, 07 Mar 2017 23:38:03 GMT</pubDate>
            <atom:updated>2017-09-05T15:09:37.334Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Website security has become more mandatory over the years and important part of information &amp; data protection when user is interacting with our site is HTTPS protocol and SSL. Encrypting user data when it is sent over the network mostly eliminates many possibilities of data sniffing and alteration which are all popular methods of breaking/hacking some website of web application. As long time web developer I was of course working with HTTPS &amp; SSL on may projects and I am well known with implementations of such (but technical side of that is not a main hero of this story) but again on some personal projects and websites I was ignoring HTTPS only because I was not ready to pay or get a valid certificate. I know, I know, everyone heard of </em><a href="https://letsencrypt.org/"><em>https://letsencrypt.org/</em></a><em> , I did to.. but why then was I ignoring it? Well that for sure is main hero of this story..</em></p><p>For those of you who didn’t heard “Let’s Encrypt” is free and open-source certification authority which can provide valid SSL certificates for your website. In just few automated steps (which was a surprising even for me) you can get that sweet &amp; secure green lock before your page URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nfY-zQk8mSLyzsUzyfzBwQ.jpeg" /><figcaption>Sure feels secure and great :P checkout <a href="https://www.facebook.com/varazdinevents/">https://www.facebook.com/varazdinevents/</a> by the way if you happen to be from <strong>Croatia</strong> or <strong>tourist </strong>in <strong>Croatia</strong>.</figcaption></figure><p>So that’s all great right, but why didn’t I do all of that before and provided my users with secure access to my website. Well for me there were few main reasons that I think many other people may also have:</p><ul><li>Its probably too much of a process, registration, approval etc.</li><li>If it’s free, is it really safe?</li><li>I don’t need HTTPS on my website.</li><li>If I do it, will it really payout?</li><li>Well nobody is forcing me to do it, I’ll just be lazy..</li></ul><p>All really reasonable points right (well fine, some are not so reasonable) , but you get it, right? The last point that is particularly unreasonable was for the irony a thing that actually made me do this. Why? Well, other night Firefox released new version with one particularly reasonable change note:</p><blockquote>Added user warnings for <a href="https://blog.mozilla.org/security/2017/01/20/communicating-the-dangers-of-non-secure-http/">non-secure HTTP pages with logins</a>. Firefox now displays a “This connection is not secure” message when users click into the username and password fields on pages that don’t use HTTPS.</blockquote><p>That means every user that will be even more notified and warned that my site should not be used, and many people, including myself would just go and close the site and never come back. After this first realization rest was pretty easy so for the end I would just like to re-imagine my previous list:</p><ul><li>Let’s Encrypt provides easy and automated process for generating valid and 100% secure SSL certificate. <a href="https://letsencrypt.org/getting-started/">https://letsencrypt.org/getting-started/</a></li><li>Yes it’s free, but so it’s breathing but you don’t think if you will breathe or not?</li><li>You need HTTPS on your website. Security is everything PERIOD.</li><li>It will payout, if nothing check how sexy that green lock is ;)</li><li>Browsers are forcing us for a long time with URL bar notification, they will force even more with steps like those in Firefox. It should be done and we should not be seeing http:// in front of our URL anymore.</li></ul><p>This article also contains my personal opinion and situation, and even everything above that I said is true every person/developer/client should evaluate there own situation and decide what kind of SSL certificate or secure connection implementation is best for specific use case.</p><p>Surf safe,</p><p>Cheers</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a3401da485" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Responsive design — a cure to design headaches]]></title>
            <link>https://medium.com/@capJavert/responsive-design-a-cure-to-design-headaches-646e5f3f104e?source=rss-843ff866a149------2</link>
            <guid isPermaLink="false">https://medium.com/p/646e5f3f104e</guid>
            <dc:creator><![CDATA[Ante Barić]]></dc:creator>
            <pubDate>Mon, 03 Nov 2014 15:45:49 GMT</pubDate>
            <atom:updated>2014-11-03T15:45:49.484Z</atom:updated>
            <content:encoded><![CDATA[<h2>Responsive design — a cure to design headaches</h2><p><strong>When we are talking about new big thing in web design and UX what is the first thing that comes to your mind? For me it is definitely responsive design. Although it has been with us for some time now people just keep talking about it and every day we see our favorite websites get new looks that are responsive and adaptive for any pesky device we try to browse them on. That is the beauty of responsive design. It makes you think and plan even more then before and literally forces you to follow that golden ratio of web design: “Form follows function”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*YEUDgd0aMLKS424U0kh1Bg.jpeg" /><figcaption><strong>Responsive design forces you to always plan few steps ahead..</strong></figcaption></figure><p>When you are looking at responsive websites and how they adapt it always feels so natural, so simple. It feels like if it was made any other way it just wouldn’t be right. For me that is the ultimate goal for every responsive site. You just have to follow the flow. Be simple, because simple does not necessary mean flat and boring. It is so much more. It is about following natural feel and have purpose and explanation for every action. This is the main thing we should ask ourselves when designing and thinking about project/work. Why did I put that there? Why is that button blue? Why is that image there? Why is the font bold? Often designers start with good thinking but then just complex them and lose the main stream. This is why we should often be asking ourselves those questions. It should be some kind of self checking. It does not matter if you are working in a team, yes it is easier then being alone but again you can’t have somebody behind you all the time. When you sit in that chair and put that mouse/pen/scissors in your hand you are all alone with your thoughts and I don’t have to say that it is better to make some changes in first hour then after bad review that is a day away.</p><p>For me a need for thinking a few steps ahead is a great boost. Lets say I am designing website’s navigation few years ago. I would be approaching to a problem this way.</p><blockquote>• how many elements does navigation needs -&gt; quite a lot? -&gt; yes -&gt; then i will make drop downs<br>• OR: how many elements does navigation needs -&gt; few -&gt; i can put nice big font there and also add icons.</blockquote><p>Not so complicated and often I would do really bad design decision, and some of those bad decisions I recognised just recently. I suppose that is the part of maturing as designer and learning on my own mistakes. Ok, but past is the past and we are back in a present day and this is how I would approach this problem today with responsive design in mind.</p><blockquote><em>how many elements does navigation needs -&gt; quite a lot -&gt; would it fit if i scaled the screen down -&gt; how readable will it be -&gt; how can i make it readable -&gt; should I use icons -&gt; ok it works with scaling down -&gt; how does it work with touch screen…</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*H-G1dC8Y6YEFGmR0RVIpjg.jpeg" /><figcaption><strong>It is always good to try different solutions!!</strong></figcaption></figure><p>The questions goes on and with that kind of thinking from the start I can archive that natural feel. Thinking in advance makes you find purpose for everything and you will rarely find a place for an element with out explanation. Also thinking ahead makes you rethink everything so many times that it can get quite confusing and people get lost. This is what I like to call “a design headaches”. What can we do then? Answer to that question I learned from my school teacher in mathematics. Yeah, I know what are you thinking — What the hell math has to do with design and development. Well my teacher said something that can be used in all problems. Over thinking often comes when you forget about simplicity. My teacher always said during the test: If some problem takes you to much to solve — skip to the next one. Of course that does not mean that you should just skip everything and in the end quit. It means that if you can’t solve something you should leave it and try do something different. Scrap the page and start over. Open blank PSD file and start designing all over again. Old people say that smarter guy always lets go. Only the fool wants to go with there head against the wall. This always encourages me to try other things and many times answer to the first question will be answered in second or third “start over” and then you get to mix the results and use all those ideas because now you actually have more answers and ways then just one blocked by a wall.</p><p><strong>This article is kinda nearing to an end so let me just sum down everything I said in one thought. New technologies make our work harder and more complex every day and that is not the bad thing because every one are trying to get better and technology is constantly forcing us to learn more. That is why i love web design, you get to learn all your life. But we don’t often get technology that is not just forcing but showing us a way to get better in everyday life. It shows us that thinking ahead and trying more things actually helps us diverse good stuff from bad and makes us better designers</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=646e5f3f104e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>