Skip to content

Instantly share code, notes, and snippets.

View jesse1981's full-sized avatar
💭
Nerding

Jesse Bryant jesse1981

💭
Nerding
View GitHub Profile
@jesse1981
jesse1981 / popupWrapper.html
Last active December 16, 2015 07:48
A small wrapper snippet to make it simple to create popup modal dialogs using jQuery UI.
<!--
Usage:
initDialog("Add a Staff Member",true,updateContact);
appendForm($( "#dialog-form" ),"addStaff","?module=staff&mode=add");
appendDetail($( "#addStaff_id" ),"First Name:","first_name","");
appendDetail($( "#addStaff_id" ),"Last Name:","last_name","");
openDialog();
initDialog: (form title str, destroyOnClose, submitCallback)
appendForm: (id to append to - will make this deprecated, will always be this ojbect
@jesse1981
jesse1981 / getQueryVar.js
Last active May 16, 2018 01:18
PHP equivalent of $_GET for Javascript
function getQueryVariable(variable,fromSrc) {
fromSrc = fromSrc || false;
if (fromSrc) {
var myScript = document.currentScript;
var query = myScript.src.replace(/^[^\?]+\??/,'');
}
else {
var query = window.location.search.substring(1);
}
var vars = query.split('&');
@jesse1981
jesse1981 / hasAlpha.js
Created April 19, 2013 05:47
Search a string of having an upper/lower alpha character.
function hasAlpha(val,upper) {
if (upper) {
for (var i in val) {
if ((val.charCodeAt(i)>=65) && (val.charCodeAt(i)<=90)) return true;
}
}
else {
for (var i in val) {
if ((val.charCodeAt(i)>=97) && (val.charCodeAt(i)<=122)) return true;
}
@jesse1981
jesse1981 / hasNum.js
Created April 19, 2013 05:48
Search a string of having a number value.
function hasNum(val) {
for (var i in val) {
if (!isNaN(parseInt(val[parseInt(i)]))) return true;
}
return false;
}
@jesse1981
jesse1981 / fakeClick.js
Last active December 16, 2015 10:09
Script a click event to object.
function fakeClick(event, anchorObj) {
if ((typeof(anchorObj)!="undefined") && (typeof(anchorObj.click)!="undefined")) {
anchorObj.click()
}
else if(document.createEvent) {
if(event.target !== anchorObj) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var allowDefault = anchorObj.dispatchEvent(evt);
@jesse1981
jesse1981 / getUrlContent.php
Created April 19, 2013 05:53
Small wrapper for PHP CURL requests.
function getURLContent($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
@jesse1981
jesse1981 / getCustomTypeData.php
Created April 19, 2013 05:57
Wordpress function for retrieving all key/value pairs for a specific content-type. See: http://code.google.com/p/wordpress-custom-content-type-manager/
function getCustomTypeData($name) {
global $wpdb;
$returnValues = array();
$sql = "SELECT id, post_title, post_status, post_author, post_content FROM wp_posts WHERE post_title<>'Auto Draft' AND post_status='publish' AND post_type='$name'";
$customPosts= $wpdb->get_results($sql);
$count = 0;
foreach ($customPosts as $post) {
$returnValues[$count]["id"] = $post->id;
$returnValues[$count]["title"] = $post->post_title;
$returnValues[$count]["content"] = $post->post_content;
@jesse1981
jesse1981 / sortCustom.php
Last active February 17, 2017 03:25
Function to sort an array, in this example, used in conjunction with getCustomTypeData.
function sortCustom($data,$field,$datatype="text",$direction="desc") {
$cycle = false;
for ($i=0;$i<(count($data)-1);$i++) {
switch($datatype) {
case "date":
$arrDate1 = explode("-", $data[$i][$field]);
$mkDate1 = mktime(1,1,1,$arrDate1[1],$arrDate1[2],$arrDate1[0]);
$arrDate2 = explode("-", $data[$i+1][$field]);
$mkDate2 = mktime(1,1,1,$arrDate2[1],$arrDate2[2],$arrDate2[0]);
@jesse1981
jesse1981 / splitn.php
Created April 19, 2013 06:07
Split a string at the offset of the nth needle.
function splitn($string, $needle, $offset) {
$newString = $string;
$totalPos = 0;
$length = strlen($needle);
for($i = 0; $i < $offset; $i++) {
$pos = strpos($newString, $needle);
// If you run out of string before you find all your needles
if($pos === false)
return false;
@jesse1981
jesse1981 / modPing.vbs
Created April 20, 2013 15:39
Small wrapper for generating a ping/reply in VBS modules
Option Explicit
'Icmp constants converted from'
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp'
Private Const ICMP_SUCCESS As Long = 0
Private Const ICMP_STATUS_BUFFER_TO_SMALL = 11001 'Buffer Too Small'
Private Const ICMP_STATUS_DESTINATION_NET_UNREACH = 11002 'Destination Net Unreachable'
Private Const ICMP_STATUS_DESTINATION_HOST_UNREACH = 11003 'Destination Host Unreachable'
Private Const ICMP_STATUS_DESTINATION_PROTOCOL_UNREACH = 11004 'Destination Protocol Unreachable'