Skip to content

sql2graphite - TypeError: not enough arguments for format string

Just ran into following issue.

Traceback (most recent call last): File "/usr/local/bin/sql-to-graphite", line 11, in <module> sys.exit(main()) File "/usr/local/lib/python2.7/dist-packages/sql_to_graphite/__init__.py", line 55, in main get_executor(dsn), File "/usr/local/lib/python2.7/dist-packages/sql_to_graphite/__init__.py", line 25, in run data = map(executor, queries) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 942, in execute return self._execute_text(object, multiparams, params) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1104, in _execute_text statement, parameters File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context context) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1416, in _handle_dbapi_exception util.reraise(*exc_info) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 507, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 187, in execute query = query % tuple([db.literal(item) for item in args]) TypeError: not enough arguments for format string

Result is, that I've created a sql statement with a >>%<< inside. I need to escape it (transform it to >>%%<<) and all is fine.

Translate to de es fr it pt ja
Categories: coding
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 1 of 5, 2 Stimme(n) 940 hits

Running Contao 3.x version and upgrading from PHP 5.x to PHP 7 results in a 500 Status?

I had the joy to debug a not working contao system line by line.

Why line by line? Because there was no entry in any logs, even with "log all motherfucker"-php.ini values on.

After parsing the lines, I ended up into this error message.

Fatal error: Cannot use 'String' as class name as it is reserved in ... system/modules/core/library/Contao/String.php on line 28

Well, nice to know the error but where was this triggered? So another round with joy and I ended up with an extension, of course installed "by hand" which means not possible to update by the contao updater and this lovely line.

$this->import('String');

After I've changed that line to the following line, all the gizmos where working again.

$this->import('StringUtils');

So, what should you do when you where faced with a 500 Apache Status Code after a contao installation moved from an PHP 5.x runtime environment to a PHP 7.x runtime environment?

cd <project root> grep -ir "import('String');" *

Replace >>import('String');<< with >>import('StringUtil');<< and that is it.

But all would be better if you are not installing extensions by hand.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: , ,
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 1 of 5, 3 Stimme(n) 66 hits

>>Uncaught Bunny\Exception\ClientException: Broken pipe or closed connection.<< and how to solve it

We were running into this issue when our consumers or producers had nothing to do in a minute or less.

After searching the web, we found this issue ticket within the conversation.

Long story short, we could solve our problem by overwriting the default heartbeat with 30 seconds.

//this is an example but full blown configuration we are using
$client = new Client(
    [
        'heartbeat' => 30,
        'host'      => '127.0.0.1',
        'password'  => 'guest',
        'user'      => 'guest',
        'vhost'     => '/'
    ]
);

If you want to know more, you can read about rabbitmq networking here and about rabbitmq detecting dead tcp connections with heartbeat and tcp keepalives here

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry:
Vote for articles fresher than 7 days!
[0] 795 hits

Die KW 25/2018 im Link-Rückblick

Translate to de es fr it pt ja

Die KW 24/2018 im Link-Rückblick

Translate to de es fr it pt ja

Die KW 23/2018 im Link-Rückblick

Translate to de es fr it pt ja

Zend Framework Kickstart or quick start script available

I was so bored setting up a zend framework application after another that I've created a simple script.

Sharing is caring, so you can find it on github with the lovely repository name phpzendframework_kickstarter.

This repository provides you two scripts to quickly create a new application from scratch (like a breeze and blazing fast within seconds ;-)).

git clone https://github.com/bazzline/php_zend_framework_kickstarter
bash php_zend_framework_kickstarter/create_application /path/to/the/application

See it working and that is it. All mandatory parts are a bash.

Translate to de es fr it pt ja

teamviewer 13 requires a desktop environment or login with lightdm etc, with startx it won't work

I stumbled upon the following quote while trying to figure out why teamview is failing silently.

WARNING!

teamviewer 13 requires a desktop environment or login with lightdm etc, with startx it won't work, the staff of teamviewer confirmed, startx feature won't come in this year, it seems reverting back to teamviewer 12 is the only option for startx folks.

source

The teamviewer people are pretty in the we don't give a fuck mood. So you either have to install bloat-ware on your pc or stick to an older version of teamviewer.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: ,
Vote for articles fresher than 7 days!
[0] 1082 hits

Create php repository and want to quickly develop and test it everywhere? Add a fanzy start_docker_container.sh shell script to it!

I have to maintain a big bunch of repositories with different languages and different language versions.

After some iterations, I came up with a simple idea by using docker for it. To ease up things for any kind of users who have to deal with this code (even qa), the last iteration is to add a "startdockercontainer.sh" script into the repository.

