-
Server moves...
after 5 years of service, and over 895 (and counting) days since the last reboot.
It's come to the time to retire tao.hosteverything.net for refurbishment, and welcome suith.hosteverything.net into it's place. If you spot anything wrong with this site or any of the others please Let me know.
leave a comment -
Fairwell trusted companion
After 10 years working together...
... it's time to say bye bye to BBedit and hello to TextMate.
TextMate isn't as mature as BBedit, but then it's not as bloated either. I found BBedit increasingly clunky of late and TextMate answers a lot of those issuses, and has some neat extra features. Check it out if you do a lot of coding on OS X.
leave a comment
-
PHP Validate UPC and EAN13 Barcodes
As I couldn't find any routines to do this...
I hacked these up in Perl an age ago... needed PHP versions so here they are (Ask if you want the Perl versions lazy..)
function validate_UPCABarcode($barcode)
{
// check to see if barcode is 12 digits long
if(!preg_match("/^[0-9]{12}$/",$barcode)) {
return false;
}
$digits = $barcode;
// 1. sum each of the odd numbered digits
$odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10];
// 2. multiply result by three
$odd_sum_three = $odd_sum * 3;
// 3. add the result to the sum of each of the even numbered digits
$even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9];
$total_sum = $odd_sum_three + $even_sum;
// 4. subtract the result from the next highest power of 10
$next_ten = (ceil($total_sum/10))*10;
$check_digit = $next_ten - $total_sum;// if the check digit and the last digit of the barcode are OK return true;
if($check_digit == $digits[11]) {
return true;
}
return false;
}function validate_EAN13Barcode($barcode)
{
// check to see if barcode is 13 digits long
if(!preg_match("/^[0-9]{13}$/",$barcode)) {
return false;
}$digits = $barcode;
// 1. Add the values of the digits in the even-numbered positions: 2, 4, 6, etc.
$even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9] + $digits[11];
// 2. Multiply this result by 3.
$even_sum_three = $even_sum * 3;
// 3. Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc.
$odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10];
// 4. Sum the results of steps 2 and 3.
$total_sum = $even_sum_three + $odd_sum;
// 5. The check character is the smallest number which, when added to the result in step 4, produces a multiple of 10.
$next_ten = (ceil($total_sum/10))*10;
$check_digit = $next_ten - $total_sum;// if the check digit and the last digit of the barcode are OK return true;
if($check_digit == $digits[12]) {
return true;
}return false;
}3 comments
leave a commentanonymous
2007.11.27 00:00 GMT
Looks great. Could you please email me the perl version. Yes, I am lazy.Thanks
anonymous
2007.11.28 00:00 GMT
hopefully these still worksub checkUPCABarcode { my ($barcode) = @_; if ( !($barcode =~ /^[0-9]{12}$/) ) { return 0; } @digits = split(//,$barcode); # -- sum each of the odd numbered digits # remember perl arrays start at zero! $odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10]; # -- multiply result by three $odd_sum_three = $odd_sum * 3; # -- add the result to the sum of each of the even numbered digits $even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9]; $total_sum = $odd_sum_three + $even_sum; # -- subtract the result from the next highest power of 10 $next_ten = (ceil($total_sum/10))*10; $check_digit = $next_ten - $total_sum;
# if the check digit and the last digit of the barcode are OK return true; if ( $check_digit == $digits[11] ) { return 1; }
return 0; }
sub checkEAN13Barcode { my ($barcode) = @_; if ( !($barcode =~ /^[0-9]{13}$/) ) { return 0; } @digits = split(//,$barcode);
# 1. Add the values of the digits in the even-numbered positions: 2, 4, 6, etc. # remember perl arrays start at zero! $even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9] + $digits[11]; # 2. Multiply this result by 3. $even_sum_three = $even_sum * 3; # 3. Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc. $odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10]; # 4. Sum the results of steps 2 and 3. $total_sum = $even_sum_three + $odd_sum; # 5. The check character is the smallest number which, when added to the result in step 4, produces a multiple of 10. $next_ten = (ceil($total_sum/10))*10; $check_digit = $next_ten - $total_sum;
# if the check digit and the last digit of the barcode are OK return true; if ( $check_digit == $digits[12] ) { return 1; }
return 0; }
anonymous
2008.02.20 09:42 GMT
Here is a PostScript routine that calculates the EAN13 check digit%!PS % ------------------------------------------------------------------ % (12-character numeric string) EAN13.CheckDigit -> (checkCharacter) % ------------------------------------------------------------------ /EAN13.CheckDigit { 5 dict begin /inputString exch def /checkDigit 0 def /factor 1 def /s 3 string def 0 1 11 { /i exch def /checkDigit checkDigit inputString i 1 getinterval cvi factor mul add def /factor factor 2 xor def } for /checkDigit checkDigit 10 mod def checkDigit 0 ne { /checkDigit 10 checkDigit sub def } if checkDigit s cvs end } def % ------------------------------------------------------------------
% Test (these are real life EANs) (900310607223) dup == EAN13.CheckDigit == % 1 (900310650559) dup == EAN13.CheckDigit == % 3 (380000110009) dup == EAN13.CheckDigit == % 2 (590471440187) dup == EAN13.CheckDigit == % 8 (380005170002) dup == EAN13.CheckDigit == % 0 (501753491820) dup == EAN13.CheckDigit == % 1 (692098249717) dup == EAN13.CheckDigit == % 6 (544900003309) dup == EAN13.CheckDigit == % 3
leave a comment
-
SHOWstudio
A new site
After many months of planning, and several weeks of very hard work, I'm please to announce that we've finally launchd a new SHOWstudio website. A complete ground up rebuild of a large part of the contextual features of the site, and the addition of a lot of new functionality, all sitting on top of the Critter CMS that I've been using on various sites over the last few years, with HTML and CSS wizardry by Paul Bruty.
... and relax.
(well, until I get back on with Digital Convenience)
leave a comment
-
adammufti.com
Site for film maker Adam Mufti
A small, CMS based, website I made for Adam Mufti, the former Motion Image Director of SHOWstudio who's now making it freelance.
leave a comment
-
WIRE: The Scottish Play: 2004
DVD Development Assistance
A simple little job, helping Colin from WIRE to learn some tricks in DVD Studio Pro for their new DVD "The Scottish Play".
leave a comment
-
Visual Appliance Website
http://www.visualappliance.com
A site I designed and coded last year for my friend Mathew for his company selling a very cool - and specialised - piece of SFX software. The content and some of the functionality have been changed a bit by Matthew - perhaps not the way I would have done it, but overall I'm pleased with the simplicity of what I produced for him.
leave a comment
-
Recent purple visitors
IP to Colour Conversion
This is something I did a while ago and then forgot about/got distracted by other things. It's really simple. It breaks apart the IP address of visitors to the site and uses each of the four value to generate a CMYK colour, which is then converted into an RGB space to be displayed on screen.
I just looked it again after a while and have noticed that recently a lot of visitors seem to have been coming from soemwhere quite purply ... so there is an area of more purple towards the bottom of the list. So I thoguht I would share it.
This is the visitors to my site, the newest at the bottom:
IP/Colours
(warning, heavy HTML page, bit of a kludge, kill some browsers)Your IP colour can be seen here:
IP/Colourleave a comment
-
Dave Gibbons Website
www.davegibbons.co.uk.
A small site I built for my friend Dave's work, on top of my default CMS. Dave is an artist, and as such most of his contents are images - drawings, paintings, or stills from films - so the site has an image orientated structure to it.
leave a comment
-
Lo-fi moblogging...
Karen Elson at Paris Fashion Week for SHOWstudio
Trying to recreate the experience of Paris Fashion week from someone who is a part of it, on the internet, can be a diffiuclt task. Expressing ourselves in writing isn't everyone's strong point - it's not really mine, which is why this isn't a blog ;-) .
And not everyone wants to be trying to find a computer or typing in messages via a mobile phone keypad.
So we reverted to older technology. I hooked up a voice modem to a Linux box running Vgetty. This allows for answerphone messages to be left, and once stored, changed into .wav files and then uploaded to the showstudio server.
As always it wasn't as easy as it sounds, taking a lot of playing around with several modems and lots of settings to try and get it to work : vgetty doesn't seem to be being actively maintained, and it's not easy to get hold of the Modems it's been tested working with. I used a Zoom 3049 modem which pretty much does it, but you have to force it to be recognised as a V253 Modem [in case anyone wonders].
Allowing for supermodel Karen Elson to leave her experiences of Paris Fashion Week for others to hear. I kind of like what's been said so far, it's quite intimate in it's way.
leave a comment