Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Aug 3, 2015

PHP namespace

When you use namespace on PHP scripts you have to use require(), require_once(), include() or include_once() . It doesn't work without one of these like you can see on this example:

php namespaces are case-insensitive:

file1.php:
namespace foo;

function 
bar()
{
    echo 
'from bar';
}
?>
file2.php:


fOo
\bar() // output: from bar
?>
This example is here:
http://php.net/manual/en/language.namespaces.rationale.php

A better example is here:
http://www.sitepoint.com/php-53-namespaces-basics/

Jul 23, 2015

Angular JS

Last days I was struggling with implementation of Angular JS on one  my websites: www.pensiunealajura.ro/mobil/

The big issue with this was to list HTML code without listing HTML tags like < or >. For instance, I wanted to have

    This is a bold text.

not

  This is a <b>bold text</b>.

So, I tried to have this with the module ngSanitize and $sanitize and $sce with  $sce.trustAsHtml.

But all of these were not good. And i dug more. And I found out that the best way to write formatted HTML code into a web page using Angular JS  is using directive ngBindHtml as is explained here: 
https://docs.angularjs.org/api/ng/directive/ngBindHtml

Now, everything is ok with my page.
:)

May 30, 2015

News about Java

A new article about Java 20 years:

Java's 20 Years Of Innovation

The importance of a given programming language—especially one as pervasive as Java—in changing how people use technology is difficult to underestimate. The big data revolution, for example, is primarily a Java phenomenon. 
[...]
Fatigue with C
However, a fatigue with C was definitely emerging. The language had two major handicaps in those days: First, it was too low level—that is, it required too many instructions to perform even simple tasks. Second, it wasn’t portable, meaning that code written in C for the PC could not easily be made to run on minicomputers and mainframes.

The low-level aspects, which still are apparent today, led developers to feel that writing applications in C was akin to mowing the lawn with a pair of scissors. As a result, large software projects were tedious and truly grueling.
The portability of C was also a major problem. Although by 1995, many vendors had adopted the 1989 ISO standard, they all added unique extensions that made porting code to a new platform almost impossible.
It’s no coincidence, then, that this era saw the emergence of a new generation of languages. In 1995 alone, there appeared Ruby, PHP, Java, and JavaScript.
Java almost immediately became popular for mainstream programming due to its portability and large set of built-in libraries. The then-mantra for Java was “write once, run anywhere.” While not strictly true initially, it quickly became so, making Java a good choice for business applications that needed to run on several platforms.

http://www.forbes.com/sites/oracle/2015/05/20/javas-20-years-of-innovation/

 


May 22, 2015

Java at 20

Remembering what the programming world was like in 1995 is no easy task. Object-oriented programming, for one, was an accepted but seldom practiced paradigm, with much of what passed as so-called object-oriented programs being little more than rebranded C code that used >> instead of printf and class instead of struct. The programs we wrote those days routinely dumped core due to pointer arithmetic errors or ran out of memory due to leaks. Source code could barely be ported between different versions of Unix. Running the same binary on different processors and operating systems was crazy talk.

Java changed all that. While platform-dependent, manually allocated, procedural C code will continue to be with us for the next 20 years at least, Java proved this was a choice, not a requirement. For the first time, we began writing real production code in a cross-platform, garbage-collected, object-oriented language; and we liked it ... millions of us. Languages that have come after Java, most notably C#, have had to clear the new higher bar for developer productivity that Java established.


James Gosling, Mike Sheridan, Patrick Naughton, and the other programmers on Sun’s Green Project did not invent most of the important technologies that Java brought into widespread use. Most of the key features they included in what was then known as Oak found its origins elsewhere:
  • A base Object class from which all classes descend? Smalltalk.
  • Strong static type-checking at compile time? Ada.
  • Multiple interface, single implementation inheritance? Objective-C.
  • Inline documentation? CWeb.
  • Cross-platform virtual machine and byte code with just-in-time compilation? Smalltalk again, especially Sun’s Self dialect.
  • Garbage collection? Lisp.
  • Primitive types and control structures? C.
  • Dual type system with non-object primitive types for performance? C++.


Apr 24, 2015

Java ME 8 and the Internet of Things

Because recently I started to work with Java mostly, I have read a lot of Java Documentation and a lot of news regarding Java. Following these I just found out that the Twitter uses Java and no Ruby anymore.

Last year I've worked a bit with Java ME. And I just read this: Internet of Thinks.

An overview and resource guide for developers new to embedded Java and IoT

Embedded systems are computer systems embedded into complete devices, whose dedicated functions reside within a larger mechanical or electrical system. Typically used in both industrial and consumer applications, embedded systems are entering the limelight with the Internet of Things (IoT). For developers just getting started with IoT, this article is a guide for learning more about the technologies that comprise Oracle's IoT platform: Java ME 8, Java ME Embedded, Java SE Embedded, and Java Embedded Suite.

