Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

David Miranda panphora

🎯
Focusing
View GitHub Profile
View find-path-of-nested-child-object-inside-parent-object.js
// starting with: object, childObject
// goal
// - given an object/array and a child object/array, give me the path to the child
// some code copied from: https://github.com/moxystudio/js-deep-for-each
function isPlainObject (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
View slugify.js
export default function slugify (str) {
return str
.trim()
.replace(/[^0-9A-Za-z\-\s]/g, " ") // keep alphanumeric, dashes, and spaces
.replace(/ +/g, " ") // replace double spaces with single space
.replace(/ /g, "-") // replace single spaces with single dash
.replace(/\-\-/g, "-") // replace double dashes with single dash
.toLowerCase();
}
View forEachNestedData.js
// DESCRIPTION:
// ============
// loops through all items in a nested object/array
//
// USE:
// ===
// forEachNestedData({currentItem, callback});
//
// OUTPUT:
// ======
View query.js
/*
# Description
A light jQuery replacement that takes a selector and returns an instance with helper methods.
# API
## event delegation
@panphora
panphora / contact.php
Last active Jan 9, 2019 — forked from libryder/contact.php
Super simple PHP contact form in one file
View contact.php
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<?php
if ($_POST['message']) {
$message = $_POST['message'];
View displayTimeLeft.js
function displayTimeLeft (endDate) {
var msUntilDate = endDate - (new Date).getTime();
var secs = Math.floor(msUntilDate / 1000) // total seconds until end date
, mins = Math.floor(secs / 60) // total minutes until end date
, hours = Math.floor(mins / 60) // total hours until end date
, days = Math.floor(hours / 24); // total days until end date
secs = secs % 60; // seconds remaining after dividing by 60 -- for display in countdown
mins = mins % 60; // minutes remaining after dividing by 60 -- for display in countdown
View Native Vanilla JS $.getScript function with callback.js
function getScript(source, callback) {
var scriptElement = document.createElement('script');
var priorScriptElement = document.getElementsByTagName('script')[0];
scriptElement.async = 1;
scriptElement.onload = scriptElement.onreadystatechange = function( _, isAbort ) {
if (isAbort || !scriptElement.readyState || /loaded|complete/.test(scriptElement.readyState) ) {
scriptElement.onload = scriptElement.onreadystatechange = null;
scriptElement = undefined;
View overcast.fm - just show podcast title.js
var $activeEpisodes = $(".episodecell");
var episodesReversedElements = $activeEpisodes.toArray().reverse();
var lastPodcastName;
episodesReversedElements.forEach(function (elem) {
var $activeEpisode = $(elem);
var podcastName = $activeEpisode.find(".titlestack div:first-child").text();
var podcastImgSrc = $activeEpisode.find(".art").attr("src");
if (podcastName !== lastPodcastName) {
View notify.js
const mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
const twilio = new require('twilio')(accountSid, authToken);
export default function notify (to, msg, options) {
if (Array.isArray(to)) {
to.forEach((toSingle) => notify(toSingle, msg, options));
return;
}
if (to.includes("@")) {
@panphora
panphora / expand-podcast-to-see-episodes.js
Created Sep 14, 2017
Modifying overcast.fm to make it more like the app
View expand-podcast-to-see-episodes.js
var $activeEpisodes = $(".episodecell");
var episodesReversedElements = $activeEpisodes.toArray().reverse();
var lastPodcastName;
episodesReversedElements.forEach(function (elem) {
var $activeEpisode = $(elem);
var podcastName = $activeEpisode.find(".titlestack div:first-child").text();
var podcastImgSrc = $activeEpisode.find(".art").attr("src");
if (podcastName !== lastPodcastName) {
You can’t perform that action at this time.