Skip to content

Instantly share code, notes, and snippets.

View jawinn's full-sized avatar

Josh Winn jawinn

View GitHub Profile
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank">
Share on Facebook
</a>
@jawinn
jawinn / MulitpleUniqueArrayValues.js
Last active August 29, 2015 13:56
Multiple *Unique* Array Values (uses jQuery)
// MULTIPLE *UNIQUE* ARRAY VALUES (uses jQuery)
// Parameter arr: array containing values
// Parameter totalNum: total number of values to get
// Returns Array
function rndArrValues(arr, totalNum){
if ( totalNum <= 0 ){ return; }
var theResult = [];
var newElement;
@jawinn
jawinn / JS_Array_Helpers.js
Created March 1, 2014 23:44
Array Helpers for JavaScript + jQuery
// For getting unique values in array
// usage:
// var duplicates = [1,3,4,2,1,2,3,8];
// var uniques = duplicates.unique(); // result = [1,3,4,2,8]
Array.prototype.contains = function(v) {
for(var i = 0; i < this.length; i++) {
if(this[i] === v) return true;
}
return false;
};
@jawinn
jawinn / percentbar.php
Created March 10, 2014 20:25
Quick and simple PHP percentage bar
<div class="percentbar" style="width:<?php echo round(100 * $scale); ?>px;">
<div style="width:<?php echo round($percent * $scale); ?>px;"></div>
</div>
Percentage: <?php echo $percent; ?>%
@jawinn
jawinn / toast.js
Created March 23, 2014 20:28 — forked from kamranzafar/toast.js
jQuery Mobile - Toast-style popup, modified
// JQuery Mobile Android-style Toast popup
// https://gist.github.com/kamranzafar/3136584
// Usage: toast("Your Message Here");
var toast = function(msg){
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h4>"+msg+"</h4></div>")
.css({ display: "block",
opacity: 0.96,
"background-color": "#332C2C",
"z-index":"9999",
position: "fixed",
@jawinn
jawinn / bare_bones_redux_config_starting_point.php
Last active August 29, 2015 14:00
Bare bones Redux config starting point
<?php
// ACTUAL DECLARATION OF SECTIONS
$this->sections[] = array(
'icon' => 'el-icon-cogs',
'title' => __('General Settings', 'YOURTHEME'),
'fields' => array(
array(
'id' => 'opt-social-facebook',
'type' => 'text',
@jawinn
jawinn / empty_paragraphs.php
Created April 24, 2014 16:01
Remove Empty Paragraphs from Shortcodes, WordPress
<?php
// http://webandphp.com/remove-markup-from-wordpress-shortcodes
/**
* Removes mismatched </p> and <p> tags from a string
*
* @author Jason Lengstorf <jason@copterlabs.com>
*/
function copter_remove_crappy_markup( $string )
{
@jawinn
jawinn / current_page_share.php
Last active November 15, 2024 09:06
Share Current Page via Facebook
<?php
/**
* Get the current Url taking into account Https and Port
* @link http://css-tricks.com/snippets/php/get-current-page-url/
* @version Refactored by @AlexParraSilva
*/
function getUrl() {
$url = isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http';
$url .= '://' . $_SERVER['SERVER_NAME'];
$url .= in_array( $_SERVER['SERVER_PORT'], array('80', '443') ) ? '' : ':' . $_SERVER['SERVER_PORT'];
@jawinn
jawinn / dot_irecommendthis.js
Created June 18, 2014 17:17
I Recommend This - JS Fix
jQuery(document).ready(function($){
$(document).on('click', '.dot-irecommendthis',function() {
var link = $(this);
if(link.hasClass('active')) return false;
var id = $(this).attr('id'),
suffix = link.find('.dot-irecommendthis-suffix').text();
$.post(dot_irecommendthis.ajaxurl, { action:'dot-irecommendthis', recommend_id:id, suffix:suffix }, function(data){
@jawinn
jawinn / random_diff_element.js
Last active August 29, 2015 14:03
Random JS Array Element, Different than the Last One
// via http://stackoverflow.com/questions/4550505/getting-random-value-from-an-array
// usage: var myRandomDiffElement = myArray.randomDiffElement(lastRandomElement);
Array.prototype.randomDiffElement = function(last) {
if (this.length == 0) {
return;
} else if (this.length == 1) {
return this[0];
} else {
var num = 0;
do {