Just read that I am not a TYPO3 core member any more. At least, I know it now.
Dmitry Dulepov
Being smart and efficient. Building life for the greater good.
May 13, 2013
Mar 19, 2013
A PHP client for TYPO3 TER
A useful piece of software from Elmar Hinz: a command line utility for TER, which can upload TYPO3 CMS extensions to TER and do many more, which you cannot do in the TYPO3 Extension Manager.
Get it here.
Get it here.
How to calculate 1+1 using the “nice code™”
use SimplePHPEasyPlus\Number\NumberCollection; use SimplePHPEasyPlus\Number\SimpleNumber; use SimplePHPEasyPlus\Number\CollectionItemNumberProxy; use SimplePHPEasyPlus\Parser\SimpleNumberStringParser; use SimplePHPEasyPlus\Iterator\CallbackIterator; use SimplePHPEasyPlus\Operator\AdditionOperator; use SimplePHPEasyPlus\Operation\ArithmeticOperation; use SimplePHPEasyPlus\Operation\OperationStream; use SimplePHPEasyPlus\Engine; use SimplePHPEasyPlus\Calcul\Calcul; use SimplePHPEasyPlus\Calcul\CalculRunner; $numberCollection = new NumberCollection(); $numberParser = new SimpleNumberStringParser(); $firstParsedNumber = $numberParser->parse('1'); $firstNumber = new SimpleNumber($firstParsedNumber); $firstNumberProxy = new CollectionItemNumberProxy($firstNumber); $numberCollection->add($firstNumberProxy); $secondParsedNumber = $numberParser->parse('1'); $secondNumber = new SimpleNumber($secondParsedNumber); $secondNumberProxy = new CollectionItemNumberProxy($secondNumber); $numberCollection->add($secondNumberProxy); $addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber'); $operation = new ArithmeticOperation($addition); $engine = new Engine($operation); $calcul = new Calcul($engine, $numberCollection); $runner = new CalculRunner(); $runner->run($calcul); $result = $calcul->getResult(); $numericResult = $result->getValue(); // 2
Example from https://github.com/Herzult/SimplePHPEasyPlus, thanks to Mathias Schreiber for the link :)
Conclusions? Do not overdo it. Simplicity will save the world. Just do a "1+1", not the framework for calculating it.
Mar 11, 2013
Bad coding
Never code like this:
function hasContentElements($pageId) {
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',
'pages', 'uid=' . $pageId ...);
return $rows;
}
function processContentElements($contentElements) {
foreach ($contentElements as $contentElement) {
...
}
}
$hasContentElements = hasContentElements($pageId);
if ($hasContentElements) {
processContentElements($hasContentElements);
}
Why is this bad? Because:
function hasContentElements($pageId) {
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',
'pages', 'uid=' . $pageId ...);
return $rows;
}
function processContentElements($contentElements) {
foreach ($contentElements as $contentElement) {
...
}
}
$hasContentElements = hasContentElements($pageId);
if ($hasContentElements) {
processContentElements($hasContentElements);
}
Why is this bad? Because:
- Function name hasContentElements suggests that it only checks that the page has content elements. It should not retrieve them. Imagine if there are 100 elements on the page. How much memory would it take just for a simple check like that?
- The variable is named improperly too. "has" means a boolean value!
- Using the variable with such name is misleading here. Unless you see and remember what the function does, you can make wrong assumptions about the logic of the processContentElements function.
Showing the current Git branch in a shell prompt
The following commands in ~/.bash_profile will show you on what Git branch you are and if there are dirty files there:
source /opt/local/share/doc/git-core/contrib/completion/git-completion.bash
source /opt/local/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\h:\w \[\033[1;36m\]$(__git_ps1 "[%s] ")\[\033[1;37m\]\$ '
This will show the branch in the cyan color and only in the directory, where you checked out the project. If there are dirty files, it will show an asterisk after the branch name.
Example:
Atlas:~/Projects/TYPO3/TYPO3_6-0 [issue_46000 *] $
source /opt/local/share/doc/git-core/contrib/completion/git-completion.bash
source /opt/local/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\h:\w \[\033[1;36m\]$(__git_ps1 "[%s] ")\[\033[1;37m\]\$ '
This will show the branch in the cyan color and only in the directory, where you checked out the project. If there are dirty files, it will show an asterisk after the branch name.
Example:
Atlas:~/Projects/TYPO3/TYPO3_6-0 [issue_46000 *] $
Mar 4, 2013
Quote #1
"There's nothing of any importance in life – except how well you do your work. Nothing. Only that. Whatever else you are, will come from that. It's the only measure of human value."
Francisco d'Anconia
Mar 1, 2013
Feb 28, 2013
Blah-blah #3
One wife tells her husband (a programmer): "Go to the shop and buy sausages. If there are eggs, buy ten". The programmer comes to the shop, dialog:
- Do you have eggs?
- Yes.
- Than give me ten sausages.
Yep. We really think like that, dear wives :)
Feb 27, 2013
Speeding up OpenOffice/LibreOffice
I had major problems with OpenOffice and its clone: LibreOffice. When I launched OpenOffice, it took about a minute for it to start. With LibreOffice the start was fast but opening each document took about 15 seconds of waiting.
I took OS X Activity Monitor and found that both apps spend all this time waiting in a call to gethostbyname. The call before that was a call to get the name of the local host. So both apps first tried to get the name of the local host and than to resolve its IP address and that did not work well.
I took OS X Activity Monitor and found that both apps spend all this time waiting in a call to gethostbyname. The call before that was a call to get the name of the local host. So both apps first tried to get the name of the local host and than to resolve its IP address and that did not work well.
Feb 26, 2013
Subscribe to:
Posts (Atom)