Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

January 9, 2016

Termux - all you need for development on Android

I just bought myself new Android phone (before I used several years old-school Nokia with Symbian) and I found myself totally surprised when I discovered Termux. You can install Vim, PHP (version 5.6), Python, GCC, golang - all you need.
If I was aware of this I would buy phone earlier but I always think that it is just a useless toy since I'm not interested to by social.

August 27, 2015

Simple file caching in PHP

If you are creating simple file cache in your PHP code and wondering about the performance try this great article - Cache a large array: JSON, serialize or var_export? (written by Taco van den Broek).

July 6, 2015

Visual Studio Code

I like to test various code editors and currently I'm using Visual Studio Code from Microsoft (yes, it's open source editor from MS running on Linux :)). I'm using it mainly for developing add-ons for Mozilla Firefox (HTML+JavaScript+CSS) and PHP projects and I'm pretty impressed.

For example here is a screenshot when I was editing JavaScript code where I made a mistake that I pushed new items into bad array (see highlighed parts of code below and you will understand):


The error shown is really usefull...

May 18, 2015

No more binary XPCOM components in Firefox

From Firefox 40 will be dropped support for binary XPCOM components - so another piece of history on which I started "real" programming will be gone. Some of you maybe remember XPCOMViewer :)

You can see more details here: https://blog.mozilla.org/addons/2015/05/04/dropping-support-for-binary-components/ and here https://groups.google.com/forum/#!topic/mozilla.dev.extensions/B3H3j6FRVms

June 24, 2014

IDE hidden in Firefox nightly

Today I read interesting article on the Mozilla Hacks blog about new WebIDE and I have to say that on my low-cost netbook is this the first IDE targeted on mobile system that actually works and is usable on slower machines (including emulator of course).
Below is a screencast which I borrowed from the original article:



I must say that while Firefox maybe have not market-share as some time ago but still it is the perfect solution for the professionals.

June 8, 2014

Creating sidebar add-on for the Firefox with Australis UI