In 1991, Mark Weiser, then head of Xerox's Palo Alto Research Center (PARC), attempted to capture the coming age of ubiquitous computing. Noting that "[t]he most profound technologies are those that disappear," Weiser described the various thought and technical experiments conducted by his colleagues at PARC, as they sought a new way of thinking about computers as embedded systems. Their vision, which might have seemed as fantastic as a hovercraft in 1991, is quickly becoming more commonplace today:
Sal awakens: she smells coffee. A few minutes ago her alarm clock, alerted by her restless rolling before waking, had quietly asked, "Coffee?," and she had mumbled, "Yes." "Yes" and "no" are the only words it knows [...]
At breakfast Sal reads the news. She still prefers the paper form, as do most people. She spots an interesting quote from a columnist in the business section. She wipes her pen over the newspaper's name, date, section, and page number and then circles the quote. The pen sends a message to the paper, which transmits the quote to her office [...]
Once Sal arrives at work, the foreview (in her car) helps her to quickly find a parking spot. As she walks into the building the machines in her office prepare to log her in ...

The embedded devices in Weiser's workday morning scenario use sensors to track a human user's interactions, and wireless connectivity to orchestrate a response: Sal's bed, alarm clock, and coffee maker are all connected to ensure that her first cup of coffee is underway before she rolls out of bed. For Weiser and his colleagues, this was calm computing; today we might call it the Internet of Things (IoT).

IoT overview

