float InvSqrt (float x)
{
float xhalf = 0.5F * x;
int i = * (int *) &x;
i = 0x5F3759DF - (i >> 1);
x = * (float *) &i;
x = x * (1.5F - xhalf * x * x);
return x;
}
The famous InvSqrt()
toggle / showhide with YUI javascript library
var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;
var $ = function(id) {
return document.getElementById(id);
}
//++++++++++++++++++++++++++++++++++++
// YUI TOGGLE
// 1/22/2008 - Edwart Visser & AW
//
// toggle the visibility
//
// REQUIRES: yahoo-dom-event.js
// OPTIONAL: animation-min.js
//
//++++++++++++++++++++++++++++++++++++
YAHOO.namespace("lutsr");
YAHOO.lutsr.doToggle = {
init : function() {
this.toggleLinks = Dom.getElementsByClassName("toggle");
for(var i=0; i<this.toggleLinks.length; i++) {
Event.addListener(this.toggleLinks[i],"click",this.animateElements,this);
}
},
toggleElements : function(e,controlNode,refEl) {
if(controlNode && refEl) {
if(Dom.hasClass(refEl,"show")) {
Dom.removeClass(controlNode,"selected");
Dom.removeClass(refEl,"show");
} else {
Dom.addClass(controlNode,"selected");
Dom.addClass(refEl,"show");
}
}
// to disable control node's default behaviour
return false;
},
animateElements : function(e,obj) {
// obj = javascript toggle object
// this = link clicked
Event.preventDefault(e);
if(this.rel) {
controlNode = this;
}
if(typeof(controlNode) == "string") {
controlNode = Dom.get(controlNode);
}
// objParameters
// [0] = object id
// [1] = animation type (fade, slide)
// [2] = animation duration (seconds)
var linkClicked = this;
var objParameters = controlNode.rel.split(",");
var refEl = Dom.get(objParameters[0]);
var objStatus = Dom.hasClass(refEl,"show"); // if true, object is shown
switchClasses = function() {
obj.toggleOtherElements(e,linkClicked,refEl);
obj.toggleElements(e,linkClicked,refEl);
}
if(objParameters[1] == "fade") {
if(objStatus == true) {
var attributes = {
opacity: { from: .999, to: 0 }
}
var objAnim = new YAHOO.util.Anim(objParameters[0],attributes);
objAnim.useSeconds = false;
objAnim.duration = objParameters[2];
objAnim.onComplete.subscribe(switchClasses);
objAnim.animate();
} else {
Dom.setStyle(objParameters[0],"opacity",0);
switchClasses();
var attributes = {
opacity: { from: 0, to: .999 }
}
var objAnim = new YAHOO.util.Anim(objParameters[0],attributes);
objAnim.useSeconds = false;
objAnim.duration = objParameters[2];
objAnim.animate();
}
} else if (objParameters[1] == "slide") {
// not implemented yet
} else {
// NO ANIMATION - switch classes
switchClasses();
}
},
toggleOtherElements : function(e,linkClicked,refEl) {
// toggle selected state of other elements pointing to the same source
for(var i=0; i<this.toggleLinks.length; i++) {
var objParameters = this.toggleLinks[i].rel.split(",");
var linkClickedParameters = linkClicked.rel.split(",");
if(objParameters[0] == linkClickedParameters[0]) {
if(Dom.hasClass(this.toggleLinks[i],"selected")) {
Dom.removeClass(this.toggleLinks[i],"selected");
} else {
Dom.addClass(this.toggleLinks[i],"selected");
}
}
}
}
}
initPage = function() {
YAHOO.lutsr.doToggle.init();
}
Event.addListener(window,"load",initPage);
Table Styles
/** * @author mithun */
table{
margin: auto;
border-collapse:collapse;
font-family:Lucida Grande, Verdana;
font-size:16px;
text-align: center;
width:80%;
}
table td,table th{
padding:2px;
font-weight:normal;
padding: 2px;
}
table th{
font-weight:bold;
}
table.aquamarine{
border: 1px solid #050;
}
table.aquamarine tr th,
table.aquamarine tr td{
border: 1px dotted #050;
}
table.aquamarine tr th{
background-color: #48a474;
color: #ccffcc;
}
table.aquamarine tr td{
background-color: #ded;
}
table.aquamarine tr.alt td{
background-color: #b8dcc1;
}
table.aquamarine tr:hover td{
background-color: #7fc08f;
color: #ccffcc;
}
table.blue{
border: 1px solid #94beff;
}
table.blue tr th,
table.blue tr td{
border: 1px dotted #94beff;
}
table.blue td, table th {
background-color: #94beff;
background-image:url(../images/bg-head.gif);
background-repeat:no-repeat;
background-position:top right;
}
table.blue td.selectedUp,
table th.selectedUp {
background-image:url(../images/bg-headup.gif);
}
table.blue td.selectedDown,
table th.selectedDown {
background-image:url(../images/bg-headdown.gif);
}
table.blue tr td{
background: #fff;
}
table.blue tr.alt td{
background: #e3edfa;
}
table.blue tr.selected td{
background: yellow;
}
table.blue tr:hover td{
background: #a6c2e7;
}
table.blue tr.selected:hover td{
background:#ff9;}table.cool{
border: 1px solid #6BB12B;
}
table.cool tr th,
table.cool tr td{
border: 1px dotted #91d552;
}
table.cool tr th{
background-color: #91d552;
color: #000;
}
table.cool tr td{
background-color: #d5f7b5;
}
table.cool tr.alt td{
background-color: #e7fad5;
}
table.cool tr:hover td{
background-color: #b1f075;
color: #333;
}
table.cyan{
border: 1px solid #2b8383;
}
table.cyan tr th,
table.cyan tr td{
border: 1px dotted #2b8383;
}
table.cyan tr th{
background-color: #099;
color: #cfc;
}
table.cyan tr td{
background-color: #e5f5f5;
}
table.cyan tr.alt td{
background-color: #d1f0f0;
}
table.cyan tr:hover td{
background-color: #a5e1e0;
color: #366;
}table.green{
border: 1px solid #00B366;
}
table.green tr th,
table.green tr td{
border: 1px dotted #00B366;
}
table.green tr th{
background-color: #167a61;
color: #cfc;
}
table.green tr td{
background-color: #569591;
}
table.green tr.alt td{
background-color: #63a8a8;
}
table.green tr:hover td{
background-color: #167a61;
color: #cfc;
}
table.nature{
border: 1px solid #4b6c15;
color: #040;
}
table.nature tr th,
table.nature tr td{
border: 1px dotted #4b6c15;
}
table.nature tr th{
background-color: #4b6c15;
color: #fff;
}
table.nature tr td{
background-color: #d9e8af;
}
table.nature tr.alt td{
background-color: #bcd671;
}
table.nature tr:hover td{
background: #73a800;
}
table.orange{
color: #400;
border: 1px solid #f93;
}
table.orange tr th,
table.orange tr td{
border: 1px dotted #f93;
}
table.orange tr th{
background-color: #fc0;
}
table.orange tr td{
background-color: #feb;
}
table.orange tr.alt td{
background-color: #fe9;
}
table.orange tr.selected td{
background-color: #fc9;
}
table.orange tr:hover td{
background: #fd8;
}
table.orange tr.selected:hover td{
background:#fcb;
}
table.olive{
border: 1px solid #090;
color: #040;
}
table.olive tr th,
table.olive tr td{
border: 1px dotted #090;
}
table.olive tr th{
background-color: #4B6C15;
color: #fff;
}
table.olive tr td{
background-color: #dfd;
}
table.olive tr.alt td{
background-color: #dfe;
}
table.olive tr.selected td{
background-color: #9dc;
}
table.olive tr:hover td{
background: #bfb;
}
table.olive tr.selected:hover td{
background:#9ca;
}
table.pink{
border: 1px solid #faa;
color: #400;
}
table.pink tr th,
table.pink tr td{
border: 1px dotted #faa;
}
table.pink tr th{
background-color: #f99;
}
table.pink tr td{
background-color: #fee;
}
table.pink tr.alt td{
background-color: #fdd;
}
table.pink tr.selected td{
background-color: #fcd;
}
table.pink tr:hover td{
background: #fbb;
}
table.pink tr.selected:hover td{
background:#ebc;
}
table.pink tr th.selectedUp{
background-color: #f99;
}
table.pink tr th.selectedDown{
background-color: #f99;
}
table.violet{
border: 1px solid #81218a;
}
table.violet tr th,
table.violet tr td{
border: 1px dotted #81218a;
}
table.violet tr th{
background-color: #81218a;
color: #fff;
}
table.violet tr td{
background-color: #f7f8f9;
}
table.violet tr.alt td{
background-color: #e8f1f7;
}
table.violet tr:hover td{
background-color: #c4cae2;
color: #333;
}
Email Validation function
function isEmail(str)
{
var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+.)+(ad|ae|aero|af|ag|
ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|
bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|
ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|
dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|
gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|
hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|
kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|
ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|
mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|
nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|
re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|
su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|
ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|
zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2]
[5][0-5]).){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|
[2][5][0-5]))$/i;
}
Tags: email, validation
Copyright Year
Copyright © 2007<?php echo ( ($Y = intval(date('Y'))) > 2007 ) ? " - $Y" : ''; ?> - All Rights Reserved - Design by ...
Euro banknote validation
<?php
/**
* Checks if the input string is a valid Euro note serial number.
*
* @param string $string
* @return bool
*/
function Euro($string)
{
settype($string, 'string');
if (strlen($string) != 12)
{
return false;
}
$string = str_replace(array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'), array(2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9), strtoupper($string));
$stack = 0;
for ($i = 0; $i < 12; $i++)
{
$stack += $string[$i];
}
if ($stack % 9 == 0)
{
return true;
}
return false;
}
?>
Publish an object via PDO (aka Cocoa Distributed Objects)
NSConnection *theConnection = [NSConnection defaultConnection]; [theConnection setRootObject:serverObject]; [theConnection registerName:@"ObjectName"];
Tags: distributed, Objects
Wrap Long Lines with PRE Tag
pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
botones que parezcan enlaces
input.enlace {
border:0;
background-color:#fff;
text-decoration:underline;
color:#000;
cursor:hand
}
MySQL search
Word searching
1.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('Keyword')
(Fastest)
2.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('+Keyword' IN BOOLEAN MODE)
(Fast)
3.
SELECT * FROM TABLE WHERE RLIKE '(^| +)Keyword($| +)'
OR
SELECT * FROM TABLE WHERE
RLIKE '([[:space:]]|[[:<:]])Keyword([[:space:]]|[[:>:]])'
(Slow)
Contains searching
1.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('Keyword*' IN BOOLEAN MODE)
(Fastest)
2.
SELECT * FROM TABLE WHERE FIELD LIKE 'Keyword%'
(Fast)
3.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('*Keyword*' IN BOOLEAN MODE)
(Slow)
4.
SELECT * FROM TABLE WHERE FIELD LIKE '%Keyword%'
(Slow)
Recordsets
1.
SELECT SQL_CALC_FOUND_ROWS * FROM TABLE WHERE Condition LIMIT 0, 10
SELECT FOUND_ROWS()
(Fastest)
2.
SELECT * FROM TABLE WHERE Condition LIMIT 0, 10
SELECT COUNT(PrimaryKey) FROM TABLE WHERE Condition
(Fast)
3.
$result = mysql_query("SELECT * FROM table", $link);
$num_rows = mysql_num_rows($result);
(Very slow)
Joins
Use an INNER JOIN when you want the joining table to only have matching records that you specify in the join. Use LEFT JOIN when it doesn’t matter if the records contain matching records or not.
SELECT * FROM products
INNER JOIN suppliers ON suppliers.SupplierID = products.SupplierID
Returns all products with a matching supplier.
SELECT * FROM products
LEFT JOIN suppliers ON suppliers.SupplierID = products.SupplierID
WHERE suppliers.SupplierID IS NULL
Returns all products without a matching supplier.