Skip to content

Instantly share code, notes, and snippets.

@Chizaram-Igolo
Chizaram-Igolo / db.php
Created November 2, 2022 19:22 — forked from gskema/db.php
PHP PDO bulk INSERT
<?php
class Db
{
public function batchInsert($table, array $rows, array $columns = array())
{
// Is array empty? Nothing to insert!
if (empty($rows)) {
return true;
}
npm install -g npm-check-updates
ncu -u
npm update
npm install
@Chizaram-Igolo
Chizaram-Igolo / Re-sync Fork.txt
Last active March 7, 2024 12:31
Re-syncing a Fork that is Commit(s) ahead of Upstream/Master
If you ever get into out-of-sync trouble, clear your working tree on your fork (git add && git commit && git push) and
run the following:
git checkout master
// git fetch upstream (add this for a slightly safer solution)
git reset --hard upstream/master
git push --force
React Firebase Check List (Revision 1.0):
Dependencies:
i) Node and NPM
ii) firebase-tools
iii) VSCode
This checklist is suitable for you if:
i) You use Windows operating system.
ii) You use ReactJS as your development library and Firebase as your BaaS.
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
db.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
});
});
// Add a first document with a generated ID.
db.collection("users").add({
first: "Ada",
last: "Lovelace",
born: 1815
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
@Chizaram-Igolo
Chizaram-Igolo / async-func-callback.js
Created July 20, 2021 23:42
Asynchronous Javascript - Old Function Callbacks, Promises, Promise Chaining, Promise Chaining with Returned Promises, Async/Await Functions.
// Asynchronous Function Callback
function loadAsset(url, cb) {
let xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.addEventListener("readystatechange", () => {
if (xhr.readyState === 4 && xhr.status === 200) {
cb(undefined, JSON.parse(xhr.responseText));
} else if (xhr.readyState === 4) {
fetch("https://jsonplaceholder.typicode.com/todos/")
.then((response) => response.json())
.then(data => {
console.log(data)
})
.catch((err) => {
console.log('rejected', err)
})
function getTodos(resource) {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.addEventListener("readystatechange", () => {
if (request.readyState === 4 && request.status === 200) {
resolve(request.responseText);
} else if (request.readyState === 4) {
reject("Error getting resource");
}