Following an example script for a php repository.
Given is, that the script is located in <project_root>/bin.
Given is, that the docker file exists in <project_root>/data/docker.

#!/bin/bash
####
# Starts a fitting container and creates image if needed.
#
# @todo
####
# @author stev leibelt <[email protected]>
# @since 2018-05-09
####

PATH_OF_THIS_SCRIPT=$(cd $(dirname "$0"); pwd)
DOCKER_IMAGE_NAME='my_php_application'
DOCKER_IMAGE_TAG='0.1.0'

if ! (docker image ls | grep -q "${DOCKER_IMAGE_NAME}\s\+${DOCKER_IMAGE_TAG}")
then
    PATH_TO_THE_DOCKER_SOURCE=$(realpath ${PATH_OF_THIS_SCRIPT}/../data/docker)
    echo ":: We have to build the docker container first."
    echo ":: Please do the following steps first."
    #this is usefull since you have to copy some ssh keys to a path
    # or configure some files.

    read -p ":: Hit <ENTER> to continue."                                                                                                                       

    docker build -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${PATH_TO_THE_DOCKER_SOURCE}
fi

docker container run --mount type=bind,source="${PATH_OF_THIS_SCRIPT}"/..,target=/application -it ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} /bin/ash

And thats it. If the image is not found on the host, we have to setup things and build the image. Afterwards we start the container and mount the repository code into /applicationof the container.

Translate to de es fr it pt ja

Hint, never ever name a column "database_name" or "table_name" when you are using PHP's Propel

Defining a column name inside a table definition "database_name" or "table_name" will result in duplicated generated constant definition which will be an evil fail you have to debug for some minutes.

Super hint! Name them "the_database_name" and "the_table_name" :-D.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: , ,
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 1 of 5, 6 Stimme(n) 870 hits

quick one, output the license for each composer.json project within a root path

A quick one since I have to alligne all my open source packages to theSPDX License List. To list all available licenses from my root path, I've quickly written this one liner.

find . -maxdepth 2 -name composer.json -type f -exec grep -i -H license {} \;

Boy, to write this one liner without having a look to one man-page took me ... well, ages.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: , , ,
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 1 of 5, 3 Stimme(n) 1214 hits

"vendor/propel/propel1/generator/bin/phing.php: Permission denied"

I had to deal with an older project and wanted to update my database orm-code.

vendor/propel/propel1/generator/bin/phing.php: Permission denied

This error message is really general and it took me a while to find the solution. For whatever reason, the file "phing.php" has lost its execute flag. To fix this error, all you have to do is:

chmod +x vendor/propel/propel1/generator/bin/phing.php

This is it.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: ,
Vote for articles fresher than 7 days!
[-2] 649 hits

Ocramius ProxyManager or the great library that does the heavy lazy loading lifting for you

Within the next few lines, I will show you how you can use the proxy manager and how low the setup fee is compared to self written code.

The setup fee

Give is, that you have installed the ProxyManager with Composer. Than, create a script like the following (I will name it foo.php because I like it ;-)).

<?php
/**
 * @author stev leibelt <[email protected]>
 * @since 2017-12-12
 */

require_once __DIR__ . '/vendor/autoload.php';

use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\Configuration;

$configuration = new Configuration();
$configuration->setProxiesTargetDir(
    __DIR__ . '/../cache'
);

spl_autoload_register(
    $configuration->getProxyAutoloader()
);

class A
{
    /** @var mixed */
    private $foo;

    public function __construct(
        $foo
    ) {
        echo __METHOD__ . PHP_EOL;
        echo 'Something will take very long.' . PHP_EOL;
        sleep(5);
        $this->foo = $foo;
        echo 'Done.' . PHP_EOL;
    }

    public function __call($name, $arguments)
    {
        echo __METHOD__ . sprintf(
            'name: >>%s<<, list of arguments: >>%s<<.',
            $name,
            implode(
                ',',
                $arguments
            )
        ) . PHP_EOL;
    }

    public function foo()
    {
        echo $this->foo . PHP_EOL;
    }
}

class B extends A
{
    /** @var mixed */
    private $constructorFoo;

    /** @var bool */
    private $isNotInstantiated;

    public function __construct(
        $foo
    ) {
        echo __METHOD__ . PHP_EOL;
        echo 'Superfast.' . PHP_EOL;
        $this->constructorFoo       = $foo;
        $this->isNotInstantiated    = true;
        echo 'Done.' . PHP_EOL;
    }

