Archive for the ‘Linux’ Category

Laravel 5.1 development with the Atom editor

Tuesday, June 30th, 2015

The brand new Atom editor is heavily inspired by Sublime, build as an open source project on webtechnology, so CSS, JavaScript and HTML, Coffeescript, LESS and NodeJS, it’s founded by Github and really hackable into the next generation.

It sports a package installer, and a nice repository full of plugins, more then 2100 at the moment.

It just released version 1.0, for Linux, Windows and OS-X. Atom is free and open source.

In short I like it. It has good support for syntax-highlighting, code-completion and snippets. A code beautifier is available as package, and so is Emmet. Atom is more an editor than a full-blown IDE, like Netbeans, but packages are really easy to build, so I guess, a lot of extending is possible.

For Laravel you need some tweaks.

Improve Laravel support in Atom

Install some extra Laravel related packages:

  • language-blade
  • atom-laravel

There are more packages like blade-snippets, but actually you don’t need them. Snippets are include in the language-blade package, although the documentation lacks to mention that. The documentation just says:

Blade templating support in Atom

Actually it adds snippets too.

Make Atom act as a IDE

A great feature of Atom is the build in Tree View. Open a projectfolder, and Atom will show you a nice tree folder view.
But to browse through your files, use another feature. Atom will index all files. CTRL P will open an findAll dialog, or a fuzzy finder and that is the fastest way to change and find files in your project. Much like Sublime or Netbeans, or CTRLP plugin for VIM.

Another IDE feature Goto Declaration doesn’t seem to work. And that is true, it doesn’t work out of the box. That did confuse me and apparently others. It needs a CTAG file. CTAG files are created by another program Exuberant Ctags. Atom’s approach is much like the Unix philosophy. Don’t invent the wheel, or

  1. Small is beautiful.
  2. Make each program do one thing well.

Exuberant Ctags does something well, so don’t imitate it. Use it.

How to install Exuberant Ctags for Atom support

sudo apt-get install exuberant-ctags

Then CD into your working directory, the root of your project:

cd ~/project

Then run CTAGS to create the TAGS file:

ctags -R --languages=php

That’s it. Goto Declaration will now work on Laravel helper functions and classes.

Great. Netbeans lacks support for Laravel, and especially editing blade files is much easier in Atom with the language-blade package.

Atom isn’t the fastest editor, it’s isn’t optimized yet that much according to the developers, and it is build upon web technologies. That means it’s hackable and extendible for nearly everyone. For that it already got a sweet spot here and no doubt the community will build every package you can think of. It´s so easy and well integrated with Github. Bright future.

Dating takes time, women are difficult but PHP?

Wednesday, March 18th, 2009

One of the big annoyances is having a blog or webpage in a certain language and that all the dates appear on your website in English. Of course you can choose just numbered formats, but sometimes the month or the day of the week in words adds that needed little extra polish.

Formatting a date in PHP

Normally a date is formatted like this with the date() function:

[sourcecode language=”php”]
< ?= date(‘d-m-Y’) ?>
[/sourcecode]

Formatting a localised date in PHP

But to format a date in your preferred language you need to use the strftime function:

Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale().

So we also need the setlocale() function. This function let you set the language to use for the formatting. Your system or server should have them installed, otherwise it’s not possible! And most of them are not installed by default, although easily available.
What does the setlocale() function do:

Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.
An invalid category name also causes a warning message. Category/locale names can be found in RFC 1766 and ISO 639. Different systems have different naming schemes for locales.

Tough pages to consume to be honest, but let’s go on.

Locales settings on your server

You can find the installed localisations in this file on a Linux server:

[sourcecode language=”xml”]
vi var/lib/locales/supported.d/local
[/sourcecode]

My server only had one line by default!
Simply add the one’s you’re missing. You can find all possible localisations in this file:

[sourcecode language=”xml”]
/usr/share/i18n/SUPPORTED
[/sourcecode]

Don’t add them all: it will decrease performance.

So we’re nearly done:

[sourcecode language=”php”]
< ?
setlocale(LC_TIME,’nl-NL.UTF-8′);
echo strftime(‘%s-$b-%y’,time())
?>
[/sourcecode]

You need to enter the correct encoding aswell, otherwise it won’t work. This is dependent of the server settings, so it will influence the portability of your code a bit.
Above code will give you the current date in Dutch, but we need another function to create localised dates from stored timestamps of the MySQL database.

Converting stored Timestamps to PHP understandable format

A MySQL timestamp value won’t work as a direct input to the strftime function. We need to convert it with another function: strtotime.

So we end up with something like this:

[sourcecode language=”php”]
< ?
setlocale(LC_TIME,’nl-NL.UTF-8′);
echo strftime(‘%A %d $b %y’,strtotime($row->timestamp))
?>
[/sourcecode]

Quite a long road to take for a boring date!

Localizing Ubuntu

Tuesday, October 10th, 2006

Ubuntu is a Debian based Linux distribution. In its few years of existence it made quite an impression by its support and speed of development. If offers the advantage to Debian in the way it supports the modern and rare hardware. I had no problem installing it on a new Dell right out of the box. I use the server version of Dapper Drake 6.06 on my PHP server. Once you have installed the OS, you can run into problems localizing your system. I wanted to have Dutch dates on my Dutch website and English dates on my international sites. The way to add support for different languages differs quite a bit from earlier Ubuntu versions, because ‘dpkg-reconfigure locales’ doesn’t work. But once you know the secret is not difficult at all.
(more…)

Your are browsing
the Archives of My Beloved PHP in the 'Linux' Category.
Categories
Archives
Links