Skip to content

Instantly share code, notes, and snippets.

View jorgepinon's full-sized avatar

Jorge Luis Piñon jorgepinon

View GitHub Profile
@jorgepinon
jorgepinon / css unicode icons
Created February 26, 2014 15:53
Use escaped unicode for css pseudo-element content value
// usage: <span aria-hidden="true" class="u-icon--chevron--left"></span>
// →
.u-icon--arrow--right:before {
content: '\279E';
}
// ❯
.u-icon--chevron--right:before {
content: '\276F';
@jorgepinon
jorgepinon / toggleOverlay()
Created February 26, 2014 17:02
simple utility for adding an overlay to help focus user on a page element
function toggleOverlay() {
if (document.getElementById('overlay') != null) {
console.log(true);
$('#overlay').fadeOut(300,function(){
$(this).remove()
});
} else {
var overlay = document.createElement('div');
overlay.id = 'overlay';
overlay.className = 'mfp-bg'; /* use existing styles */
@jorgepinon
jorgepinon / preventDoubleSubmission.js
Last active August 29, 2015 14:10
block form double-submission
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// don't submit
e.preventDefault();
} else {
// set data attr to true for next time
@jorgepinon
jorgepinon / ffmpeg web video
Last active August 29, 2015 14:12
basic ffmpeg web video command
ffmpeg -i input_file.mp4 -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output_file.mp4
@jorgepinon
jorgepinon / getFirstSegment()
Last active August 29, 2015 14:15
returns the first segment of the current url
function getFirstSegment() {
var path = window.location.pathname;
seg1 = path.split("/")[1];
return seg1;
}
@jorgepinon
jorgepinon / showRandomItem
Last active August 29, 2015 14:17
displays a random item from an unordered list (like for random promo images)
//todo: de-jquery this
function showRandomItem(list) {
// random ad on refresh. Each a element should have style="display:none"
var items = $(list).children('li'),
tot = items.length;
if (tot > 1) {
var randNum = Math.round(Math.random()*(tot-1));
items.eq(randNum).show();
} else {
$(items).show();
@jorgepinon
jorgepinon / formInputsToJson
Created August 17, 2015 16:51
convert form data to json obj (for ajax post)
function formInputsToJson(form) {
var $form = $(form);
var fArr = $form.serializeArray()
var fObj = {};
for (var i in fArr) {
fObj[fArr[i].name] = fArr[i].value;
}
return fObj;
validate domain (only letter, numbers, and hypens... and must start with a letter)
^[a-zA-Z]+[a-zA-Z0-9\-]*$
var myModule = (function () {
var privateMethod = function () {
console.log('A private method');
},
someMethod = function () {
console.log('A public method');
},
anotherMethod = function () {
console.log('Another public method');
};
@jorgepinon
jorgepinon / function largestLessThanMaxLimit(limit = 10)
Created April 2, 2017 17:53
largestLessThanMaxLimit: higher-order function for reducing arrays to largest value while not going over the max defined
function largestLessThanMaxLimit(limit = 10) {
var maxLimit = limit;
return function largestLessThanMaxLimit(...args) {
return args.reduce( function(acc, val) {
if( val > acc && val < maxLimit ) {
return val;
}
else {
return acc;
}