Skip to content

Instantly share code, notes, and snippets.

View zerostyle's full-sized avatar
🌋
🌊

Joshua Stearns zerostyle

🌋
🌊
View GitHub Profile
@zerostyle
zerostyle / pagination.js
Created February 22, 2019 23:22
Pagination Previous and Next Pattern (React)
const previous = currentIndex => {
const { items, setActiveId } = this.props
const index = (currentIndex - 1 + items.length) % items.length
setActiveId(items[index].id)
}
const next = currentIndex => {
const { items, setActiveId } = this.props
const index = (currentIndex + 1) % items.length
setActiveId(items[index].id)
stage all changedd files for a commit

git add .

stage specific file for a commit

git add /path/to/file

for some reason you want to unstage

git reset unstage all files
git reset /path/to/file unstage specific file

@zerostyle
zerostyle / extract
Created August 23, 2013 20:07
Extract Youtube/Vimeo info from URL
function parseVideoURL(url) {
function getParm(url, base) {
var re = new RegExp("(\\?|&)" + base + "\\=([^&]*)(&|$)");
var matches = url.match(re);
if (matches) {
return(matches[2]);
} else {
return("");
}
@zerostyle
zerostyle / query.js
Last active December 16, 2015 16:49
Minimal css selector
/**
* Minimal CSS selector engine for modern browsers.
* @param {String} selector A string containing a selector expression.
* @param {Node=} opt_context The context to search within.
* @returns {Node|NodeList} An element or list of matched elements.
*/
window.$$ = function(selector, opt_context) {
var context = opt_context || document;
var results = context.querySelectorAll(selector);
@zerostyle
zerostyle / youtubeID.js
Created March 12, 2013 13:01
Get Youtube ID from URL.
var videoURL = 'http://www.youtube.com/watch?v=jkWWJ9W5300';
var videoID = videoURL.replace(/.*youtube.*watch.*v=([a-zA-Z0-9-_]+).*/,'$1');
@zerostyle
zerostyle / retrieve-root.js
Created March 11, 2013 09:11
Retrieve root URL
var root = location.protocol + '//' + location.host;
if(window.addEventListener) { // correlates with media query support
var timer = false
, resize_monitor = function() {
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(function() { _gaq.push(['_trackEvent', 'Resize', 'Resize', 'Resized']); }, 100);
// or log a pageview on a non-existant page if you prefer
@zerostyle
zerostyle / hideAddressBar.js
Last active December 12, 2015 10:39
Hide address bar
function hideAddressBar() {
if( /iphone|ipod|android/gi.test( navigator.userAgent ) && !/crios/gi.test( navigator.userAgent ) ) {
window.addEventListener( 'load', removeAddressBar, false );
window.addEventListener( 'orientationchange', removeAddressBar, false );
}
}
@zerostyle
zerostyle / htmlEncode
Created February 8, 2013 16:24
htmlEncode
function htmlEncode(value){
return $('<div/>').text(value).html();
}
@zerostyle
zerostyle / serializeObject
Last active December 12, 2015 07:58
Turns html form in to an object
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {