Skip to content

Instantly share code, notes, and snippets.

View samakintunde's full-sized avatar
🛠️
Building stuff...

Samuel Akintunde samakintunde

🛠️
Building stuff...
View GitHub Profile
@samakintunde
samakintunde / fs-rename.js
Last active July 21, 2020 21:16
fs-rename: This function will rename every instance of the string passed in in the directory name or file name. You can also choose to exclude select folders and files. Think about renaming css files to scss or prefixed directories..
#!/bin/sh node
const fs = require("fs");
const path = require("path");
const parseArgs = require("minimist");
const argv = parseArgs(process.argv.slice(2));
// readDirectory gets the files and folders of a directory, excluding an unwanted list
function readDirectory(directory, excludes) {
console.log(`Performing operations in ${directory}`);
@samakintunde
samakintunde / dom-helper.js
Created October 27, 2019 11:39 — forked from SitePointEditors/dom-helper.js
Mini jQuery, sort of.
/**
* A collection of helper prototype for everyday DOM traversal, manipulation,
* and event binding. Sort of a minimalist jQuery, mainly for demonstration
* purposes. MIT @ m3g4p0p
*/
window.$ = (function (undefined) {
/**
* Duration constants
* @type {Object}
@samakintunde
samakintunde / makeObjectsInArrayUnique.js
Created October 23, 2019 08:50
Make every object in an Array unique.
const makeObjectsOfArrayUnique = (arr, property) => {
// Array to keep unique items
const result = [];
// We're using the Map's in-built ability to filter duplicates
const map = new Map();
for (const element of arr) {
if (!map.has(element[property])) {
map.set(element[property], true);
result.push(element);
@samakintunde
samakintunde / string-to-node-dom-helper.js
Created March 28, 2019 11:42
A function that converts can help convert Strings to DOM Nodes using . functional approach. Courtesy of @WickyNilliams.
function el(tag, attrs, children = []) {
const element = document.createElement(tag);
if (attrs) {
Object.entries(attrs).forEach([attr, value] => {
element.setAttribute(attr, value);
});
}
if (typeof children === 'string') {
@samakintunde
samakintunde / setEqualHeights.js
Created March 15, 2019 13:41
Set slides in carousel to height of highest card
let cards = document.querySelectorAll(".js-carousel .card");
cards = Array.from(cards);
// Set slides in carousel to height of highest card
const setEqualHeight = () => {
let cardHeights = [];
cards.forEach(card => {
let height = window.getComputedStyle(card).height;
height = Number(height.slice(0, -2));
@samakintunde
samakintunde / code-test.js
Created September 30, 2018 19:28
Chaser Code Test
function orderObjectsByRanking(objectArr) {
objectArr.sort((a,b) => {
if(a.ranking > b.ranking) return 1;
if(a.ranking < b.ranking) return -1;
return 0;
});
}
@samakintunde
samakintunde / webdev_online_resources.md
Created July 16, 2018 23:23 — forked from bradtraversy/webdev_online_resources.md
Online Resources For Web Developers (No Downloading)