zaterdag 16 februari 2013

Android xml / rss tag / attribute parser for (image) display (in android app)

My first app was a very simple image gallery,
with 3 buttons, calling 3 different urls in a webview.
This url was a php script that i wrote.




The host with this script would be queried like this:

http://your.host/fde-xmlparser.php?latest=1
http://your.host/fde-xmlparser.php?id=40
http://your.host/fde-xmlparser.php (skips to the next id automatically, everytime)

which grabs image links from any  RSS feed (in my case, supplied by phoca gallery). The script returns the contents of these files, so they can be directly viewed in any (mobile) webbrowser.


It supports alot:
None of the rss feed, php script, or the images need to be on the same host.
It reverts to local image fetching when script + images are on the same host, useful for hosts without url wrapper and curl. Note that in this case, the php script needs to be in the same or a parent folder of the images.

This feed can be queried with an html tag (setting) and attribute (setting).
Buildin support allows for file-location altering (find / replace), so for example, small thumbnail links can be changed into normal links.


These calls can be made from for example, google app-inventor like this: 


It's not very hard to accomplish in android studio either, if you follow the
Android studio Training.

There you have it, an super easy image gallery, suitable for lots of digital artists.

Download here:
http://code.google.com/p/xml-links-to-app-inventor/


Dont forget to check out my main project, http://www.bartbosma.eu/freedomeditor/

Windows 7 and S.M.A.R.T. feature (hard drive reliability warning)

I noticed that by default, (my version of) Windows 7 doesn't warn about early hard drive errors.
I've read somewhere that they didn't want to bug end-users with the problems their system administrator should deal with. In the past, microsoft their policy certainly seemed quite the opposite. Now lets make it clear, of all things the end-user SHOULD be bothered with, is the safety of their personal data.

Here is a quick fix.

Put below in a blabla.reg file,
or goto start> run > regedit and change it manual:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WDI\{29689E29-2CE9-4751-B4FC-8EFF5066E3FD}]
"ScenarioExecutionEnabled"=dword:00000001
"EnabledScenarioExecutionLevel"=dword:00000002
"DfdAlertTextOverride"="Hard Drive Failure"


You might want to goto control panel > folder options > view > uncheck hide extensions for known types, in order to allow easy creation of above mentioned .reg file.





Now to enable a tight s.m.a.r.t. check schedule, go start > write "cmd" in search box > rightclick > run as admin

schtasks /Create /F /SC weekly /D MON,TUE,WED,THU,FRI /TN "Check Hard drives for S.M.A.R.T. issues" /RL HIGHEST /TR %windir%\system32\DFDWiz.exe





With this fixed, i'd like to point out that if you aren't using an extra UPS (emergency power supply), you should keep write cache disabled (as default) on your hard drive in case of a power failure.

If you are using an UPS, then with the smart checks enabled you probably don't need to backup your data anymore...

Filtering userinput for outputting filenames in PHP

So you have a string, want to turn it into a legit filename, or just display the string in html compatible mode?