If there is one defining characteristic of IoT, it is interoperability, or the coordination of multiple devices. As observed in the above scenario, IoT uses sensors to collect data (in that case about Sal's interactions in her environment) and wireless connectivity to orchestrate a response. IoT is built on a confluence of technologies, including new and old hardware platforms, big data, cloud computing, and machine-to-machine (M2M) computing. APIs are the necessary glue, bringing all of these moving parts together.

Most importantly for Java developers, Java is key to many of the emerging IoT technologies already, and Oracle has committed to making Java a leading platform (if not the platform) for IoT. Java ME 8 breathes new life into Java's small device technology, extending it with a differentiated line of embedded Java platforms.
The next sections will introduce the technologies that comprise Oracle's IoT platform; follow the links to learn more about Java ME, Java ME 8, and the three embedded frameworks: Java ME Embedded, Java SE Embedded, and Java Embedded Suite.


Java ME

Java Micro Edition was originally intended to address the constraints associated with building applications for small devices. Based on Java SE, Java ME (or J2ME, as we knew it in 1999) was the platform for Java applications running on small devices with limited memory, display, and power capacity. Today it is used to develop embedded systems, ranging from industrial controls to mobile phones (especially feature phones), to set-top boxes and Blu-ray players.
Developers working in Java ME can choose from multiple configurations, profiles, and optional packages:
  • A configuration provides the most basic set of libraries and virtual machine capabilities for a broad range of devices.
  • A profile is a set of APIs that support a narrower range of devices.
  • An optional package is a set of technology-specific APIs. The Wireless Messaging API is one example. Check out Oracle's optional package primer to learn more about optional packages.

Configurations and profiles

In time two configurations have emerged: Connected Limited Device Configuration (CLDC) is the configuration for small devices, and Connected Device Configuration (CDC) is the configuration for more capable mobile devices such as smartphones and set-top boxes.
Java ME profiles sit on top of configurations, defining higher-level APIs of use to particular applications. Mobile Information Device Profile (MIDP), for instance, sits on top of CLDC and provides user interface, networking, and persistent storage APIs. Applications that run in a CLDC/MIDP environment (such as games) are known as MIDlets.

Java ME 8

In late 2012, Oracle embarked on an ambitious project to deliver a major update of the Java ME platform standard. Two Java Specification Requests (JSRs) were designed to meet current market requirements for embedded devices and prepare Java ME for future Java platform specifications: JSR 360 (CLDC 8), an evolutionary update to CLDC 1.1.1, would bring the virtual machine, Java language, and libraries up to date with Java SE 8. JSR 361 (Java ME Embedded Profile/MEEP 8) would update Information Module Profile - Next Generation (IMP-NG).

CLDC 8 and MEEP 8

CLDC 8 is based on JSR 139 (CLDC 1.1) and aligns the core Java ME virtual machine, language support, libraries, and other features with Java SE 8:
  • The virtual machine has been updated to comply with version 2 of the JVM specification.
  • Newer Java SE language features such as generics, assertions, annotations, and try-with-resources are now supported.
  • New libraries such as Collections, NIO subset, and Logging API subset are now supported.
  • A consolidated and enhanced Generic Connection Framework for multi-protocol I/O is supported.
MEEP 8 updates the original IMP-NG specification to provide a powerful and flexible application environment for small embedded Java platforms. The specification builds on CLDC 8 with the following features:
  • A new, lightweight component and services model
  • Shared libraries
  • Multi-application concurrency, inter-application communication, and event system
  • Application management
  • API optionality to address low-footprint use cases

The long, strange life, death, and rebirth of Java

Java at 20: Where do we go from here?


 May 23, 1995 saw the fruits of a four-year project at Sun Microsystems called Java. The new language with a C-like syntax promised the ability to write once and run anywhere through the use of virtual machines that compiled the code on the native platform at runtime.

The project began in 1991 when a small group of Sun engineers called the "Green Team," led by James Gosling, began working on a language and networking system for the next generation of digital consumer devices and computers.

In the 20 years since its launch, Java has exploded in use, been the subject of lengthy litigation with Microsoft, grew and died on the desktop, moved to the server, then jumped to feature phones, only to have its lunch eaten by smartphones, fallen into such disarray that the Department of Homeland Security said not to use it, and is now enjoying a renaissance under the stewardship of Oracle.
What other programming language can claim such drama?

When the project began, Sun saw a collision of the computer industry and non-computer industry technologies like cell phones to stereo systems to railroads to whatever. Sun noticed that they were all, in some form or another, reinventing computer science.

"The unifying theme was networking," said Gosling, now chief software architect for Liquid Robotics. "When we looked at these companies, they were designing their own networking and doing a really bad job of it. A lot of it was predictable. They were repeating a number of experiments we'd had in computer science 30 years ago."

The problem was the consumer electronics people didn't take networking into account, like common APIs across multiple platforms, or code reuse. "There was essentially no software reuse. Everybody was reinventing everything over and over again. We were trying to get to a place where we had models to help them get out of that," said Gosling.

"I really think Java's future is in IoT. I'd like to see Oracle and partners focused on a complete end-to-end storage solution for Java, from devices through gateways to enterprise back-ends. Building that story and making a success of it will help cement the next 20 years for Java. Not only is that a massive opportunity for the industry, but also one I think Java can do quite well." - Mike Milinkovich, executive director of the Eclipse Foundation

Read more here: http://www.javaworld.com/article/2912380/java-platform/the-long-strange-life-death-and-rebirth-of-java.html

Dec 11, 2013

Excel VBA: Clipboard clear

This year I started to work into a big company. Here I need to code in MS EXcel VBA. Or VBA Access.

Trying to copy the data from a Excel Sheet to another Sheet, I started to use VBA Clipboard. But, at the end, the clipboard has remained full. The solution  was following:

Clipboard clear 

If you want to cleanup the clipboard of an Excel using VBA, this is the way:
Application.CutCopyMode = False

Jul 6, 2010

MySQL tutorial - Managing database

Creating Database

To create a database in MySQL, you use the CREATE DATABASE statement as follows:
CREATE DATABASE [IF NOT EXISTS] database_name;
CREATE DATABASE statement will create the database with the given name you specified. IF NOT EXISTS is an option part of the statement, this part prevents you from error if there is a database with the given name exists on the database server. In our tutorial, for example, to create classicmodels database, you just only apply CREATE DATABASE statement above as follows:
CREATE DATABASE classicmodels;
After executing the statement, the MySQL will returns you a message to indicate whether the execution are successful or not.

Showing Databases

SHOW DATABASE statement will show all databases in your database server. You can use SHOW DATABASE statement  to check the database you've created or to see all the databases' name on the database server before you create a new database.
SHOW DATABASES;
On my database server, the output is :
+--------------------+
| Database           |
+--------------------+
| information_schema |
| classicmodels      |
| mysql              |
+--------------------+
8 rows in set (0.00 sec)

Selecting Database

To select a database which you plan to work with, you use USE statement
USE database_name;
You can select our sample database by using the USE statement as follows:
USE classicmodels;
From now you can query the tables' data and do whatever you want inside the selected database.

Removing Database

Removing database means you delete the database. All the data and related objects inside the database are permanently deleted and cannot be undone. So it is very important to execute this query with cares. To remove the database you can use DROP DATABASE statement as follows :
DROP DATABASE [IF EXISTS] database_name;
Like CREATE DATABASE statement, IF EXIST part is an optional part to prevents you from removing database which is not existed. In order to practice with DROP DATABASEstatement, you can create a temporary database, show the database on the database server, and drop it step by step as follows :
CREATE DATABASE IF NOT EXISTS temp_database;
SHOW DATABASES;
DROP DATABASE IF EXISTS temp_database;