Tag Archive for key

Array Search on Key

function array_search_key($needle, $haystack, $haystackKey, $strict = false) {
	foreach($haystack as $key => $value) {
		if(isset($value[$haystackKey])) {
			if($strict) {
				if($value[$haystackKey] === $needle) return true;
			} else {
				if($value[$haystackKey] == $needle) return true;
			}
		}
	}
	
	return false;
}

source

jQuery onKeyboardSmashed event Plugin

(function($){
 $.fn.extend({
 
 	onKeyboardSmashed : function(callbackFunction,options) {
		var defaults = {
			threshold: 3
		};
		
	  var options = $.extend(defaults, options);
	  
	  
	  return this.each(function() {

			var keys_pressed = 0 ;
			$(this).keydown(function(event) {
				keys_pressed++
			
					if( keys_pressed >options.threshold){
						    if(typeof callbackFunction == 'function'){
							  callbackFunction.call(this);
							}
					}
			});
			
			$(this).keyup(function(event) {
				keys_pressed--;
			});
		
	  });
	  
	}
 });
})(jQuery);

source

keyword tool

<a href="<a href="http://www.precisionkeywordfinder.com">keyword" >http://www.precisionkeywordfinder.com">keyword</a> tool</a>

source

How to send a form by pressing ENTER key

<script type="text/javascript">
	function submitonenter(formid,evt,thisObj) {
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		if (evt) {
			// process event here
			if ( evt.keyCode==13 || evt.which==13 ) {
				thisObj.blur();
				document.getElementById(formid).submit();
			}
		}
	}
</script>

source

Foreign Keys

