Skip to content

Instantly share code, notes, and snippets.

View Deityhub's full-sized avatar
🌍
Making everyday life better

Chizoba Jude Ojini Deityhub

🌍
Making everyday life better
  • 011011010110000101110100011100100110100101111000
View GitHub Profile
@Deityhub
Deityhub / rotateMatrixToLeft.js
Created August 28, 2022 16:23
Rotate 2D array matrix to the left (one step at a time)
function rotateMatrix(rowCount, colCount, matrix) {
let row = 0;
let col = 0;
let prev;
let curr;
/*
row - Starting row index
rowCount - ending row index
col - starting column index
@Deityhub
Deityhub / rotateMatrixToRight.js
Created August 28, 2022 16:22
Rotate 2D Matrix to the right (one step at a time)
function rotateMatrix(rowCount, colCount, matrix) {
let row = 0;
let col = 0;
let prev;
let curr;
/*
row - Starting row index
rowCount - ending row index
col - starting column index
@Deityhub
Deityhub / rotate.js
Created August 27, 2022 15:44
Rotate a 2D array matrix by 90 degrees
function rotate(arr) {
const arrLength = arr.length;
let matrix = Array.from({length: arrLength}, () => []);
for(let i = 0; i < arr.length; i++) {
for(let j = 0; j < arr.length; j++) {
let temp = arr[j][i];
matrix[i][arrLength - 1 - j] = temp
}
@Deityhub
Deityhub / reverse.js
Last active August 27, 2022 15:42
Reverse an array in place by swapping
function reverseArr(arr) {
const n = parseInt(arr.length/2);
for(let i = 0; i < n; i++) {
const temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
return arr;
}
@Deityhub
Deityhub / express_postgress_knex.md
Created February 8, 2022 11:39 — forked from laurenfazah/express_postgress_knex.md
Cheat Sheet: Setting up Express with Postgres via Knex

Express & Postgres via Knex

Note: <example> is meant to denote text replaced by you (including brackets).

Setup

// global dependencies
npm install -g knex
@Deityhub
Deityhub / log.js
Created November 9, 2021 15:36
Log request middleware
// log request middleware
const getActualRequestDurationInMilliseconds = start => {
const NS_PER_SEC = 1e9; // convert to nanoseconds
const NS_TO_MS = 1e6; // convert to milliseconds
const diff = process.hrtime(start);
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
};
app.use(function(req, res, next) {
const current_datetime = new Date();
const formatted_date =
@Deityhub
Deityhub / creatServer.js
Created March 23, 2021 19:43
Create server handler for using the same port on the both http and https
function createServer(opts, handler) {
const server = net.createServer(socket => {
socket.once('data', buffer => {
// Pause the socket
socket.pause();
// Determine if this is an HTTP(s) request
const byte = buffer[0];
let protocol;
@Deityhub
Deityhub / 1_kubernetes_on_macOS.md
Created January 26, 2021 20:04 — forked from kevin-smets/1_kubernetes_on_macOS.md
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

/**
* @param {string} text the content to copy to clipboard
* @description copies text to clipboard
*/
export default function(text) {
/* Get the text field */
const el = document.createElement('textarea');
el.value = text;
@Deityhub
Deityhub / curl.md
Created July 5, 2020 16:33 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.