|
|
|
Monday, 24 January 2011 12:32 |
a little helper function which parses about any date and returns the same date in MySQL date/time format Download Wow Hits 2010 2011
function date_to_mysql($date) {
//if $date is not numeric, assume it's in textual format
if (!is_numeric($date)) {
$date=strtotime($date);
}
return date('Y-m-d H:i:s',$date);
}
 Read more: |
|
|
Wednesday, 08 September 2010 03:30 |
Synopsis
this is possibly the simplest toBinary function i've seen/written in javascript without using memory intensive power buiding until loops
Purpose
this function will take any numeric input (stripping out non numeric characters) and convert it into binary
function toBinary( n ) {
n = n.replace(/[^0-9]/,'');
if( !n || n == 0 ) return 0;
//calculate the number of bits required to store the number
var bits = Math.floor( Math.log( Math.pow( 2 , Math.ceil( Math.log( (Number( n ) +1 ) ) / Math.log( 2 ) ) ) ) / Math.log( 2 ) );
var bitArray = new Array();
var bitVal;
var i;
for( i = 0 ; i < bits ; i ++ ) {
bitArray[i] = 0;
//calculate the max value of this bit, make sure it starts as low as possible
bitVal = Math.pow(2,bits-i-1);
if( n >= bitVal) {
bitArray[i] = 1;
n = n - bitVal;
}
}
return bitArray.join("");
}
 Read more: |
|
Saturday, 26 June 2010 19:40 |
There are several ways to check if a String is numeric, i.e. type casting it as a float or using a regular expression e.g.
def numeric?(s)
s[/\d+/].to_s.length == s.length
end
# or
String.class_eval {def numeric?() self[/\d+/].to_s.length == self.length end}
# or
def isNumeric(s)
begin
Float(s)
rescue
false # not numeric
else
true # numeric
end
end
# or
def isNumeric(s)
Float(s) != nil rescue false
end
Resources:
- Determine if a string is numeric - Rosetta Code [rosettacode.org]
- Ruby Programming Language :: How to check if a string is a integer ? [megasolutions.net]
*update: 26-Jun-2010 @ 10:02pm*
Here's a simpler method:
s = "23423"
def s.numeric?()
self.to_i.to_s == self
end
s.numeric?
#=> true
# or if you want to use a float
s = "23423.4"; def s.numeric?() self.to_f.to_s == self end; s.numeric?
#=> true
 Read more: |
|
|
Wednesday, 24 February 2010 16:20 |
Source: Chapter 2 - Designing Beautiful APIs [github.com] (O’Reilly’s Ruby Best Practices) via RubyInside.com
def distance4(*points)
x1,y1,x2,y2 = points.flatten
raise ArgumentError unless [x1,y1,x2,y2].all? { |e| Numeric === e }
Math.hypot(x2 - x1, y2 - y1)
end
Resources:
- Class: Numeric [ruby-doc.org] Read more: |
|
Thursday, 28 January 2010 06:00 |
 | About Etchasoft Reports
Design reports directly within Interface Builder! Drag and drop objects to quickly build your reports. Supports text, attributed text, dates, numeric values, images, horizontal/vertical lines and yes, even sub-reports. Text, attributed text and sub-reports can dynamically grow and split across page boundaries.
The datasource independent design is Enterprise, Consultant and ISV friendly. Drive report content based on parameters. Header and footer sections are available at the report, page and grouped data levels. Numeric summary syntax provided. Additionally, optional delegate methods allow you to create custom calculations, toggle object visibility and change colors, text and many other attributes at run-time. Many more features. |
Read more: |
|
|
|
|
|