ALTER TABLE [dbo].[sarg_PM_StatusHistory]  WITH NOCHECK ADD  CONSTRAINT [FK_sarg_PM_StatusHistory_sarg_PM_LOC] FOREIGN KEY([locID])
REFERENCES [dbo].[sarg_PM_LOC] ([locID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[sarg_PM_StatusHistory] CHECK CONSTRAINT [FK_sarg_PM_StatusHistory_sarg_PM_LOC]
GO

/****** Object:  Index [IX_sarg_PM_StatusHistory]    Script Date: 02/05/2010 09:29:47 ******/
CREATE NONCLUSTERED INDEX [IX_sarg_PM_StatusHistory] ON [dbo].[sarg_PM_StatusHistory] 
(
	[locID] ASC,
	[status] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

source

key code exceptions

var x = {
	'backspace' : 8,
	'tab' : 9,
	'enter' : 13,
	'shift' : 16,
	'ctrl' : 17,
	'alt' : 18,
	'pause' : 19,
	'caps lock' : 20,
	'escape' : 27,
	'page up' : 33,
	'page down' : 34,
	'end' : 35,
	'home' : 36,
	'left arrow' : 37,
	'up arrow' : 38,
	'right arrow' : 39,
	'down arrow' : 40,
	'insert' : 45,
	'delete' : 46,
	'left window key' : 91,
	'right window key' : 92,
	'select key' : 93,
	'numpad 0' : 96,
	'numpad 1' : 97,
	'numpad 2' : 98,
	'numpad 3' : 99,
	'numpad 4' : 100,
	'numpad 5' : 101,
	'numpad 6' : 102,
	'numpad 7' : 103,
	'numpad 8' : 104,
	'numpad 9' : 105,
	'multiply' : 106,
	'add' : 107,
	'subtract' : 109,
	'decimal point' : 110,
	'divide' : 111,
	'f1' : 112,
	'f2' : 113,
	'f3' : 114,
	'f4' : 115,
	'f5' : 116,
	'f6' : 117,
	'f7' : 118,
	'f8' : 119,
	'f9' : 120,
	'f10' : 121,
	'f11' : 122,
	'f12' : 123,
	'num lock' : 144,
	'scroll lock' : 145,
	'semi-colon' : 186,
	'equal sign' : 187,
	'comma' : 188,
	'dash' : 189,
	'period' : 190,
	'forward slash' : 191,
	'grave accent' : 192,
	'open bracket' : 219,
	'back slash' : 220,
	'close braket' : 221,
	'single quote' : 222
};

source

Insert or update if unique key already exist

INSERT INTO `tableName`
VALUES (?,?,?,'-1',?,'0')
ON DUPLICATE KEY
UPDATE `id` = ?, `foo` = ?, `bar` = ?

source

Regular Expression Key Clean

"""
****************************************************
*Name : regexkeyclean.py
*Author : Jason Spadaro
*Date : Mon Jun  8 17:39:16 EDT 2009
*Description : Demonstrates using regular expressions to take data from a
*              list, and incorporate it into a dictionary.
*
*       Copyright 2009
****************************************************
"""

import re

class myRegexer:
"""
****************************************************
*All this  does is describe an aggregator of regular expression objects
****************************************************
"""

def __init__(self, exps):
"""
****************************************************
*Takes a dictionary of strings representing regular expressions,
*uses that dictionary to create a dictionary of regular expression
*objects, and places them in in the instance data.
****************************************************
"""

self.exps = exps
tempDct = {}
for k, v in self.exps.iteritems():
tempDct.update({k: re.compile(v)})
self.exps = tempDct

class dataItem:
"""
****************************************************
*An individual data object
****************************************************
"""
def __init__(self, dct):
"""
****************************************************
*Sets up the dictionary instance data
****************************************************
"""

self.dct = {"name":"", "id":"", "data":""}
self.dct.update(dct)

def __str__(self):
"""
****************************************************
*Convient formating if you need to "see" what this is
****************************************************
"""
myStr = ""
for k, v in self.dct:
myStr = myStr + k + "-->" + v + ","
myStr = myStr[0,-1]
return myStr

class dataDictionary:
"""
****************************************************
*Aggregates dataItems, with a method to change the list to a dictionary
*formatteed according to regular expressions.
****************************************************
"""

def __init__(self, dataList, regexExps):
"""
****************************************************
*Sets up the data list, data dictionary, and the regular
*expressions to be used.
****************************************************
"""

self.dataItems = {}
self.dataList = dataList
self.regexExps = regexExps
self.myRegexer = myRegexer(self.regexExps)

def listToItems(self):
"""
****************************************************
*Converts the list of items to a dictionary of items.  It keys
*the item based on a matches to the "name" regular expression.
*The value associated with that key is a dictionary where the
*all the data is keyed similarly using regular expressions.
****************************************************
"""

self.dataItems = {}
for i in self.dataList:
tempDct = {}
name = ""
for k, v in i.iteritems():
"""
****************************************************
*Designates the regular expression to associate
*with each key.
****************************************************
"""

if self.myRegexer.exps["name"].match(k):
tempDct.update({"name":v})
name = tempDct["name"]

if self.myRegexer.exps["id"].match(k):
tempDct.update({"id":v})

if self.myRegexer.exps["data"].match(k):
tempDct.update({"data":v})

self.dataItems.update({name:tempDct})

def __str__(self):
"""
****************************************************
*User readable version of the data
****************************************************
"""

myStr = ""
for k, v in self.dataItems.iteritems():
myStr = myStr + "

____" + k + "____
"
myStr = myStr + "	" + v.__str__()
return myStr

##########################################################################

if __name__ == "__main__":

#First we need our data...
my_data = [{"dataName":"foo",
"idNum":1,
"data":1},

{"dataname":"bar",
"id_num":2,
"data":"10"}]

#Now, how are we going to designate keys?  Like this:
my_regular_expressions = {"name":"(.*)(N|n)(A|a)(M|m)(E|e)(.*)",
"id":"(.*)(I|i)(D|d)(.*)",
"data":"data"}

#Instantiate our data dictionary
sample_data_dct = dataDictionary(my_data, my_regular_expressions)

#Here's the list we've fed in
print sample_data_dct.dataList
print

#Here's our dictionary.  Notice that it's empty.
print sample_data_dct.dataItems
print
print "#####################################"
print

#Here's the magic.  Converting the list  to our dictionary of "Items"
sample_data_dct.listToItems()

#The final output.  Notice that (a) the name of each object has been
#successfully extracted, and (b) each object's keys have been normalized
#for the appropriate values.
print sample_data_dct


######################OUTPUT#######################
"""

[{'dataName': 'foo', 'idNum': 1, 'data': 1}, {'dataname': 'bar', 'id_num': 2, 'data': '10'}]

{}

#####################################



____foo____
{'data': 1, 'name': 'foo', 'id': 1}

____bar____
{'data': '10', 'name': 'bar', 'id': 2}

"""

source

Create Unique Code Replacing Lookalike Characters

function create_key(&$cnnDB){
$letters = range('A','Z');
$numbers = range(0,9);
$all = array_merge($numbers,$letters);
$foundkey = false;
while(!$foundkey){
for($i=0;$i<5;$i++){
$num = rand(0,count($all)-1);
$key .= $all[$num];
$total += $num;
}

//Replace Oh with Zero, I with one
$key = str_replace(
array('O','I'),
array('0','1'),
$key
);

//make checksum
$key .= $all[($total % count($all))];

$key = str_replace(
array('O','I'),
array('0','1'),
$key
);

$SQL = 'select C_Key from customers where C_Key = "'.$key.'"';
$result = $cnnDB->GetRow($SQL);
if(count($result) == 0){
$foundkey = true;
}
}

return $key;
}

source

SAS programming errors we make….. can be deadly sometimes

The errors I will list here will be very few in number. They are errors that you will likely make at some time if you do not remain alert. These errors could have serious consequences so that is why I have described them as "deadly errors".

source