Skip to content

Instantly share code, notes, and snippets.

View Andaeiii's full-sized avatar
🥦
...look deep into nature, you'd understand everything better.

Ande Caleb Andaeiii

🥦
...look deep into nature, you'd understand everything better.
View GitHub Profile
@Andaeiii
Andaeiii / page.css
Last active August 15, 2022 08:33
How to make a flex item fit into any given space, this one trick might help solve 90% of your flex issues... know when to use display:flex and display: flexbox...
.parent{
display:flex;
flex-direction:column;
}
.child{
flex:1;
}
@Andaeiii
Andaeiii / multiple_jquery_ajax.js
Created June 1, 2022 11:48
Calling multiple ajax calls all at once using JQuery..
//spread the options here....
let xhrURLOptns = {
cors: true,
crossDomain: true,
contentType: 'application/json',
withCredentials: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
@Andaeiii
Andaeiii / ReverseInteger.js
Last active April 11, 2022 08:16
my LeetCode Reverse Integer solution
/*
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Examples ::
1. Input: x = 123, Output: 321
2. Input: x = -123, Output: -321
3. Input: x = 120, Output: 21
//you could spread a string to an array.. rather than splitting it.
@Andaeiii
Andaeiii / axios-redux-interceptor.js
Last active August 15, 2022 08:34
lets say you want to intercept your axios request and also trigger redux-reducers in the process, this is the way to go about it...
import axios from "axios";
import * as config from './Settings'; //get app settings..
import { store } from '../index';
//initialize headers...
const headers = { 'Content-type': 'application/json; charset=UTF-8' };
//use interceptors to catch all axios events.. loading events...
// Add a request interceptor
@Andaeiii
Andaeiii / redux-help.js
Created April 1, 2022 15:39
The basic Redux Setup
//on the index.js - import required libraries..
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import reducers from './reducers/index'; //all reducers combined here..
const store = createStore(reducers, compose(applyMiddleware(thunk)));
// also you refactor the initaal ReactDom.render script to this...
@Andaeiii
Andaeiii / gist:9197b32f3870158c170c9add305c73c0
Last active April 1, 2022 15:40
using bcrypt to encrypt password in nodejs/express applications using moongoose...
//npm install bcrypt --save
import bcrypt from 'bcryptjs';
import UserModel from '../models/users.js';
export default config = {
PORT: 5200,
DB_USER: '.......',
DB_PASS: '.......',
DB_NAME: '.......',
@Andaeiii
Andaeiii / gist:8d9016134042e9ccf2b942dd89ebf8a8
Last active April 1, 2022 15:40
My pagination construct usinga arrays to build up links... with " . . . . " used to denote existing links before and after the active link
let arr = paginate(index, len);
const paginate = (index, len) => {
let curIndex = (index === null) ? 1 : index;
let prvArr = (curIndex == 1) ? [] : (curIndex == 2) ? [1] : (curIndex == 3) ? [1, 2] : ['..', curIndex - 1];
let nxtArr = (curIndex == len) ? [] : (curIndex == len - 1) ? [len] : (curIndex == len - 2) ? [len - 2, len - 1] : [curIndex + 1, '...'];
return [1, ...prvArr, curIndex, ...nxtArr, len]
.filter((v, i, s) => s.indexOf(v) === i)
.map(v => v === '..' ? '...' : v)
.map(v => v === '...' ? '.....' : v);
@Andaeiii
Andaeiii / gist:853efef8907eb34d05c75c8295fea968
Last active April 1, 2022 15:43
Mongo DB short Commands on how to go about the basics in CRUD operations
// mongoDB Shell Commands...
// show dbs - show databases.
// use mycustomDatabase - create database and switch
// db - show me the current database being used...
db.createUser({
user:"antyrii",
pwd: "99wcl34",
@Andaeiii
Andaeiii / gist:9b77dc76822adefce445c88fb40b8a41
Last active April 1, 2022 15:41
..brief insight into the usage of common JS ES6 methods
var arr = String('aminu;ocholi;oketta;odinma;mohammed;fidelis;james;brown;').split(';');
var students = [
{ name: 'aminu', age: 9, class: 'primary 6' },
{ name: 'delilah', age: 84, class: 'primary 6' },
{ name: 'mary', age: 19, class: 'primary 6' },
{ name: 'sujim', age: 12, class: 'primary 6' },
{ name: 'Mohammed', age: 29, class: 'primary 6' },
{ name: 'Tango', age: 84, class: 'primary 6' },
@Andaeiii
Andaeiii / gist:13e508c13e620e4060ff09c35d978f63
Last active April 1, 2022 15:41
From a given array of numbers find the lonely integer
function lonelyinteger(a) {
// Write your code here
let isUnique = (value, index, self) => self.indexOf(value) === index;
let distinct = a.filter(isUnique);
let lonelyint = null;
distinct.forEach(v => {
if (a.filter(index => index == v).length == 1) {
lonelyint = v;
}
});