Skip to content

Instantly share code, notes, and snippets.

View joshcanhelp's full-sized avatar
👋
Open to new connections!

Josh Cunningham joshcanhelp

👋
Open to new connections!
View GitHub Profile
@joshcanhelp
joshcanhelp / WP attachment metas
Created July 10, 2013 17:42
Adding meta fields to attachments
/*
* Meta fields for media uploads
*/
/*
* @param array $form_fields
* @param object $post
*
* @return array
*/
@joshcanhelp
joshcanhelp / gist:6108952
Created July 29, 2013 23:55
Get and parse blocked IPs
$blocked = get_option('blacklist_keys');
$blocked = str_replace( "\r", "\n", $blocked );
$blocked_arr = explode( "\n", $blocked );
$blocked_arr = array_map('trim', $blocked_arr);
$final_blocked_arr = array();
foreach ($blocked_arr as $ip) {
$ip = trim($ip);
if ( filter_var( $ip, FILTER_VALIDATE_IP ) ) {
@joshcanhelp
joshcanhelp / gist:6196492
Created August 9, 2013 19:32
WordPress mobile UA redirection
/**
* Redirect on mobile UA
*/
function tenup_mobile_redirect() {
$useragent = $_SERVER['HTTP_USER_AGENT'];
// From http://detectmobilebrowsers.com, set 8/9/2013
// We're looking for user agents that are associated with mobile devices
if ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\
@joshcanhelp
joshcanhelp / gist:6196972
Created August 9, 2013 20:36
Add and save media attachment custom fields in WordPress
/*
* @param array $form_fields
* @param object $post
*
* @return array
*/
function tenup_attachment_fields_to_edit ( $form_fields, $post )
{
$form_fields[ "use_as_header_img" ] = array(

Keybase proof

I hereby claim:

  • I am joshcanhelp on github.
  • I am joshcanhelp (https://keybase.io/joshcanhelp) on keybase.
  • I have a public key whose fingerprint is 8703 9194 46F1 49DD 05BA 772E 7E34 CED3 7442 9737

To claim this, I am signing this object:

Running "simplemocha:all" (simplemocha) task
1..1
ok 1 Array indexOf() should return -1 when the value is not present
# tests 1
# pass 1
# fail 0
Done, without errors.
@joshcanhelp
joshcanhelp / gist:a66e195864eadb7113b8
Created June 4, 2014 18:47
JS queue structure WTF
function Queue() {
this.dataStore = [];
}
Queue.prototype.enqueue = function (element) {
this.dataStore.push(element);
};
Queue.prototype.dequeue = function () {
return this.dataStore.shift();
@joshcanhelp
joshcanhelp / gist:b4eebe3be32d46a648d9
Created June 18, 2014 14:11
Mongo 101 homework 2.2
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost/m101', function(err, db) {
if (err) {
throw err;
}
var data = db.collection('data');
var cursor = data.find({});
cursor.sort("Temperature", -1);
@joshcanhelp
joshcanhelp / app.js
Created June 19, 2014 15:28 — forked from clarle/app.js
// Module dependencies
var express = require('express'),
mysql = require('mysql');
// Application initialization
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
/**
* CSS and JavaScript for admin pages
*/
function proper_admin_css_js() {
global $pagenow;
// CSS
wp_enqueue_style(