Bash Create User Script

This is a very simple script to create users and set them up in a userdir enabled Apache environ.

#!/bin/bash
if [ "$#" -ne 1 ]; then
	echo "Usage: ./mkacct.sh <username>"
	exit;
else
	sudo useradd -m -s '/bin/bash' $1
	sudo chmod 711 "/home/$1"
	sudo mkdir "/home/$1/public_html"
	sudo chmod 755 "/home/$1/public_html"
	sudo chown "$1.$1" /home/$1/public_html
	sudo passwd $1
fi;

Screen Resolution - Web development

I have used the statcounter for several years to help me adjust page layouts for web development.

The mistake I have been making is that the browser does not usually have the entire screen resolution available.

Today I took some time checked the window dimensions on a Windows 7 laptop with a 1366x768 screen and several browsers.

Firefox

  • Full screen with menu and bookmark bar 1366x608
  • Windowed, full height x600

Internet Explorer

  • Full screen with menu, bookmark, DebugBar 1301x548
  • Windowed, full height x540

Chrome

  • Full screen 1366x667
  • Windowed, full height x639

These dimensions depend on the toolbars in use, etc, but they provided a very helpful reminder that 1366x768 screen resolution is not the same as a 1366x768 browser page.

In addition, the best way to test a page under Internet Explorer is to use Internet Explorer, and if you you need to test different versions (you do!), you can use IE or IETester (http://www.my-debugbar.com/wiki/IETester/HomePage). Sometimes there is simply no substitute for target machine and browser testing.

eZ Publish - Adding Bootstrap Glyphicons

If you are using Bootstrap with eZ Publish, you can add a custom tag to include glyphicons which will allow editors to add the icons into their content.

This is a simple implementation, it allows the user to enter the name of the icon they would like to use.

content.ini.append.php

<?php /* ini charset="utf-8"

[CustomTagSettings]
AvailableCustomTags[]=glyphicon
IsInline[glyphicon]=true

[glyphicon]
CustomAttributes[]
CustomAttributes[]=name

*/ ?>

The template HTML must match the Bootstrap version in use.

design/site/templates/content/datatype/view/ezxmltags/glyphicon.tpl

<!-- Choose the HTML for the tag based on the version of Bootstrap you are using -->
<span class="glyphicon glyphicon-{$name}"></span>

<!-- or -->

<i class="icon-{$name}"></i>

eZ Publish - Object Relation Attributes - Reckless Cleanup

This is NOT A FIX for the code, but if you are getting confusing results for queries due to relationships between object relation attributes which were deleted from content classes, you may use this query:

Backup your database first

This is not for the faint of heart

There are no warranties or other guarantees - use this at your own risk.

DELETE FROM ezcontentobject_link WHERE contentclassattribute_id != 0 AND NOT EXISTS (SELECT * FROM ezcontentclass_attribute WHERE ezcontentclass_attribute.id = ezcontentobject_link.contentclassattribute_id);

Twitter Application Auth Sample - PHP

This is a sample PHP code which can be used to get a Twitter OAuth token for use in making API calls.

It includes a trends available request that gets the list of countries for which Twitter trends are available.

Be sure to read the documentation at the link above. A given application can only have one token at any given time, so once established, the token should be stored and reused.


        $consumerKey = '-- YOUR CONSUMER KEY --';
        $consumerSecret = '-- YOUR CONSUMER SECRET --';
        $encodedKey = urlencode($consumerKey);
        $encodedSecret = urlencode($consumerSecret);
        $bearerTokenCredentials = $encodedKey.':'.$encodedSecret;
       
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/oauth2/token');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
        curl_setopt($ch, CURLOPT_HTTPHEADER,
                array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
                        'Authorization: Basic '.$base64BearerTokenCredentials));
        $result = curl_exec($ch);
        $error = curl_errno($ch);
        if ($error === 0) {
                $json = json_decode($result);
                curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/1.1/trends/available.json');
                curl_setopt($ch, CURLOPT_HTTPGET, true);
                curl_setopt($ch, CURLOPT_POST, false);
                curl_setopt($ch, CURLOPT_HTTPHEADER,
                                array('Authorization: Bearer '.$json->access_token));
                $result = curl_exec($ch);
                $error = curl_errno($ch);
                curl_close($ch);
                if ($error === 0) {
                        $json = json_decode($result);
                        $countries = array();
                        foreach ($json as $location) {
                                if ($location->placeType->name == 'Country') {
                                        $countries[$location->woeid] = $location->name;
                                }
                        }
                        asort($countries);
                }
        }