Skip to content

Instantly share code, notes, and snippets.

View Loonz806's full-sized avatar
🤩
Every person is a contributor to your journey, open minds and be kind

Lenny Peters Loonz806

🤩
Every person is a contributor to your journey, open minds and be kind
View GitHub Profile

1. The Ternary Operator

if / else replacement

Longhand:

const x = 20;
let answer;

if (x > 10) {
    answer = "greater than 10";
@Loonz806
Loonz806 / prepMethod.md
Last active April 25, 2022 21:56
public speaking

P.R.E.P. Method

Point of view

share your perspective and keep it short and sweet, two sentences at most

Reason

justify your view, One or two bullets but not more than three or you lose your audience

Example, Evidence, or Experience

Show an example, personal experience or evidence to support your reasoning

STARL Method

Situation

background context on the situation

  • Tell me about the situation.
  • Who was involved?
  • How did everyone get here?
  • What was your role at the time?
import { useState, useEffect } from "react";
const CACHE = {};
export default function useStaleRefresh(url, defaultValue = []) {
const [data, setData] = useState(defaultValue);
const [isLoading, setLoading] = useState(true);
useEffect(() => {
// cacheID is how a cache is identified against a unique request
const cacheID = url;
@Loonz806
Loonz806 / getIpadModel.js
Created November 20, 2020 18:18
How to detect type of iPad model.
// iPad model checks.
const getiPadModel = () => {
if (window.screen.height / window.screen.width == 1024 / 768) {
// iPad, iPad 2, iPad Mini
if (window.devicePixelRatio == 1) {
return "iPad 1, iPad 2, iPad Mini 1";
}
// iPad 3, 4, 5, Mini 2, Mini 3, Mini 4, Air, Air 2, Pro 9.7
else {
return "iPad 3, iPad 4, iPad 5, iPad Air 1, iPad Air 2, iPad Mini 2, iPad Mini 3, iPad Mini 4, iPad Pro 9.7";

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@Loonz806
Loonz806 / pubSub.js
Created May 1, 2020 16:21
Pubsub pattern
let subscribers = {};
module.exports = {
// method to publish an update
publish(event, data) {
if (!subscribers[event]) return;
subscribers[event].forEach(subscriberCallback =>
subscriberCallback(data));
},
// method to subscribe an update
subscribe(event, callback) {
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
console.log("check failed?");
} else {
fs(window.TEMPORARY,
100,
console.log.bind(console, "not in incognito mode"),
console.log.bind(console, "incognito mode"));
}
@Loonz806
Loonz806 / deferScriptExecution.js
Created March 23, 2020 17:05
A defer script execution snippet for only executing a callback on user interaction
function deferStartTillUserAction(cb) {
var locked = true;
var didClick = false;
var didScroll = false;
function unlock() {
if (locked) {
locked = false;
cb();
}
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"