This Week I Learned #8
John Paul Ada
Posted on July 5, 2018
JavaScript, Python, Reason, and more! Fun tech stuff to look forward to!
JavaScript Proxy
Proxies in JavaScript allow us to add hooks to objects. For example, when a value in an object is being extracted or being set, we can execute some side-effect or override the value being returned. This is helpful if you want to do some simple pub-sub actions, e.g. informing other objects if an object's value has changed. This can also be helpful if you want to do validation, e.g. the value in the object will remain the same if the value it was set with was invalid. This is a very powerful feature so check it out and see what creative ways you can use JavaScript proxies in!
Here's a basic validation example from MDN:
let validator = {
set: function(obj, prop, value) {
if (prop === 'age') {
if (!Number.isInteger(value)) {
throw new TypeError('The age is not an integer');
}
if (value > 200) {
throw new RangeError('The age seems invalid');
}
}
// The default behavior to store the value
obj[prop] = value;
// Indicate success
return true;
}
};
let person = new Proxy({}, validator);
person.age = 100;
console.log(person.age); // 100
person.age = 'young'; // Throws an exception
person.age = 300; // Throws an exception
FormSpree
One of the things that throw you off when you want to create a landing page or just a simple static homepage is the issue of forms. Where would you send them if you don't have a server?
FormSpree deals with that problem by receiving the data from the form and forwarding the data to your email. It has a pretty okay free tier and for unlimited amounts of emails you just have to pay $10 per month.
<form action="https://formspree.io/your@email.com"
method="POST">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>
for-await-of
Sometimes it's helpful to put Promises in an array and loop through their resolved values, like when making a lot of requests via fetch
or axios
. When dealing with an array of Promises, we usually use Promise.all to make sure they're all resolved, right? The problem with this is that it will wait for all of the Promises to resolve first before we can actually work with them. What we want is to get each request and start working with them the moment they resolve. How do we do that? We can use the for-await-of JavaScript syntax.
Here's an example from from Dr. Axel Rauschmayer's blog. Basically instead of using Promise.all like this:
for (const x of await Promise.all(syncIterableOverPromises)) {
// Do something with x
};
we do this instead:
for await (const x of syncIterableOverPromises) {
// Do something with x
};
This will get each x
in the syncIterableOverPromises
iterable and then wait for it to resolve then proceed to the body of the for loop to work with the resolved x
. This makes it easier to start working with a list of Promises without waiting for all of them to complete.
Clementine
If you have difficulty trying to build your application specs and the cost for building the application, you can use Clementine for that! Clementine guides you through the process of building your app specs, and at the end, estimates how much building the application would cost.
Vibora
If you like building Web APIs with Python with Django or Flask, why not take Vibora out for a spin? Vibora is a new web framework for building fast APIs, faster than most of the popular Python web frameworks out there. Inspired by Flask, Vibora is pretty easy to use and it is fully asynchronous. Check out their benchmarks on their site to see for yourself!
Transfer.sh
If you want to share files for free without leaving your terminal, transfer.sh is the thing or you! If you the installation instructions, you'll have a transfer binary that you can run to upload a file. After uploading, you'll be presented with the download link you can send to your friends! The link lasts for 14 days and can be as big as 10 GB. The best thing is that it's free! Check it out!
Sail CI
If you want a hosted CI solution that's cheap, easy to use, and has a great free tier, check out Sail CI! You have 1000 build minutes per month which is already good enough compared to most hosted solutions out there. It's also pretty to setup! Just go to your project directory, run sail init
, define your pipeline in a .sail
file and you're all set!
It currently only supports Github, but we'll probably see support on the others like Gitlab and Bitbucket in the near future!
Why do I Procrastinate
This site asks you some questions and figures out why you're procrastinating. After that, it gives you recommendations on what to do to stop procrastinating and start working!
ML5.js
TensorFlow.js took the web world by storm but to some still feel it is complicated even for common tasks. ML5.js makes this simpler by having a relatively easier API for dealing with common tasks like image classification. If you've been itching to do Machine Learning on the web, try this out!
Mkcert
When developing for the web, sometimes we need to test our applications with HTTPS enabled. The problem is that most of the time, that is difficult - so features that require HTTPS to work can't be tested on locally. Mkcert helps us with this problem by being a zero-config tool for creating certificates for HTTPS. Next time you need HTTPS for local testing, try Mkcert out!
Get HTTPS for Free
Let's be honest - the process of getting a certificate from Let's Encrypt is not a piece of cake. Get HTTPS for Free helps you create your own certificates and get them signed with Let's Encrypt with relatively easy to understand instructions - and all you need is a terminal window and the single page of the site. The site doesn't look too great, but it works!
Side note: I'm trying to recreate the site with another design - if you want to help me out here: https://github.com/johnpaulada/gethttpsforfree-redesign!
Railway-Oriented Programming
When developing applications, we usually focus on the happy path - on how the application should be behaving, but when you think about it, errors are also part of the program. Therefore, we also have to assume errors are going to happen and assume that there will be two paths: the happy path and the failure path. That's what Railway-Oriented Programming is all about. Our program should always take those two paths in consideration. Check it out if you're interested! 😄
ReasonML Philippines
ReasonML is an awesome language created by Jordan Walke, the same guy who created React at Facebook. I've been very interested in it since the time I heard it last year during ReactConf 2017 during Cheng Lou's talk. I noticed that there weren't a lot of ReasonML enthusiasts in the Philippines - heck there wasn't even a Facebook group! So I created one! If you're from the Philippines, or even if you're just plain interested in ReasonML, please join us in the group! 😃
Posted on July 5, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.