I'm creating simple add-on for Mozilla Firefox and even I did such add-ons before I run into the troubles. It's because of new Firefox UI called Australis and because I want this add-on to be bootstrapped (so it doesn't require browser restart to complete the installation).
After a short googling I found CustomizableUI.jsm and I finally got the working solution.
So here is my bootstrap.js which adds the sidebar:

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const { classes: CC, interfaces: CI, utils: CU } = Components;
const self = {
    id: "tagssidebar@ondrejd.info",
    name: "TagsSidebar",
    path: {
        chrome: "chrome://tagssidebar/"
    }
};
const prefPrefix = "extensions." + self.id + ".";

CU.import("resource://gre/modules/Services.jsm");
CU.import("resource:///modules/CustomizableUI.jsm");

var gStylesSrv;
var gStylesURI;

// Bootstrap API: install(aData, aReason)
function install(aData, aReason) {
    if (aReason == ADDON_INSTALL) {
        // Set default preferences
        let prefs = Services.prefs.getBranch(prefPrefix);
        prefs.setBoolPref("showInSidebar", true);
        prefs.setBoolPref("showTagCloud", false);
        prefs.setBoolPref("showFavicons", false);
    }
} // end install(aData, aReason)

// Bootstrap API: uninstall(aData, aReason)
function uninstall(aData, aReason) {
    if (aReason == ADDON_UNINSTALL) {
        // Remove default preferences
        Services.prefs.deleteBranch(prefPrefix);
    }
} // end uninstall(aData, aReason)

// Bootstrap API: startup(aData, aReason)
function startup(aData, aReason) {
    // Create new toolbar button
    CustomizableUI.createWidget({
        id: "tagssidebar-toolbarbutton",
        defaultArea: CustomizableUI.AREA_NAVBAR,
        label: "TagsSidebar",
        tooltiptext: "Toggle visibility of TagsSidebar.",
        type: "button", 
        onBeforeCreated: function(aDocument) {
            // We need to add more UI than the toolbarbutton (broadcaster, key and menuitem):
            // Broadcaster
            let bcset = aDocument.getElementById("mainBroadcasterSet");
            if (bcset) {
                let bc = aDocument.createElementNS(XUL_NS, "broadcaster");
                bc.setAttribute("autoCheck", "false");
                bc.setAttribute("group", "sidebar");
                bc.setAttribute("id", "viewSidebar_tagssidebar");
                bc.setAttribute("oncommand", "toggleSidebar('viewSidebar_tagssidebar');");
                bc.setAttribute("sidebarurl", "chrome://tagssidebar/content/sidebar.xul");
                bc.setAttribute("sidebartitle", "TagsSidebar");
                bc.setAttribute("type", "checkbox");
                bcset.appendChild(bc);
            }
            // Key
            let keyset = aDocument.getElementById("mainKeyset");
            if (keyset) {
                let key = aDocument.createElementNS(XUL_NS, "key");
                key.setAttribute("command", "viewSidebar_tagssidebar");
                key.setAttribute("id", "key_openSidebar_tagssidebar");
                key.setAttribute("key", "t");
                key.setAttribute("modifiers", "accel,shift");
                keyset.appendChild(key);
            }
            // Menuitem
            let mp = aDocument.getElementById("viewSidebarMenu");
            if (mp) {
                let mi = aDocument.createElementNS(XUL_NS, "menuitem");
                mi.setAttribute("key", "key_openSidebar_tagssidebar");
                mi.setAttribute("label", "TagsSidebar");
                mi.setAttribute("observes", "viewSidebar_tagssidebar");
                mi.setAttribute("tooltiptext", "Toggle visibility of TagsSidebar!");
                mp.appendChild(mi);
            }
        },
        onCreated: function(aNode) {
            // Add ID of broadcaster we created before as a command:
            aNode.setAttribute("command", "viewSidebar_tagssidebar");
            return aNode;
        }
    });

    // Load stylesheet
    gStylesSrv = CC["@mozilla.org/content/style-sheet-service;1"].getService(CI.nsIStyleSheetService);
    gStylesURI = Services.io.newURI(self.path.chrome + "skin/overlay.css", null, null);
    gStylesSrv.loadAndRegisterSheet(gStylesURI, gStylesSrv.USER_SHEET); 
} // end startup(aData, aReason)

// Bootstrap API: shutdown(aData, aReason)
function shutdown(aData, aReason) {
    if (aReason == APP_SHUTDOWN) return;

    // Destroy our widget
    CustomizableUI.destroyWidget("tagssidebar-toolbarbutton");

    // Unload stylesheet
    if (gStylesSrv.sheetRegistered(gStylesURI, gStylesSrv.USER_SHEET)) {
        gStylesSrv.unregisterSheet(gStylesURI, gStylesSrv.USER_SHEET);
    }
} // end shutdown(aData, aReason)

May 27, 2014

24 Free programming books

Today I found interesting post on LinuxLinks.com - you can find here links to twenty four free books each for different programming languages:

May 20, 2014

Nice Bash find-and-replace script

It's some time when I read the post Scripting a 'Find-and-Replace' for big text files by Bob Mesibov. Yesterday I finally got some time to look at it and use it as a learning material. I must frankly admit that I would have real troubles to write something like this in Bash - usually I'm using PHP in such cases.
Because in the original post is only the image not the source of script self I saved it into one my repository so you can easily use it - fandr.sh.

April 16, 2014

WordPress: Anonymous PHP functions

Recently I wrote about my problem with WordPress editor and now I realize that I wanted to write also about something different - using anonymous functions in WordPress development - it's amazing how using of them can simplify your code (if you forget older PHP versions).

Compare these examples:

<?php
// Sets WordPress admin bar hidden.
// Old:
add_filter('show_admin_bar', '__return_false');
// New:
add_filter('show_admin_bar', function() { return false; });

// Activate widgets
// Old:
add_action('widgets_init',
     create_function('', 'return register_widget("Your_Widget_Class");')
);
// New:
add_action('widgets_init', function() {
    register_widget('Your_Widget_Class');
});

And of course that this can be used everywhere you're using function such add_action, add_filter etc.







April 15, 2014

WordPress: Custom font family in TinyMCE editor

I tried to add custom font family to the WordPress editor but it turns to the little battle - firstly I just do what is described in the WordPress Codex:

your-theme/functions.php:
<?php
function your_theme_editor_styles() {
    add_editor_style('assets/css/editor-style.css');
}
add_action('init', 'your_theme_editor_styles');
?>

your-theme/assets/css/editor-style.css:
@font-face {
    font-family: CharisSILBold;
    src: url(../fonts/CharisSIL-Bold.woff);
}

body#tinymce.wp-editor { 
    font-family: CharisSILBold; 
    font-size: 14pt;
}

