Skip to content

Instantly share code, notes, and snippets.

@Joopmicroop
Joopmicroop / bash open urlList in Chrome
Created February 2, 2018 15:33
bash open urlList in Chrome
#!/bin/bash
if command -v chrome 1>/dev/null; then
chromeUrlList=(
"https://google.com"
"https://gmail.com"
)
# create subShell
( chrome ${chromeUrlList[*]} &>/dev/null 2>/dev/null & )
fi
@Joopmicroop
Joopmicroop / Helper functions
Last active November 13, 2019 10:36
dom helper functions
function CssHelper(){
// checkers
this.isPx = function isPx(v){ return /px/gi.test(v); };
this.isPc = function isPc(v){ return /%|pc/gi.test(v); };
this.isVal = function isVal(v){ return !isNaN(v); };
// converters
this.toVal = function toVal(v){ return parseFloat(v); };
this.toUnit = function toUnit(unit, v){ return this.toVal(v)+unit; };
this.toPx = this.toUnit.bind(this, 'px');
this.toPc = this.toUnit.bind(this, '%');
@Joopmicroop
Joopmicroop / extractRSSFromItunesURL
Created November 8, 2018 13:20
extract the rss feed from an itunes podcast url
#!/bin/bash
#URL="https://itunes.apple.com/us/podcast/surprisingly-awesome/id1053898"
isValidURLRegex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $1 =~ $isValidURLRegex ]]
then
# extract id from url
ID=$(echo $1 | grep -oP 'id\d+' | grep -oP '\d+')
else
ID=$1
@Joopmicroop
Joopmicroop / saveSelection and restoreSelection
Created August 30, 2018 13:41
to save and restore the cursor position/selection of eg contentEditable elements after update render
var saveSelection, restoreSelection;
if (window.getSelection && document.createRange) {
saveSelection = function(containerEl) {
var range = window.getSelection().getRangeAt(0);
var preSelectionRange = range.cloneRange();
preSelectionRange.selectNodeContents(containerEl);
preSelectionRange.setEnd(range.startContainer, range.startOffset);
var start = preSelectionRange.toString().length;
@Joopmicroop
Joopmicroop / compareSentences
Last active June 1, 2018 16:17
compare sentences / equality fitness function
function calculateStringFitness(str0,str1,opt){
function countMatches(a0, a1){
var matches, pos0, pos1, matchObj;
matches = pos0 = pos1 = 0;
matchObj = {};
a0 = a0.sort();
a1 = a1.sort();
// match everything within style tags
(?<=(<style[^>]*>))([^]+?)(?=(<\/style>))
// writen but untested
function HashTable(obj){
this.length = 0;
this.items = { };
for(var p in obj){
if(obj.hasOwnProperty(p)){
this.items[p] = obj[p];
this.length++;
@Joopmicroop
Joopmicroop / onCD bash
Last active January 5, 2018 19:58
run script on cd'ing into and out of a directory
# onCD
# -----
# Place the code below in your .bashrc file.
# then place a script in any directory, named 'oncd.sh'
# the script will receive an argument of 'enter' or 'leave'
# when cd'ing into or out of the directory.
#(doesn't work with "shopt -s autocd", use COMMAND_PROMPT for that)
cd () {
oldpath=$PWD
*{
margin:0;
padding:0;
border:0;
box-sizing: border-box
}
html, body{
height:100%;
width:100%;
@Joopmicroop
Joopmicroop / unified amd, exports, window
Last active August 12, 2016 09:12
write modules compatible for amd require/exports or root/window
(function (root, factory) {
if (typeof define === "function" && define.amd) define(factory); // amd
else if(typeof module == 'object') module.exports = factory(); // node require
else if(typeof exports == 'object') exports = factory(); // browserify
else root.ResizeSensor = factory(); // root/window
})(this, function () {
// code here
// return foo;
})