Showing posts with label coder. Show all posts
Showing posts with label coder. Show all posts

Sep 23, 2015

Generate random string with PHP

If you want to generate random code with PHP you can use this function:

<?php
public function genRandmStr($lgt = 8){
       
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@#!';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $lgt; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
}

// you can see the result here
echo genRandmStr();
?>

Sep 18, 2015

CakePHP how to retrieve POST and GET vars

When you are working with CakePHP framework and you try to retrieve the variables which have been sent through GET or POST.

For POST variables you have

For $_POST['key']  we have
$this->request->data('key');


For GET variables you have

For $_GET['kpa']  we have
$this->request->query('kpa');


Sep 8, 2015

HTML5 vs HTML

There is some differences between HTML and HTML5. So though, we have:

HTML5 was designed to replace both HTML 4, XHTML, and the HTML DOM Level 2.
And XHTML is HTML + XML. For a better syntax and for a better administration they had to force HTML to be proper: for instance, if you open this tag <p> you have to close the tag with </p>.

The main goals of HTML5 are:
- Deliver rich content as graphics or movies without the need of additional plugins as Flash, for instance;
- Provide better semantic support for web page structure. For this, HTML5 introduces new structural element tags;
- Provide better cross-platform support (for PC browser, tablet or smartphone);
- Provide a stricter parsing standard to simplify error handling, ensure more consistent cross-browser behavior.

HTML5 has improved the support for embedding graphics, video and audio. For that HTML5 has some new tags: <canvas>, <audio>, <video>

HTML5 has introduced web workers. A web worker is a script that runs in the background, in another thread, without the page has to wait for it to complete. The visitor can continue to interact with the page while the web worker runs in the background.


HTML5 has new semantic tags to complement the structural logic of modern web applications. Here we have:
<main>
<nav>
<article>
<section>
<header>
<footer>
<aside>

HTML5 has new controls like
<calendar>
<date>
<time>
<email>
<url>
<search>



HTML5 has new extensions to the Javascript API as geolocation, drag-and-drop, storage and caching.

Aug 28, 2015

CakePHP and PHP version

I was trying to code at my project. It was OK on my localhost webserver. But... when I moved the files on the real webserver I had a problem.
I didn't know what could that be. I got errors just on some pages. Not at all pages of my website.
Then, I realized that, perhaps, my version of PHP could be too old. Actually, not my version but real webserver version.

Indeed, the problem it was with PHP version which is 5.3 and this version doesn't know about the arrays declared like this:

$ar = ['key1' => 'value1', 'key2' => 'value2'];

It knows only like this:

$ar = array('key1' => 'value1', 'key2' => 'value2');

I got this issue when I tried to make a Form and I finished to have this PHP code

echo $this->Form->input('name', [
                'label'=>[
                    'class' =>  'ContactInput',
                    'text'  =>  'Name:' . $messgError['name']
                ]

            ]);



Apr 24, 2015

No more Security fixes for Java 7

Oracle to end publicly available security fixes for Java 7 this month

Users are advised to migrate to Java 8

Public updates for Java 7 -- including bug and security fixes -- will end this month, a situation that one security advocate says could impact millions of applications.

"As outlined in the Oracle JDK [Java Development Kit] Support Roadmap, after April 2015, Oracle will not post further updates of Java SE [Standard Edition] 7 to its public download sites," Oracle's Java SE Support Roadmapstates. "Customers who need continued access to critical bug fixes and security fixes as well as general maintenance for Java SE 7 or older versions can get long-term support through Oracle Java SE Support. The process of migrating users from Java 7 to Java 8 through the auto update feature is expected to take place after the January 2015 CPU release."

Oracle released Java SE 7 in July 2011; Java SE 8 was released in March 2014. Java, particularly on the client side, has been beset by security issues in recent years. But Oracle has taken many steps to address the issues and stressed that most of the problems dated back several years, before Oracle took over Java from Sun in 2010.

Still, the impact of Oracle's cessation of public updates could be severe, an official at security firm Waratek, believes. Oracle's "rapid" end-of-life schedule for Java versions is great for innovation and language evolution, Waratek CTO John Matthew Holt said in an emailed statement. "However, there is a dangerous tradeoff; now millions of Java 7 applications will have to defend themselves against code-level vulnerabilities without the benefit of future fixes." Holt advocates either upgrades to Java 8 or use of Java Run-time Application Self Protection (RASP) technologies (Waratek is a RASP vendor).

This week's security update from Oracle, meanwhile, marks the "proverbial 'end of the road' for Java 7 application security, Holt said. "After today, the only version of the Java Platform which will receive public security updates is Java 8.  This is huge news, and it is going to cause enormous headache and disruption to millions of application owners around the world."
Contacted Tuesday afternoon for a comment on the end of public updates for Java SE 7, by late evening Oracle had not yet responded.