But it doesn't work (of course). Then I look into the default theme and found the solution (code in functions.php is the same as before so here only editor-style.css):

your-theme/assets/css/editor-style.css:
@font-face {
    font-family: CharisSILBold;
    src: url(../fonts/CharisSIL-Bold.woff);
}

html .mceContentBody { 
    font-family: CharisSILBold;
    font-size: 14pt;
}

It sucks that small things take so much time (but of course it's my fault).

Tested on WP 3.8.*.



March 10, 2014

Mozilla Brick - UI Components for Modern Web Apps

I just discovered Mozilla Brick - a bundle of reusable UI components for rapid development of cross-browser and mobile-friendly HTML5 applications. What is interesting is made using X-Tag which JavaScript library that provide the same as old and powerful XBL.
Hopefully I will get opportunity to try it on same real project soon.

March 9, 2014

Microsoft .NET Applications in OpenShift

Some time ago I wrote about OpenShift - open cloud platform. Today I read a nice article on ZDnet about support for .NET applications ... on more reason for using OpenShift!
Get more informations here: http://www.zdnet.com/red-hat-brings-microsoft-net-apps-to-its-openshift-cloud-7000027019/

February 22, 2014

Time tracking utility - doTimeTracker CLI 0.2

Today I made visible my BitBucket repository with odTimeTracker CLI. It's a Linux command line utility for tracking time that you spent working on various tasks. Is written in Vala and is a part of bigger solution for dealing with common office tasks for the freelancers as am I. I will explain this a little bit more very soon.

There are some screenshots:


More screenshots can be found in this web album.


February 20, 2014

Simple Carousel

I was working on one web when I needed simple carousel - I have simple requirements:
  • based on jQuery (since I'm using it on that site)
  • really, really small footprint
  • allow multiple carousels on one page
I spent some time with searching but I found nothing what I like so I made mine. The code is really simple and works just fine - you can see for yourself on jsFiddle.

If you want you can download it:

January 30, 2014

OpenShift from RedHat

I don't know if you are aware of OpenShift from RedHat - but if you don't try it. It is really good place for trying technologies or developing new projects. For free you get three slots for applications that you can use various technologies such as:
As you can see it offers really lot and for free - I don't know better service for freelance developers.

December 31, 2013

Zabezpečení WordPressu

Zde si popíšeme několik způsobů, jak lépe zabezpečit web používající WordPress. Nejprve však jedno upozornění - jedno z nejdůležitějších pravidel je udržovat WordPress aktualizovaný na poslední verzi, stejně tak i nainstalované pluginy (či témata vzhledu).

Před instalací


Nejprve je vhodné změnit prefix databáze v souboru wp-config-sample.php z původního prefixu:

$table_prefix = 'wp_';

na nějaký jiný:

$table_prefix = '1w27p_';

Po změně přejmenujte z wp-config-sample.php na wp-config.php a přejděte k normální instalaci.

Po instalaci


Po instalaci WordPress nastaví přihlašovací jméno na admin - toto je dobré změnit na jiné. Zároveň by heslo mělo být odolné - nejlepší je vygenerovat si silné heslo pomocí některých on-line generátorů hesel.

Zabezpeční adresáře wp-admin


Dále je vhodné omezit přístup do složky wp-admin dle IP adresy administrátora (či více administrátorů). Toho lze docílit vytvořením souboru .htaccess s tímto obsahem:

Deny from all
Allow from <Your IP>

Přístup do adresáře wp-admin je vhodné zabezpečit i přes heslo.

Zabezpečení souboru wp-config.php


Soubor wp-config.php lze zabezpečit dvěma způsoby - buď přesunout tento soubor o adresář výše (což na mnoha serverech znamená mimo dosah běžných návštěvníků) nebo přístup k němu můžete omezit v souboru .htaccess:

<files wp-config.php>
order allow,deny
deny from all
</files>

Zabezpečení adresářů wp-includes a wp-content


Poté je vhodné omezit i přístup k většině souborů ve složkách wp-includes a wp-content - přístup povolíme pouze k obrázkům, CSS a JavaScript souborům. Toto zařídíme přidáním následujících řádek do souboru .htaccess:

Order Allow, Deny, Deny from all
<Files ~ ".(css|jpe?g|png|gif|js)$">Allow from all</Files>

Jiný způsob (dle WordPress Security) a mnou doporučovaný je:

# Block the include-only files.
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]

# BEGIN WordPress
...

Poznámka: Kód výše musí být mimo tagy # BEGIN WordPress and # END WordPress jinak může dojít k přepsání při změně nastavení systému WordPress.
Také je třeba si uvědomit, že toto nebude správně fungovat na Multisite, protože RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] zabrání souboru ms-files.php v generování obrázků. Pokud tento řádek přeskočíte, bude generování fungovat, ale znamená to i méně bezpečnosti.