    public function __call($name, $arguments)
    {
        $this->instantiateIfNeeded();

        parent::__call($name, $arguments); // TODO: Change the autogenerated stub
    }

    public function foo()
    {
        $this->instantiateIfNeeded();

        parent::foo(); // TODO: Change the autogenerated stub
    }

    private function instantiateIfNeeded()
    {
        if ($this->isNotInstantiated) {
            parent::__construct(
                $this->constructorFoo
            );

            $this->isNotInstantiated = false;
        }
    }
}

echo ':: Construct A' . PHP_EOL;
$a = new A('a');
echo ':: Construct B' . PHP_EOL;
$b = new B('b');
echo ':: Construct C' . PHP_EOL;
$factory = new LazyLoadingValueHolderFactory(
    $configuration
);
$c = $factory->createProxy(
    A::class,
    function (&amp; $wrappedObject, $proxy, $method, $parameters, &amp; $initializer) {
        $wrappedObject = new A('c'); // instantiation logic here
        $initializer   = null; // turning off further lazy initialization
    }
);

echo ':: Begin A' . PHP_EOL;
$a->foo();
$a->bar('foo', 'bar', 'baz');
echo ':: End A' . PHP_EOL;

echo ':: Begin B' . PHP_EOL;
$b->foo();
$b->bar('foo', 'bar', 'baz');
echo ':: End B' . PHP_EOL;

echo ':: Begin C' . PHP_EOL;
$c->foo();
$c->bar('foo', 'bar', 'baz');
echo ':: End C' . PHP_EOL;

And finally, execute it (clear && php foo.php).

What have we done - the explanation of the script

First, we are creating a class "A" that does some complicated stuff. Than, we are trying to implement our own lazy loading logic by creating a class "B". Afterwards we are instantiating A, B and A with the proxy manager. Finally, we are calling two methods for each instantiation.

When you execute the script, you quickly will figure out that the instantiation of $a is taking as long as expected while $b and $c are almost instantly there. At the end $b and $c will react the same.

Why should you use the proxy manager if you can archive the same stuff with "just some lines of code"? Because the proxy manager reduced your maintenance coast. If "A" would change, you would have need to extend or change "B" as well (e.g. A gets another method) while you don't have to touch any piece of code when using the proxy manager. Secondly, proxy manager is well tested and used. If you find an issue, you can fix it since the code is open source and do something good for the world - because sharing is caring.

Translate to de es fr it pt ja
Categories: coding
Defined tags for this entry: , , ,
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 2 of 5, 2 Stimme(n) 748 hits

Migrate all branches and tags to bitbucket/github/gitlab/other remote endpoint

To have a real world scenario think about the task to migrate from an existing private gitweb repository to bitbucket, with all tags and branches.

The solution simple und just needs some time if the repository is a bigger one.

First, you have to create an empty and new repository at bitbucket.

cd <path you want to do this action>
#the next step is just for safety reasons
mkdir <repository_name>
git clone --mirror [email protected]<your host>:<repository_name>.git .
git push --mirror [email protected]:<user_name>/<repository_name>

See how easy it is? Why not write a simple bash script?

#!/bin/bash
####
# @link https://artodeto.bazzline.net/archives/19519-Migrate-all-branches-and-tags-to-bitbucketgithubgitlabother-remote-endpoint.html
# @since 2017-11-06
# @author stev leibelt <[email protected]>
####