The April 2015 Critical Patch Update released Tuesday by Oracle provides 98 new fixes for security issues across a wide range of product families, said Eric Maurice in an Oracle blog post. These range from Oracle Database to Oracle Fusion Middleware, Java SE, and MySQL. Fourteen of the security fixes are for Java SE.

This story, "Oracle to end publicly available security fixes for Java 7 this month" was originally published by InfoWorld.



Dec 20, 2011

Creating XML from MySQL as easy as PI


ANALYSIS
Unfortunately, importing XML into MySQL is more like chocolate cheesecake, but there are solutions available. Just follow this guide and you'll be on your way to integrating Web services with your database in no time. Starting from scratch
With the growing popularity of XML, developers have found an easy method to present data sets in a standardised way. What else does that sound like? A database! It's only natural that it should be simple to convert your information without a lot of fuss -- and you can. Some proprietary database manufacturers, such as Microsoft and IBM, have taken steps to integrate XML into their systems. This comes as no surprise since these two companies are both heavily involved in the XML standardisation project. Not wanting to be left behind, the creators of MySQL database incorporated a means for generating an XML data file. It's supported in version 3.23.48 and up. You can use the command line or facilitate the process with the programming language of your choice. To get started, you can download MySQL database  for free from MySQL.com. The current release is sufficient to support this feature, and you don't need to compile it with any special parameters. Fruit filling
Once you're installed, created, and populated your database, execute the following command to generate an XML file:
mysqldump --xml databasename [tables]
If you'd like to save this to a file, simply use the standard *NIX method of outputting to a file:
mysqldump --xml databasename > filename.xml
This produces a well formed XML document. Because XML is datacentric, if you dump your entire database and it contains no information, your file will result in a series of empty tags based on the table names. Your output should look something like this:

Now you're free to use this data file with any application you desire. This method is useful in a number of ways. Not only will it create a standardised representation of your data, but it can also take a snapshot of your database (or portion of your database) for display. Rather than making repeated calls to the database server, just generate an XML document when your database changes and reference that from Web pages or whatever you're using. This can localize calls for data, reduce the overhead of frequent calls to a database, and easily present a subset of your information for improved performance, security, or localization. Ice cream on the side
It's really easy to get XML from MySQL, but how about the other direction? That's a little trickier. MySQL itself doesn't support this function, and with good reason. The database currently has no way to validate the XML file. This could result in a number of scenarios, ranging from a partial load to ignoring malformed tags and statements to simply forcing the entire load to fail. MySQL supports only cascading back-outs in current development versions. While it's not pretty from a native standpoint, you do have some options. One solution is Perl's DBIx::XML_RDB module. You can use this method to both import and export XML, though understandably the import is heavily dependent upon a correctly structured XML file. To get the data, the module essentially runs a query and formats the results in an XML file. Conversely, you can use the module to read an XML file, create a SQL query, and execute it. There is a simpler option as well. The DBIx::XML_RDB module ships with two utility scripts to facilitate the process: xml2sql.pl and sql2xml.pl. I found agreat tutorial  on using this Perl module at O'Reilly's XML.com Web site. It will walk you through the process. Another, more generalized effort comes from Ron Bourret's XML-DBMS project . This is an ongoing effort to support XML imports and exports with relational databases using Perl and Java. There's also some very interesting work that supports mapping one database to another using XML as facilitating middleware. This is a community-oriented open source project being managed on SourceForge . Other languages, particularly Web scripting languages, haven't ignored the need to import XML into SQL databases either. There are similar efforts for Python, such as the xml2sql and dtd2sql modules, outlined in detail in this article from IBM , and a couple of projects in the works for PHP, such as the "XML MySQL class" project. Scrumptious
With these utilities, importing and exporting XML into and from MySQL is easy! Since MySQL is popular and free, it's been the test bed for integrating many scripting languages in XML, and as a result there are a number of tutorials and scripts specific for this database. With the power of a relational database and the ability to easily create XML files, MySQL can be an integral part of your Web services solution.

Mar 9, 2011

PHP number of days of a month

If you want to obtain number of days of a month, in PHP, you can use cal_days_in_month function:


int cal_days_in_month ( int $calendar , int $month , int $year )







So, here we have one example of usage of this function:


$num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
    echo "There was $num days in August 2003";
?>

Jul 9, 2010

Analog Clock with JavaFX

Last mounth just I have commenced learning JavaFX.

I have entered on the site www.javafx.com and I have started with some tutorials. And after couple of hours I started with Analog Clock. And I have modified the code and I have saved as desktop application. And now rules like that:


My code look like this:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


/**
* @author Stefan Vilceloiu
*/