Zakázání editování souborů


V případě, že více uživatelů s administrátorskými právy je také vhodné zakázat přímou editaci souborů z administrace, v tom případě přidejte na konec souboru wp-config.php tento řádek:

define('DISALLOW_FILE_EDIT', true);

Zakázání XMLRPC


Pokud k přístupu používáte pouze defaultní webové rozhraní je vhodné i zakázat XMLRPC - toto provedete přidáním následujícího řádku na konec souboru wp-config.php:

add_filter('xmlrpc_enabled', '__return_false');

Pluginy pro vyšší zabezpečení


Níže najdete několik užitečných pluginů, které zvýší zabezpečení vašeho webu. Osobně povětšinou používám kombinaci prvních dvou pluginů, ale pluginů s podobnou tématikou existuje daleko více.

Limit Login Attempts


Tento plugin umožní omezit počet přihlašovacích pokusů - to je užitečné pro bránění se tzv. brute force typu útoků.

Acunetix Secure WordPress


Plugin nabízí prozkoumání vaší instalace systému WordPress z hlediska zabezpečení. Po instalaci a aktivaci pluginu přejděte na stránku jeho nastavení a zaškrtněte následující možnosti:

  • Hide WordPress version for all users but administrators
  • Remove various meta tags generators from the blog's head tag for non-administrators.
  • Remove Really Simple Discovery meta tags from front-end
  • Remove Windows Live Writer meta tags from front-end
  • Disable error reporting (php + db) for all but administrators
  • Remove core update notifications from back-end for all but administrators
  • Remove plug-ins update notifications from back-end
  • Remove themes update notifications from back-end
  • Remove login error notifications from front-end
  • Hide admin notifications for non admins
  • Remove the version parameter from urls

Aktuální míru zabezpečení a případné chyby můžete prozkoumat v administraci na stránkách Secure WP -> Nástěnka (Dashboard) a Secure WP -> Scanner.

Wordfence Security


Wordfence Security je plugin nabízející lepší zabezpečení vašeho webu a zahrnuje firewall, aktuální statistiky provozu s geolokací a další vlastnosti.
U tohoto pluginu je velký rozdíl mezi neplacenou a placenou verzí - pokud si pořídíte placenou verzi je to dobrá náhrada za předchozí plugin v opačném případě je lepší použít Acunetix Secure WordPress.

Ostatní


Pokud chcete ještě lepší zabezpečení proti mailware a spamu můžete také použít placené služby jako jsou Akismet či Securi - obě jsou prověřené a nabízejí výbornou spolupráci se systémem WordPress.

Zdroje