Premature Optimization with Ilia Alshanetsky @ Dutch PHP Conference | Notes

-> demonstrate the user concept with an imperfect solution that does the job, optimize along the way
-> tune the right portions of the application, not over-engineer from the very beginning
—> scale the scope to the nature of the problem

-> simplify
—> less code does not mean that it’s faster
—> PHP doubled the # of LOC in a few years but it’s faster, not slower :-)

-> hardware [HW]
—> since it’s cheaper, maybe throwing HW at it this might get it faster & buy you time to find the solution to the problem
—> SW development time to optimize might be more expensive
—> CPU bottlenecks & RAM issues are easier to solve lately
—> drives, the well-known bottleneck, have also received SSD [measurements show it's a lot better]

-> HW caveat
—> might only temporarily solve issues
—> DB saturation
—> non-scalable code [this is NOT the same as high-performing code]
—> network bottlenecks [latency]
—> extremely low # of sessions per server [Smarty: 50 reqs/sec]

-> optimization
—> start by trying to make the code faster without modifying a LOC [this way you avoid introducing new bugs & QA cycle, easier deployment]

-> how PHP works in 30 secs
—> each require/include triggers compile+execute
—> compilation is expensive
—> opcode cache [if the file is not changed, you get it from the cache]
—> APC vs Zend’s solution vs X-Cache

-> in-memory cache
—> do the PHP sessions in memcache instead of filesystem

-> ways of caching data
—> complete page [caching proxy, e.g. Squid; pre-generate; on-demand]
—> cache the parts that are really slowing down the page [example using memcache for SQL results caching]
—> partial caching of code [example using memcache for results of a function call; cache TTL of 1h]

-> output buffering
—> Apache’s SendBufferSize should be the same as PageSize
—> tcp_wmem | affects everything on tcp-ip
—> tcp_mem |

-> use profiling to understand the real bottleneck in the code, without the “educated assumptions”
—> Xdebug & XHProf [last one comes from Facebook]
—> Kcachegrind

-> code that generates notices / errors is slowed down by them, because resources are allocated for them, even if you don’t see them

QQA in Software Projects with Sebastian Bergmann @ Dutch PHP Conference | Part 2 | Notes

-> Continuous Integration
—> build automation [write build script to get latest code version; run tools to detect problems; run unit tests & publish these results; package; deploy]
—> summary of the tools enumerated below can be found in this presentation: http://www.slideshare.net/sebastian_bergmann/continuous-integration-of-php-projects-4354597

-> static code analysis
—> LOC [= lines of code] metric
—> CLOC [= comment LOC]
—> NCLOC [= non-comment LOC]
—> ELOC [= executable LOC]
—> welcome to phploc [ http://github.com/sebastianbergmann/phploc ]
—> demo phploc directly on PHPUnit

-> code duplication
—> totally identical LOC
—> phptok some_file.php
—> phpcpd /path/to/your/project [ the copy/paste detector >:) ]

-> code complexity
—> cyclomatic complexity [count the # of branching points]
—> NPath complexity [count the # of possible execution paths]

-> phpcs
—> the code sniffer :-)
—> start here: http://github.com/sebastianbergmann/phpcs-sebastian
—> allows for defining own sniffs; demo sniff list

-> pdepend
—> static analysis of PHP code
—> helps identify parts of app. which should be refactored

-> build automation tools
—> ant, make, phing, rake
—> delve a bit into ant features
—> small ant config to pull from git, run phpunit, run some of the static code analysis tools in parallel
—> demo ant run for an existing project, and get a glimpse at the reports of the static code analysis tools output

-> continuous integration server options
—> phpUnderControl: customized CruiseControl
—> Hudson [Java-based, open-source]
—> Bamboo -> the Atlassian way of doing it, still Java-based
—> Arbit -> an alpha release, PHP-based solution
—> demo: http://ci.thephp.cc/

QA in Software Projects with Sebastian Bergmann @ Dutch PHP Conference | Part 1 | Notes

-> what is SW quality?
-> the BankAccount example
—> PHPUnit 3.4.12 is used for these examples
—> CLI run using phpunit BankAccountTest
—> phpunit –testdox BankAccountTest —> used for instance to present functionality summary before the actual coding
—> setUp()
—> Q&A —> use @expectedException annotation instead of the try/catch block inside the method body
—> Q&A —> use 1 test method for each test, not stuff everything in 1 method
—> PHPUnit 4 might use the traits feature of PHP, as opposed to the JUnit approach

-> organizing tests
—> tree structure, mirroring the actual code organization
—> using group annotation you can run only specific tests
—> phpunit –filter testFreezingAnObjectWorks Tests [ excludes a specific slow test ]

-> automated bugfixes project
—> write a test to repro the bug
—> use genetic programming to issue the patch that fixes the bug

-> SW testing pyramid /// Categories of (Unit) Tests
—> bottom level: unit tests
—> upper level: functional tests [this is not the functional testing w/ Selenium!] [it's testing blocks of functionality instead units] [do the interfaces between classes abide their contracts?]
—> top-level: End-to-End Test [these are the expensive ones ... running a full Selenium arrangement across all browsers took more than 24h]

-> minimalistic MVC implementation
—> used to demo unit testing for more than just the Model
—> assertAttributeEmpty() and assertAttributeContains() work with public / private / private class members
—> @depends is a simple way of declaring dependencies between tests
—> sample of refactoring so that there’s no need to assertAttribute*() for protected / private members

-> PHPUnit Best Practices
—> use an XML configuration file
—> look inside the cwd for a phpunit.xml [fallback to phpunit.xml.dist]
—> generate code coverage report, showing also dead code
—> new beta thingy: code coverage distribution report + class complexity

Wireshark not listing interfaces on Mac OS X

It’s a permission problem, please check here for the solution.

How you should not do a banner

Don’t show a picture of one product and the name of another. It’s just so…

HTC_HeroOrSprint

Now don’t get me wrong, I know they’re both called Hero. But one’s also a Sprint.

Do your research before stuffing items in Photoshop and deliver your project. And do have a second pair of eyes around you before you push this live.

Migrating phone book from Nokia XpressMusic to Android using a Mac

Looks complicated, huh? Especially when people say there’s no real Mac-to-Android sync software.

But we’re all tekkies here, we solve stuff, and don’t complain about it ;-) And we’re using free software to do it, yummy!

All you need is PhoneDirector to get your Nokia agenda on the Mac. Just install it and follow the instructions, you should be just fine. After you get all this, export them into a .vcf file, we’ll need it in a moment.

Now, to get this info in the Android is really a piece of cake. Go to the Contacts settings in Gmail and import the .vcf file you generated with PhoneDirector. Then go to your Android phone and sync your contacts. Ta-da! Welcome to the Google world!

NB: if you’re having a hard time finding the Contacts in the Gmail app, like I did, look immediately under your labels list.

The above steps weren’t good for you? Then you might need to take a look at this.

Mac development environment, the easy way

So, you want to use that Apple machine for developing websites. That’s pretty easy to setup, here are some guidelines you can use in order to create the basic environment for creating great web applications.

  1. MAMP
    • even though you already have Apache and PHP installed (oh, and Ruby as well), you also need the mySQL; basically it’s not that trivial to add the popular DB to the mix, and this is where MAMP comes into play: it provides the sqlite for quick and easy part, and also mySQL for the more complicated items
    • it also includes the phpMyAdmin in case you don’t want to use  more powerful tool
    • download it from the official page or from sourceforge
    • installation is pretty straightforward, but do take a look at the last section here
    • start the MAMP application
    • the path to your webroot is /Applications/MAMP/htdocs
  2. Editor
    1. Aptana is for heavy users
      • since it’s based on Eclipse, you’ll quickly find your way around
      • download it from here and use the online documentation in case you run into trouble
    2. Smultron is a light-weight, extremely capable and configurable editor
      • please don’t get fooled by the looks of it, take your time and explore it; it’s a valuable companion
      • the SourceForge page of the Smultron project
      • get directly the improved interface, a patch which appeared on the internet because many users complained about the icons
  3. a developer’s file managermuCommander
    • usually you’ll find yourself limited by the multitude of Finder windows, so you’ll miss the MidnightCommander / TotalCommander / etc. software; meet muCommander; since it runs on amy platform, you might just take it with you on your other environments and modernize the old mc
    • here’s an alternative download source

That should be it. Congratulations!

Are you using something else to this mix? Tell us all about it.

How to restore your Mac settings

If you installed a program which took the horrible approach of rewriting your .profile settings file and you discover you don’t have access to the shortcuts from your terminal anymore, here’s how to fix it:

  • open a terminal window and make sure you navigate to the home directory
  • cd ~
  • open your profile settings using the full path to your editor (I use nano):
  • /usr/bin/nano .profile
  • make sure your PATH setting contains at least the following information:
  • export PATH=/usr/bin:/bin:
  • make the shell reload your profile
  • . ./.profile

Now we’re talking! You can ls and sudo again!

Wget: filename too long


wget -O short_name.ext "your URL"

;-)

How to change your layout in Android landscape / portrait mode

In the res folder we are used to having a layout folder, in which we keep the XML files which describe our application’s layouts. This trick will show you how to improve the view in landscape or portrait mode, whichever you might need.

How do I quickly change my emulator from portrait to landscape and viceversa?

Use Ctrl + F11 to test around.

Can I only improve the layout and use no extra code?

The short answer is yes, definitely.

The layouts in /res/layout are applied to both portrait and landscape, unless you specify otherwise. Let’s assume we have /res/layout/home.xml for our homepage and we want it to look differently in the 2 layout types.

  1. create folder /res/layout-land (here you will keep your landscape adjusted layouts)
  2. copy home.xml there
  3. make necessary changes to it
  4. run the application in the emulator and test it using the Ctrl + F11 combination