//public class Main {

import java.util.Calendar;
import java.util.Date;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.Scene;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

// varies according to scene size

var width:Number = bind scene.width;
var height:Number = bind scene.height;

// list of months
var months:String[] = ["IAN", "FEB", "MAR", "APR", "MAI", "IUN",
"IUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
var radius:Number = bind width/3; // Decides the main size of the clock
var centerX:Number = bind scene.width/2; // Shifting the X center
var centerY:Number = bind scene.height/2; // Shifting the Y center
var hours:Number;
var minutes:Number;
var seconds:Number;
var date:String;
var month:String;
var year:String;
var combination: String;

var time = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames: [
KeyFrame {
time: 1s
action: function() {
actionOnTick();
}
}
]
}

time.play();

//instance of calendar
function createCalendar() {
var date = new Date();
def calendar = Calendar.getInstance();
calendar.setTime(new Date()); // fix for mobile
calendar
}
// action taken on one tick
function actionOnTick () {
var calendar = createCalendar();
seconds = calendar.get(Calendar.SECOND);
minutes = calendar.get(Calendar.MINUTE);
hours = calendar.get(Calendar.HOUR);
date = String.valueOf(calendar.get(Calendar.DATE));
if(date.length() != 2) {
date = "0{date}";
}
month = months[(calendar.get(Calendar.MONTH))];
year = String.valueOf((calendar.get(Calendar.YEAR)));
combination = "{date}-{month}-{year}";
}
//scene which can be dynamic
var scene:Scene = Scene {
width: 233
height: 260
fill: Color.TRANSPARENT
content: [
Group {
translateX: bind centerX
translateY: bind centerY
content: bind [
Circle {
radius: radius + 20
fill: RadialGradient {
centerX: 0
centerY: 0
radius: radius + 20
proportional: false
stops: [

Stop {
offset: 0.9
color: Color.SILVER
},
Stop {
offset: 1.0
color: Color.BLACK
}
]
}

},
Circle {
radius: radius + 10
stroke: Color.BLACK
fill: RadialGradient {
centerX: 0
centerY: 0
radius: 90
proportional: false
stops: [
Stop {
offset: 0.0
color: Color.WHITE
},
Stop {
offset: 1.0
color: Color.ANTIQUEWHITE
}
]
}

},
Rectangle {
x: -35,
y: 2 * radius / 3 - 15
width: 71
height: 20
fill: Color.GRAY
opacity:0.4
strokeWidth: 2
stroke: Color.BLACK
arcHeight:10
arcWidth:10
},
Text {
font: Font {
size: 11
name: "Arial"
}
x: -31 ,
y: 2 * radius / 3
content: bind combination
},
Text {
font: Font {
size: 11
name: "Tahoma"
}
x: -24 ,
y: -1.21 * radius / 3
opacity:0.85
fill: Color.RED
content: "Vilceloiu"
},
for (i in [3, 6, 9, 12]) // Setting the main digits 3,6,9,12
Text {
transforms:bind [
Transform.translate(-5, 5)
]
x: radius * (( i + 0 ) mod 2 * ( 2 - i / 3))
y: radius * (( i + 1 ) mod 2 * ( 3 - i / 3))
content: "{i}"
font: Font {
size: 12
name: "Tahoma"
}
},
// making dots on rest of the place
for (i in [1..12])
if (i mod 3 != 0 ) then Circle {
transforms:Rotate {
angle: 30 * i
}
centerX: radius
radius: 4
fill: Color.BLACK
} else [ ],

// circle at the core center
Circle {
radius: 5
fill: Color.BLACK
},
// one more circle inside the above circle
Circle {
radius: 3
fill: Color.GRAY
},
// second arm
Line {
transforms: Rotate {
angle: bind seconds * 6
}
endY: -radius - 3
strokeWidth: 2
stroke: Color.RED

},
// hour arm
Path {
transforms: Rotate {
angle: bind (hours + minutes / 60) * 30 - 90
}
fill: Color.BLACK
opacity: 0.8
elements: [
MoveTo { x: 4, y: 4 },
ArcTo {
x: 4
y: -4
radiusX: 1
radiusY: 1
},
LineTo { x: radius - 23 y: 0 },
]
},
// minute arm
Path {
transforms: Rotate {
angle: bind minutes * 6 - 90
}
fill: Color.BLACK
elements: [
MoveTo { x: 4, y: 4 },
ArcTo {
x: 4
y: -4
radiusX: 1
radiusY: 1
},
LineTo{ x: radius y: 0 },
]
}
]
}
]
};

Stage {
style: StageStyle.TRANSPARENT
title: bind combination
scene: bind scene
width: 240
height: 320
}
//}



And now you can see my name on the clock and the current date in the bar (bottom)