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 / bitwise_permissions.js
Last active February 8, 2022 08:42
Bitwise permissions in JavaScript.
/*
Bitwise permissions in JavaScript.
Take a look at the original Instagram post for an explanation as to how this works!
https://www.instagram.com/p/CB1QSWIAq9d
*/
// Permissions
const read = 1;
const write = 2;
const remove = 4;
@ez-javascript
ez-javascript / cryptonator.js
Created June 28, 2020 16:01
Working with the Cryptonator API in NodeJS.
/*
Working with the Cryptonator API in NodeJS.
Take a look at the original Instagram post!
https://www.instagram.com/p/CB_BQ87ldEA/
*/
const axios = require("axios");
// Cryptonator API (use "https://api.crytonator.com/api/full" for additional data)
const URL = "https://api.crytonator.com/api/ticker";
@ez-javascript
ez-javascript / object_to_map.js
Last active September 5, 2020 20:04
Convert an object into an ES6 map with this simple yet effective trick.
/*
Convert an object into an ES6 map with this simple yet effective trick.
Take a look at the original Instagram post!
https://www.instagram.com/p/CCJw3YJAvO0/
*/
const data = {
name: "John Doe",
age: 20,
address: "Main Street 123"
@ez-javascript
ez-javascript / detect_online_connection.js
Last active September 5, 2020 20:31
Detect changes in internet connection using nothing but pure JavaScript.
/*
Detect changes in internet connection using nothing but pure JavaScript.
Take a look at the original Instagram post!
https://www.instagram.com/p/CCWs55wgWjM/
*/
let isOnline = navigator.onLine;
if(isOnline) {
// Do something...
@ez-javascript
ez-javascript / get_current_time_ISO.js
Last active September 5, 2020 20:04
Get the current time using three different methods!
/*
Get the current time using the JavaScript Date object and
converting it into an ISO string.
Take a look at the original Instagram post!
https://www.instagram.com/p/CCZZV7MgECh/
*/
// Retrieve current data
const now = new Date();
@ez-javascript
ez-javascript / merge_two_maps.js
Last active September 5, 2020 20:04
Merge two or more maps using the ES6 spread syntax.
/*
Merge two or more maps using the ES6 spread syntax.
Take a look at the original Instagram post!
https://www.instagram.com/p/CCjj7ySgV_N/
*/
let map1 = new Map([
["name", "John Doe"],
["age", 20]
]);
@ez-javascript
ez-javascript / basic_array_sorting.js
Last active September 5, 2020 20:04
Basic and compare function array sorting in JavaScript.
/*
Basic array sorting with Array.sort().
Take a look at the original Instagram post!
https://www.instagram.com/p/CCt5fSJgom7/
*/
let array = [ "Hello", 3, 1, 7, "World" ];
array.sort();
@ez-javascript
ez-javascript / get_IP_Geolocation.js
Last active September 5, 2020 20:04
Retrieve an IP geolocation using JavaScript.
/*
Retrieve an IP geolocation using JavaScript.
This API has great docs, make sure to check them out if you're interested
in using it: https://ip-api.com/docs
Take a look at the original Instagram post!
https://www.instagram.com/p/CDGrgoLgWbi/
*/
// You can use any other HTTP library, of course!
const axios = require("axios");
@ez-javascript
ez-javascript / this_in_JavaScript_constructors.js
Last active September 1, 2020 21:55
What's "this" in JavaScript?
/*
What's "this" in JavaScript (inside of a constructor)?
Take a look at the original Instagram post!
https://www.instagram.com/p/CDrcMOgAQgO/
*/
function Person(name) {
this.name = name;
}
@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 {