Skip to content

Instantly share code, notes, and snippets.

View ourmaninamsterdam's full-sized avatar

Justin Perry ourmaninamsterdam

View GitHub Profile
@ourmaninamsterdam
ourmaninamsterdam / gist:4555503
Last active December 11, 2015 05:58
Finds and removes item from array
/**
* remove_from_array()
* Based on str param supplied, finds and removes matching item from array
* @param {Array} array Array to query
* @param {String} str String to look for
* @return {Bool} returns true after item is found and remove from array
*/
function remove_from_array(array, str) {
var i;
for(i = 0; i < array.length; i++){
@ourmaninamsterdam
ourmaninamsterdam / gist:4555610
Created January 17, 2013 12:27
Returns an array of values from a JSON array
/**
* get_keys()
* @param {Array} data JSON array
* @param {String} label Value to return
* @return {Array} array of matched property
*/
function get_keys(data, label) {
var key, values = [];
for(key in data){
values.push(data[key][label]);
@ourmaninamsterdam
ourmaninamsterdam / jquery.microcarousel.js
Last active February 23, 2019 19:24
Super compact jQuery vertical text carousel plugin, with variable content-based slide latency. < 0.5k minified.
;(function($) {
$.fn.microcarousel = function(options) {
var settings = $.extend({
timer_latency : 40
}, options);
return this.each(function() {
var timer, $wrapper = $(this);
$wrapper.children().addClass("slide");
@ourmaninamsterdam
ourmaninamsterdam / index.html
Last active December 11, 2015 07:09
**BETA**. jQuery plugin to independently animate elements using their data attributes used for animation properties.
<!DOCTYPE html>
<html lang="en-gb">
<head>
<title>Animator</title>
<meta charset="utf-8" />
<style>
.block{
background: #ccc;
box-sizing: border-box;
height: 100px;
@ourmaninamsterdam
ourmaninamsterdam / simple-pagination.html
Created January 24, 2013 18:50
Simple JS pagination script that can be easily modified to accept a JSON array. Known bug where pages 11-20 are skipped when paging through.
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Simple JavaScript pagination</title>
<meta charset="UTF-8">
<style>
div{
position: relative;
}
#stage{
@ourmaninamsterdam
ourmaninamsterdam / gist:5232000
Created March 24, 2013 13:37
Get computed style of elements and pseudo elements
function getComputedStyle(elem, property, pseudoelem){
return window.getComputedStyle(elem, (pseudoelem || null)).getPropertyValue(property);
};
getComputedStyle(myElem, "height").width;
getComputedStyle(myElem, "height", ":after").width;
@ourmaninamsterdam
ourmaninamsterdam / gist:5319295
Created April 5, 2013 13:32
Dustin Diaz object string supplanter
function substitute(s, o){
return s.replace( /{([^{}]*)}/g ,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
}
substitute("My name is {name} and I work at {workplace}",{
name: "Justin Perry",
@ourmaninamsterdam
ourmaninamsterdam / accordion.css
Last active December 16, 2015 01:19
Pure CSS3 Accordion with Deep link and inter-slide navigation. Haven't tested but should work IE8, just without animations. No fallbacks for IE7 at this time. Trying to figure out how to close an open slide when clicking the open link again.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
@ourmaninamsterdam
ourmaninamsterdam / gist:5370657
Last active December 16, 2015 03:29
Debug list. Accepts primitive values and arrays.
function log(){
var debug = document.getElementById('debug'),
reverse = true,
log = Array.prototype.slice.call( arguments, 0 ).join('{join}').replace(/{join}/g, '<br>');
debug.innerHTML = (reverse)? log + '<br>' + debug.innerHTML : debug.innerHTML + '<br>' + log;
}
log(myObject.name, myObject.thing, 'With a label: ' + myObject.label);
@ourmaninamsterdam
ourmaninamsterdam / gist:5370671
Last active December 16, 2015 03:29
Filters an array based on filter. Accepts regex or simple string. Returns a filtered array.
var filter = '.png';
var list = ['userimage105325.png','userimage669.jpg','userimage6929.png','userimage85818.gif'];
function filterArray(array, filter){
var i, filteredArray = [];
filter = new RegExp(filter, 'g');
for( i = 0, len = array.length; i < len; i++ ){
if( array[i].toString().match(filter) ){
filteredArray.push( array[i] );
}