Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
jgresalfi / shiftCipher.js
Last active November 24, 2022 06:40
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
//All letters to uppercase. Don't transform non-alphabetic characters (i.e. spaces, punctuation), but do pass them on.
function rot13(str) {
var codeArr = [], seq, final = "";
for (var i = 0; i < str.length; i++) {
uCode = str.charCodeAt([i]);
if ((uCode > 64 && uCode < 78) || (uCode > 96 && uCode < 110)) {
uCode += 13;
codeArr.push(uCode);
} else if ((uCode > 77 && uCode < 91) || (uCode > 109 && uCode < 123)){
@jgresalfi
jgresalfi / divi-button-min-size
Created August 7, 2018 04:49
Divi buttons normally scale with text, which can look crappy. Set a minimum width with this CSS - buttons will scale up depending on text content.
.et_pb_button { min-width: 180px; text-align:center; }
//Or for more targeted styles, apply your own class
.your-css-class .et_pb_button { min-width: 180px; text-align:center; }
@jgresalfi
jgresalfi / yoast_seo_canonical_remove.php
Created September 28, 2017 21:22 — forked from amboutwe/yoast_seo_canonical_change_woocom_shop.php
Code snippets for the Yoast SEO canonical output
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast SEO Canonical From All Pages
* Credit: Yoast Team
* Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8
*/
add_filter( 'wpseo_canonical', '__return_false' );
@jgresalfi
jgresalfi / .eslintrc
Created February 1, 2017 03:47 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@jgresalfi
jgresalfi / .bash_profile
Created January 28, 2017 21:16
bash_profile with some useful alias', etc
#   Set Paths
#   ------------------------------------------------------------
    export PATH="$PATH:/usr/local/bin/"
    export PATH="/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
#   Set Default Editor (change 'Nano' to the editor of your choice)
#   ------------------------------------------------------------
    export EDITOR=/usr/bin/nano
# Misc shortcuts
@jgresalfi
jgresalfi / sortAndAdd.js
Last active September 23, 2016 15:45
Return lowest possible index position of second argument after it is added to the first arg's array and sorted...
function getIndexToIns(arr, num) {
let numArr = arguments[0],
addNum = arguments[1];
numArr.push(addNum);
numArr.sort(function(a, b) {
return a - b;
});
return numArr.indexOf(addNum);
}
@jgresalfi
jgresalfi / seekAndDestroy.js
Created September 21, 2016 03:13
Remove all elements from the initial array that are of the same value as the arguments that follow array.
function destroyer(args) {
var args = [...arguments]
, finalArray = []
, targetArray = args.shift();
finalArray = targetArray.filter(function(el) {
return args.every(function(arg) {
return ( el !== arg);
});
});
@jgresalfi
jgresalfi / falsyBouncer.js
Created September 19, 2016 00:40
Remove all falsy values from an array.
function bouncer(arr) {
var newArr = arr.filter( function(el) {
if (el) {
return el;
}
});
return newArr;
}
bouncer([7, "ate", "", false, 9]);
@jgresalfi
jgresalfi / mutations.js
Created September 18, 2016 12:06
Verify that all characters in second array element are contained in first element.
function mutation(arr) {
var str1 = arr.slice(0, 1).join(" ").toLowerCase(),
str2 = arr.slice(1).join(" ").toLowerCase(),
hits = 0;
for (var i = 0; i < str2.length; i++) {
if (str1.indexOf(str2[i]) !== -1) {
hits += 1;
}
}
if (hits === str2.length) {
@jgresalfi
jgresalfi / chunkyMonkey.js
Created September 15, 2016 03:05
Splitting array into two dimensional array based on size parameter
// Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
function chunkArrayInGroups(arr, size) {
var newArr = [];
beginSlice = 0,
endSlice = size;
for (var i = 0; i < (arr.length/size); i++) {
newArr.push(arr.join("").slice(beginSlice, endSlice).split());
beginSlice += size;