Skip to content

Instantly share code, notes, and snippets.

View barkdoll's full-sized avatar

jesse barkdoll

View GitHub Profile
@barkdoll
barkdoll / pipe_helper.php
Last active September 9, 2019 15:04 — forked from taufansena/PHP2.php
PHP Pipeline
<?php
// Derived from
// https://gist.github.com/taufansena/4d198d5a836c7a319e4b3ca3bbce27dc
if ( ! function_exists('make_pipeline') )
{
function make_pipeline(...$funcs)
{
return function($arg) use ($funcs)
@barkdoll
barkdoll / ancestor.js
Last active August 2, 2022 05:44
Check if passed element or any of its parents match the passed CSS selector (returns boolean).
/**
* Check if passed element or any of its ancestors match
* the passed CSS selector string or validation function.
*
* @param {Element} elm - the element whose DOM tree path will be compared against the selector or callback
* @param {string|function} selectorOrCallback - either a DOM selector string or a callback that returns a boolean
* @returns {boolean} true if an element is found to match the selector; false otherwise
*/
function hasAncestor(elm, selectorOrFn)
{
@barkdoll
barkdoll / xml_json.py
Last active May 27, 2019 02:48
Convert between XML and JSON in Python (source: http://tripsintech.com/xml-to-json-python-script-also-json-to-xml/)
# make sure you pip install xmltodict
import xmltodict
import json
# https://stackoverflow.com/a/20725965
def is_json(maybe_json):
try:
json_object = json.loads(maybe_json)
except ValueError as e:
@barkdoll
barkdoll / JapaneseRegex.js
Last active May 24, 2019 19:12 — forked from ryanmcgrath/JapaneseRegex.js
Regex to test for presence of Japanese characters
// REFERENCE UNICODE TABLES:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
// http://www.tamasoft.co.jp/en/general-info/unicode.html
//
// TEST EDITOR:
// http://www.gethifi.com/tools/regex
//
// UNICODE RANGE : DESCRIPTION
//
// 3000-303F : punctuation
@barkdoll
barkdoll / scroll_to_bottom_of_element.js
Last active May 27, 2019 02:51
Trigger and animation that scrolls to the bottom edge of the passed element (IE 11 not supported)
const windowScrollBtm = elm => {
if (typeof window.scrollTo === 'function')
{
// scroll to bottom of output log
const stats = elm.getBoundingClientRect()
const top = stats.top;
const height = stats.height;
const bottom = top + height;
@barkdoll
barkdoll / throttle.py
Last active May 27, 2019 03:16
Throttle decorator function stored for safe keeping (stolen from an SO post)
# https://stackoverflow.com/a/667706
import time
# ##################################################################### #
# If interval is set to False (default), then then the limit is the #
# rate of execution calls per second to the provided function. #
# Example: @throttle(2.5, False) = function is limited to 2.5x/second #
# ##################################################################### #
# If interval is set to True, then the limit is the time in seconds #
@barkdoll
barkdoll / conditional_iterators.py
Last active May 22, 2019 04:07
How to use conditionals inside your iterators, list comprehensions, etc. to filter / map lists
data_to_search = ['stuff', 'yes', 'this', 'is', 'sweet' ]
most_wanted = [ 'sweet', 'stuff' ]
[ print(w) for w in data_to_search if w in most_wanted ]
# Output:
# stuff
# sweet
@barkdoll
barkdoll / onScreen.js
Created May 9, 2019 19:35
Check if an element is [at least partially] in the browser viewport.
const onScreen = elm => {
const getViewportY = () => {
const top = window.pageYOffset || document.documentElement.scrollTop;
const bottom = top + document.documentElement.clientHeight;
return { top, bottom }
}
@barkdoll
barkdoll / index.html
Created April 17, 2019 20:55 — forked from dreyescat/index.html
Webpack config to expose bundle in a variable in the global context
<html>
<head>
</head>
<body>
<script src="lib/yourlib.js"></script>
<script>
window.onload = function () {
EntryPoint.run();
};
</script>
@barkdoll
barkdoll / debounce.js
Last active April 4, 2019 15:32
A debounce function to kill a function running if called again; credit to Taylor Case - https://medium.com/@TCAS3/debounce-deep-dive-javascript-es6-e6f8d983b7a1
const debounce = (fn, time) => {
let timeout;
return function() {
const functionCall = () => fn.apply(this, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}