Skip to content

Instantly share code, notes, and snippets.

View shearichard's full-sized avatar

Richard Shea shearichard

View GitHub Profile
@shearichard
shearichard / string-to-hex
Created April 13, 2014 23:57
Show Hex equivalent of string
print(":".join("{:02x}".format(ord(c)) for c in s))
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
img{
width: 80%;
margin: 0%;
padding: 0%;
@shearichard
shearichard / subprocess-example
Created April 2, 2015 23:37
Running execuable/bat from Python (in Windows land)
from subprocess import call
from subprocess import Popen, PIPE, check_output
import os
dir_of_this_script = os.path.dirname(os.path.realpath(__file__))
pathforarg = os.path.join(dir_of_this_script,"*.py")
out = check_output(['exp-oracle-dwitasdev.bat', '*.py'], shell=True)
print out
@shearichard
shearichard / dot_path_from_class_hierarchy.py
Created June 1, 2015 23:11
Python : Produce a dotted path of a class instance hierarchy
class C(object):
def __init__(self):
self.c_a_d2 = "alpha in C"
self.c_b_d2 = "beta in C"
def mymethod(self):
pass
class B(object):
def __init__(self):
self.b_a_d1 = "alpha in B"
@shearichard
shearichard / geturlparams.js
Created September 2, 2015 02:08
JS function to extract parms from a URL
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
};
@shearichard
shearichard / test_input_type.js
Created September 2, 2015 10:24
Testing for INPUT type using jQuery
//NB: Doesn't work for TextArea elements
//
if ($('#' + arr_guids[i]).is('input:checkbox')){
console.log("checkbox");
}
if ($('#' + arr_guids[i]).is('input:radio')){
console.log("radio");
}
if ($('#' + arr_guids[i]).is('input[type="text"]')){
console.log("text input");
@shearichard
shearichard / OracleIdxStatsDump
Created May 28, 2012 02:51
Refresh Oracle Index Stats and output idx related info
set serveroutput on
set pages 0
set feedback off
set echo off
DECLARE
height index_stats.height%TYPE;
del_lf_rows_len index_stats.del_lf_rows_len%TYPE;
lf_rows_len index_stats.lf_rows_len%TYPE;
del_perc number;
table_name user_indexes.index_name%TYPE;
@shearichard
shearichard / jq_jqui_version_info
Created April 30, 2013 10:26
Get information about jQuery and jQuery UI versions in use
var jquiver4sheadbg = $.ui ? $.ui.version || "pre 1.6" : 'jQuery-UI not detected';
alert('jQ UI version : ' + jquiver4sheadbg);
var jqcorever4sheadbg = $().jquery;
alert('jQ version : ' + jqcorever4sheadbg);
@shearichard
shearichard / mixins_and_init_sharing.py
Created April 30, 2013 11:41
Demonstration of how mixins can be used to consolidate common __init__ functionality for classes that have differing superclasses
class SomeMixin(object):
def __init__(self, rel=None, attrs=None, *args, **kwargs):
print 'Testing sharing an __init__ via a mixin class'
self.someattr = "sm"
super(SomeMixin, self).__init__(*args, **kwargs)
class SomeSuper1(object):
def __init__(self, rel=None, attrs=None, *args, **kwargs):
print 'Testing sharing an __init__ via a super1 class'
class SomeSuper2(object):
def __init__(self, rel=None, attrs=None, *args, **kwargs):
@shearichard
shearichard / monthdelta.py
Created June 17, 2013 21:53
Move backwards and forwards in month long chunks of time
def monthdelta(date, delta):
'''
Acts like datetime.timedelta but deals with months
`date`: A datetime object representing the base date
`delta`: An integer representing the offset (-ve for going back in time)
Found at : http://stackoverflow.com/a/3425124/364088
'''