Skip to content

Instantly share code, notes, and snippets.

View ez-javascript's full-sized avatar
💛
Focusing

EZ JavaScript ez-javascript

💛
Focusing
View GitHub Profile
@ez-javascript
ez-javascript / javascript_object_size_method1.js
Created October 27, 2020 20:53
Get the size of an object in JavaScript!
/*
Get the size of an object in JavaScript!
Method 1: Manually counting each property
Take a look at the original Instagram post!
https://www.instagram.com/p/CG3GNHiAFbq/
*/
const getSize = (object) => {
let size = 0;
@ez-javascript
ez-javascript / javascript_time_date_object.js
Created October 25, 2020 22:19
Retrieving the current time in JavaScript—here are three ways to do it!
/*
Retrieving the current time in JavaScript—here are three ways to do it!
Method 2: Date object
Take a look at the original Instagram post!
https://www.instagram.com/p/CGyGduqgiVV/
*/
let now = new Date();
// Create timestamp
@ez-javascript
ez-javascript / cryptojs_message_encryption_decryption.js
Created October 23, 2020 20:44
Encrypt and decrypt messages easily with CryptoJS!
/*
Encrypt and decrypt messages easily with CryptoJS!
Take a look at the original Instagram post!
https://www.instagram.com/p/CGsyg27gO0E/
*/
const { AES, enc } = require("crypto-js");
// Your password (it should be kept in a seperate file, but
// for the sake of simplicity it's hardcoded!)
@ez-javascript
ez-javascript / simple_weather_app.js
Created October 22, 2020 19:41
A really simple weather app in NodeJS.
/*
A really simple weather app in NodeJS.
(Hardcoded location. See other file for version with process args.)
Take a look at the original Instagram post!
https://www.instagram.com/p/CGqGcCUggYK/
*/
const weather = require("weather");
// Options for the search
@ez-javascript
ez-javascript / javascript_labels.js
Last active October 22, 2020 19:31
All about JavaScript labels!
/*
JavaScript labels: usage with nested for-loops!
Take a look at the original Instagram post!
https://www.instagram.com/p/CGkxCv6ge1U/
*/
outerLoop:
for(let i = 0; i < 3; i++) {
innerLoop:
for(let j = 0; j < 3; j++) {
@ez-javascript
ez-javascript / static_keyword_in_javascript.js
Last active September 26, 2020 20:02
Static keyword in JavaScript: what, why and when.
/*
Static keyword in JavaScript: what, why and when.
Take a look at the original Instagram post!
https://www.instagram.com/p/CFnMKRbArjI/
*/
class Person {
// A static method
static hello() {
console.log("Hello");
@ez-javascript
ez-javascript / data.json
Created September 9, 2020 13:51
JavaScript: JSON vs YAML, which one should I use?
{
"name": "John",
"age": 20,
"languages": [
"JavaScript",
"PHP"
]
}
@ez-javascript
ez-javascript / javascript_queues.js
Created September 1, 2020 21:53
Data structures: Queues in JavaScript.
/*
Data structures: Queues in JavaScript.
Take a look at the original Instagram post!
https://www.instagram.com/p/CEnAZEDgiby/
*/
class Queue {
constructor() {
// List of elements
this.elements = [];
@ez-javascript
ez-javascript / javascript_RxJS.js
Last active September 5, 2020 20:04
RxJS Observables: How do they work?
/*
RxJS Observables: How do they work?
Take a look at the original Instagram post!
https://www.instagram.com/p/CD7MXBSAlwm/
*/
const { Observable } = require("rxjs");
// Function to generate numbers between 1 and 10
const random = () => Math.floor(Math.random() * (10 - 1) + 1);
@ez-javascript
ez-javascript / javascript_OOP.js
Last active September 5, 2020 20:04
What's the "super" keyword in JavaScript?
/*
What's the "super" keyword in JavaScript?
This gist and the Instagram post assume that you already have a
basic understanding of object-oriented programming.
Take a look at the original Instagram post!
https://www.instagram.com/p/CDtbJvVgpuU/
*/
// Parent class
class Shape {