Skip to content

Instantly share code, notes, and snippets.

View AsaoluElijah's full-sized avatar

Asaolu Elijah AsaoluElijah

View GitHub Profile
@AsaoluElijah
AsaoluElijah / backend.js
Created June 28, 2021 00:55
Upload and read uploaded file content in express.js
/*
⚠ First install express and multer by running:
npm i -s express multer
*/
const express = require("express");
const multer = require("multer");
const path = require('path')
@AsaoluElijah
AsaoluElijah / first.md
Last active April 19, 2021 18:58
Nuxt.js store (vuex) cheat sheet 📝

Understanfing vuex (store) in Nuxt.js

NTL,R - A "store" is basically a reactive container that holds your application state. Also, data in a store is univeral, i.e you can access them anywhere in your vue/nuxt.js application

Key Terms

  • State - state is just like data(){return{..}} in normal vue.js, but with different syntax in a store

  • Mutation - mutations also are literally methods:{methodName(){...}} in a normal vue.js file, but with different syntax in a store

@AsaoluElijah
AsaoluElijah / number_with_comma.md
Last active October 1, 2020 11:50
Add comma separator to thousands in JavaScript

Add comma separator to thousands - Javascript

const numberWithCommas = (x) => {
    return Number(x).toLocaleString();
}

Example

@AsaoluElijah
AsaoluElijah / last_elem.md
Last active September 26, 2020 23:36
Get Last Element In An Array - PHP, JavaScript & Python

Get Last Element In An Array - PHP, JavaScript & Python

Javascript

const sampleArray = ["foo", 1, 2,"bar"];
let lastElement = sampleArray[sampleArray.length - 1];
console.log(lastElement) // bar
@AsaoluElijah
AsaoluElijah / readtimecount.md
Last active September 26, 2020 23:42
Calculate Reading Time With PHP - Asaolu Elijah

Calculate Text/Article Reading Time With PHP

    $wordsPerMinute = 200; // Set Average Word Per Minute 
    $word = "This is an example of a very long text!";
    $textLength = explode(" ", $word); // Split word by spaces(this will return an array)
    $textLength = sizeof($textLength); // Get the size of the returned array
    $result = $textLength / $wordsPerMinute;
    $result = ceil($result); // Convert result to integer -- If a double value like 2.7 is returened, it will convert it to 3
 echo $result."min";
@joepie91
joepie91 / express-server-side-rendering.md
Last active February 20, 2024 20:52
Rendering pages server-side with Express (and Pug)

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti
@gokulkrishh
gokulkrishh / media-query.css
Last active May 17, 2024 04:45
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
/* CSS */
@graydon
graydon / country-bounding-boxes.py
Created April 23, 2014 00:03
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),