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 / docCookies.js
Created May 6, 2013 12:14
Library provided by Mozilla for JS cookie handling.
var docCookies = {
getItem: function (sKey) {
return unescape(document.cookie.replace(new RegExp("(?:(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*)|.*"), "$1")) || null;
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
case Number:
@jesse1981
jesse1981 / acao.php
Created April 23, 2013 15:02
Cross Domain Resource Sharing example
function isAllowedOrigin($origin) {
// your logic here
//...
return true;
}
if (($_SERVER["HTTP_ORIGIN"]=="http://www.yoursite.com.au") || (isAllowedOrigin($_SERVER["HTTP_ORIGIN"]))) {
header("Access-Control-Allow-Origin: *");
}
@jesse1981
jesse1981 / modRegistry.vbs
Last active January 11, 2024 11:16
Some sample registry get/set/monitor examples in VB Script.
const KEY_QUERY_VALUE = &H0001
const KEY_SET_VALUE = &H0002
const KEY_CREATE_SUB_KEY = &H0004
const DELETE = &H00010000
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
@jesse1981
jesse1981 / directoryToArray.php
Last active December 16, 2015 11:19
PHP function to return a directory tree to an array.
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..") &&
(is_dir($directory. "/" . $file)) &&
($recursive)) $array_items = array_merge($array_items,
directoryToArray($directory. "/" . $file, $recursive));
if (is_dir($directory. "/" . $file)) {
$file = $directory . "/" . $file;
@jesse1981
jesse1981 / modCharting.vbs
Created April 20, 2013 15:42
Module for automatic spreadsheet formatting and chart generation in Excel.
Public Sub ChartAll()
On Error GoTo Handler
Worksheets.Add before:=Worksheets(1)
Sheets(1).Name = "Summary"
Sheets(1).Activate
'Application.ScreenUpdating = False
' Fix issue with invalid data type to MakeArray
Dim strSheetName As String
' end fix
@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'
@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 / 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 / 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 / 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;
}