if (!function_exists("filesystemcode")){

function filesystemcode($string, $arr1="a", $arr2="b") {
$c=array();
if (isset($arr1)) {
if (!isset(${$arr1}) || !is_array(${$arr1})){
${$arr1} = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
}}

if (isset($arr2)) {
if (!isset(${$arr2}) || !is_array(${$arr2})){
${$arr2} = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");}else{$b='';}
}
if (isset($a) && isset($b)){
return str_replace($a, $b, $string);
}else{return($string);}

}
}


Remove html compatible encoded illegal filename characters:

//$string="%21dad";
$string=filesystemcode($string, "a", "c");
//echo $string; //"dad";



Remove illegal filename chars:

//$string="/dad";
$string=filesystemcode($string, "b", "c");
//echo $string; //"dad";




Convert filesystem incompatible chars into html compatible chars:

//$string="!dad";
$string=filesystemcode($string, "b", "a");
//echo $string; //"%21dad";




Convert html compatible chars into filesystem incompatible chars:

//$string="%21dad";
$string=filesystemcode($string, "a", "b");
//echo $string; //"!dad";



Note, usually you would want to urlencode($string) afterwards.

Howto pick Custom PC parts for dummys..

Hey, decided to write an quick introduction guide for beginners at picking parts for building a computer.

Basically the checklist of items you need to buy are:

* Some tower
* Power Supply Unit
* Mainboard
* Processor + cooler
* Internal memory
* HDD and/or SDD
* Videocard, depending on mainboard (does it have onboard videocard?)


The hard part is deciding which brand/models you want.

If you're in the used parts market and planning to buy from individuals instead of legit companys: Only buy individual parts for the right price (LOW), as the risk is just too high.
Best to either buy a complete used pc, or buy new parts. When you're gonna visit someone to test a complete pc, ask them to turn on the software Memtest86 atleast half a day before you come over.
When you're there it shouldn't report any errors, should report you how long it has been running, if memtest86 doesn't error, go install the software speedfan, and investigate the s.m.a.r.t. values of the hard drive. Memory errors aren't always caused by bad sticks, they can sometimes be caused by a bad mainboard, so take good care.


The PSU

Practical:

* Don't buy more then twice amount of watts that you need, for efficiency cause.

* Fanless PSUs exist for a while now. Relatively new are the hybrid PSUs, whereas the fan only starts moving if the psu gets hot, or depending on make, if its working more then for example 70%. You will have to pay extra, but even most normal psu's hardly make a sound at all (real noisemakers are usually videocards and cpu coolers). Also you can cut some old bicycle tire tube, and put pieces of rubber between your psu and your tower, to minimize resonation.

If you are worried about psu failure (stability), buy a redundant psu. Do make sure each redundant can supply more then enough watt to power your whole system.

However, a proper psu should just never fail in its lifespan, providing that you followed the instruction manual. So, ask yourself if its worth the extra cash.

Talking about resonation, we get to the technical part:

Technical:
Most reviewers get paid by manufacturers and dont actually have a clue about hardware, which is proven right here : http://www.hardwaresecrets.com/article/Why-99-Percent-of-Power-Supply-Reviews-Are-Wrong/410/

That said, here is a list of sites that actually properly test PSUs:

http://www.hardwaresecrets.com/article/Hardware-Secrets-Power-Supply-Test-Methodology/522/7

Note that hardwaresecrets.comitself also posts reviews about psus.


Mainboard / Processor
It gets tricky here.

I usually consider the cheapest option, as i usually replace my mainboard long before cheap components might die (which can be about 5 years).

You should make sure that you're buying the proper socket, one which has cpus available in a price range between 150 euro/175 dollar and 5000. Usually you then buy the 150 dollar cpu and 3 years later you buy the fastest cpu for that board for 150 as a cheap good upgrade.

http://en.wikipedia.org/wiki/CPU_socket

It's important to pick a high bus speed, and goto the website of the manufacturer to check if the mainboard supports the (almost) fastest memory on the market. Sometimes its important to check for things like for example USB3, SATA 3.2 (is for connecting hard drives). when a new technology is introduced only a tiny amount of budget boards carry it.

If you can't afford a single bit of data corruption ever, your mainboard (and memory) needs to support ECC, which stands for error correction (needs to be enabled in bios).

These errors usually are the results of influences like radiation or sunflares, so mostly these mainboards are only used in (web)servers and science and financial systems like banks.


Internal memory

Just 3 things which are really important:

* does it fit your mainboard?
* Speed
* ECC (Registered = ECC, unbuffered = no ECC)


HDD and/or SSD

for SSD drives just go here:
http://www.chip.de/bestenlisten/Bestenliste-Solid-State-Disks-SSD--index/index/id/1016/

Perhaps also here:
http://www.tomshardware.com/charts/hard-drives-and-ssds,3.html

* It's best to make sure that your ssd controller has professional ECC
* SSD is a relative new type of hard drive, therefore i don't recommend em just yet, unless you search and read about your choice extensively before you actually buy it.

For a HDD, just get alot of cache and if you don't like noise, get a low RPM drive. more RPM equals a quicker drive, however it's a really annoying sound..
Since hdds usually hold your data, you should extensively research those before you decide they are good enough for your cause.

Videocard

If your mainboard doesnt have onboard videocard, and you aren't a gamer, then i highly suggest to buy a fanless card. If you are a gamer then my opinion is always stick to nvidia. They had good linux support when ati had none, they had reliable drivers for windows when ati still had BSODs. They're just 1 step ahead imo.

The official CAPTCHA boycot.


Dear readers.

For years now, all the internet users have been proving to websites that they are not robots, thanks to a small group of exploiters, who automate crawlers to post their link everywhere on the internet.

For these same years, there have been alternate methods to keep spammers out, but webmasters and programmers are either too LAZY  to adept, or too scared of not being mainstream, causing all of us to waste our energy into telling a computer for example that 2+2=4, as if a 50 year old computer couldn't calculate that.

So how can we stop this pure timewasting? Share this post to any webmaster or webprogrammer or website that you know.
If you arent one of those, then you are allowed to stop reading now, as the stuff below doesnt concern you.


Below here is the example of an alternate method to keep spammers out, this one is written in PHP, but any web programming language can use this method. Smallest issue is that anyone submitting a form using this method, needs to have cookies plus javascript enabled, but c'mon, this is 2013, not the middle ages. Most captcha scripts also require javascript enabled anyway.

------------------
form html:
-------------
<form class="sec"  action="formhandler.php">
<input type="text" name='required"
onfocus="
var d= new Date();
$.get('handlers/token.php?'+d.getTime()+'='+d.getTime(),
function (txt){
$('.sec').append('<input type=\'hidden\' name=\'ts\' value=\''+txt+'\' />');
});
this.focus;this.select();
"

You can see this small part is written partly in jQuery markup, feel free to re-write it in normal javascript.
You can also note we need a token.php file.




------------
token.php:
------------
<?php

$ct=time();
setcookie('token',md5($_SERVER['SERVER_SIGNATURE'].$_SERVER['PATHEXT'].$_SERVER['HTTP_USER_AGENT'].$ct), 0, '/');
echo $ct;

?>



 --------------
 handler.php:
---------------
 <?php
$formtimeout=60*20; # 20 minute for fill in a form



$override="o"; # "on" for disable spammerprotection







## anti spambot validation
if (isset($_POST['ts']) && isset($_COOKIE['token']) && $_COOKIE['token']==md5($_SERVER['SERVER_SIGNATURE'].$_SERVER['PATHEXT'].$_SERVER['HTTP_USER_AGENT'].$_POST['ts']) && (int)$_POST['ts']+$formtimeout > time()){
#$allowsql=true;
}else{ if ($override!="on"){

#spamprotect debugging
#echo md5($_SERVER['SERVER_SIGNATURE'] . $_SERVER['PATHEXT']. $_SERVER['HTTP_USER_AGENT']. $_POST['ts']). "<hr />";echo $_COOKIE['token']."<hr />";
#if ((int)$_POST['ts']+$formtimeout > time()){echo  (int)$_POST['ts']+$formtimeout."<hr />";echo time();}

#possible unsafe user redirect to main page
#header("Location: ../index.html");
die("unsafe user");}
}

#your  form processing  here

 ?>