if [[ $# -lt 2 ]];
then
    echo ":: Invalid arguments provided."
    echo "   <command> \"<source repository url>\" \"<destination repository url>\""

    exit 1;
fi

DESTINATION_REPOSITORY_PATH="${2}"
SOURCE_REPOSITORY_PATH="${1}"
TEMPORARY_DIRECTORY="migrate_git_branch"

echo ":: Creating temporary directory."
mkdir "${TEMPORARY_DIRECTORY}"

cd "${TEMPORARY_DIRECTORY}"

echo ":: Cloning from source repository.".
git clone --mirror "${SOURCE_REPOSITORY_PATH}" .

echo ":: Pushing to destination repository."
git push --mirror "${DESTINATION_REPOSITORY_PATH}"

echo ":: You have to remove the following temporary directory if you want to."
echo "   "$(pwd)
Translate to de es fr it pt ja

MySQL and a known bug since 2003 about the auto_increment value

We detected a bug that is known since 2003.

The value of an auto increment column is set back to zero when you are having an empty table and restarting the MySQL DBMS. We run into this issue by using the auto increment value as a history id into a second table.

How can you work around this issue?

The easiest way is to order by id descending on the second table or to setup a "start up" shell script that calculates and sets the auto increment value.

Translate to de es fr it pt ja

Safe the open web - Please Tim Berners-Lee, kick out the EME proposal

Zak Ragoff has written an important article about Tim Berners-Lee decision he has to make right now.

Tim decided it the past to not include closed source binary blob software running in the browser without any control to lock down the web to something big companies can control. Was this the right decision? Well, see where HTML or javascript is used and answer the question on your own.

Big, DRM companies like Netflix, Apple, Google and Microsoft (they are just the vassals from MPAA and RIAA - America, fuck yeah! ;-)) are working on a standard called Encrypted Media Extension. This proposal is created to gain control over anything. You can start with Videos but the proposal is "open for change", so it is a no brainer to add images, audio, more or less even the whole HTML or Javascript under the "cover" of a DRM.

Beside the fact that big companies can decide who can see what, there is an even bigger issue rotating in my open source mind. I, as a user, have to run closed source binary code and all I can do is pray or blindly trust that this companies are not fooling around with me like mining all my data or that they are taking security serious. Well, call me blinded by the past, but this never happens on close source software.

Please Tim, do it like Linus has done it with NVidia and give them a nice "I don't care" kick in their buts.

Translate to de es fr it pt ja

Zend Framework 2 - Lazy Factory - Kickstarter (for ZF 2.4)

No blabla, just how you do it with zend framework 2.4.

#add following line to your composer.json
"ocramius/proxy-manager": "1.0.*",

composer update

#add following lines to your module.config.php
'lazy_services' => [
    'class_map' => [
        \My\Class::class => \My\Class::class
    ]
],
'service_manager' => [
    'delegators' => [
        \My\Class::class => [
            \Zend\ServiceManager\Proxy\LazyServiceFactory::class
        ]
    ],
    'factories' => [
        \My\Class::class => \My\ClassFactory::class,
        \Zend\ServiceManager\Proxy\LazyServiceFactory::class => \Zend\ServiceManager\Proxy\LazyServiceFactoryFactory::class
    ]
]

Thats it.

Useful links are a gist from a closed issue and somehow an official howto (maybe working with zend framework greater 2.4).

Translate to de es fr it pt ja

simple bash function to prefix any given command with sudo if needed

The title of this entry tells it all. I've create a simple bash function to prefix any given command expression with sudo if needed. If needed means, if you are not root. It is totally simple but to be true, it took me time to use my bash skills to write it. Imagine you now how to draw a cloud, the sun, a tree and a house and once you figure out how to concatenate all of that elements to draw a picture for your parents ;-).

if [[ $# -lt 1 ]];
then
    echo "Invalid number of arguments provided"
    echo "${FUNCNAME[0]} <command to execute>"
    return 1
fi

if [[ $(whoami) == "root" ]];
then
    [email protected]
else
    sudo [email protected]
fi

Looks like Chuck Norris is using github right now. Github is down, otherwise I would add a link to the fitting repository commit. Github is back online, here is the promised link to the commit.

Übersetze nach en fr

serendipity command line update released

I am happy to announce the initial and 1.0.0 of the serendipity command line update script. It is designed to do the boring work of updating against the latest release. The workflow is dead simple.

  • fetch latest version
  • check if latest version is installed
  • make a backup of the existing installation
  • update

Enjoy using it. If you find an error, feel free to open an issue or a pull request.

Translate to de es fr it pt ja

Vim 8.0 released

This the first major Vim release in ten years. There are interesting new features, many small improvements and lots of bug fixes.

Among the new features are:
- Asynchronous I/O support, channels, JSON
- Jobs
- Timers
- Partials, Lambdas and Closures
- Packages
- New style testing
- Viminfo merged by timestamp
- GTK+ 3 support
- MS-Windows DirectX support
[...]

Quelle

Translate to de es fr it pt ja

Kirigami official released

Das KDE-Framework Kirigami steht in einer ersten Veröffentlichung bereit, um Qt-Entwickler bei der Erstellung konvergenter Apps für Desktop und Mobilgeräte plattformübergreifend zu unterstützen.

Quelle
[...]
Kirigami currently officially supports Android, Desktop GNU/Linux (both X11 and Wayland), Windows, and the upcoming Plasma Mobile. iOS support is currently in an experimental stage, support for Ubuntu Touch is being worked on. The plan is to eventually become part of KDE Frameworks 5, but is currently released standalone in KDE Extragear. Since it is aimed to be a Tier 1 framework, it has no other dependencies apart from Qt, and therefore will not increase your application’s size any more than necessary. [...]

Quelle
kirigami design principles, ui patterns and styleguide
kirigami api documentation

Translate to de es fr it pt ja