Skip to content

Instantly share code, notes, and snippets.

View adammbalogh's full-sized avatar

Adam Balogh adammbalogh

View GitHub Profile
@nikic
nikic / objects_arrays.md
Last active September 24, 2024 14:51
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@spacecowb0y
spacecowb0y / Vagrantfile
Last active January 19, 2017 00:09
Vagrant config to setup a rvm + ruby + rails + passenger + nginx + mysql.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.hostname = "ruby-dev-server"
config.vm.provision :shell, path: "install.sh"

Jessica Kerr "Functional Principles for Object Oriented Development"

Principles

  • Data In, Data Out: (Most) Functions should only depend on its parameters and should do nothing but produce output.
    • Testable: No need to setup extern dependencies or tear them down after testing
    • Easier to understand: Only local context dependent
    • A good "data in, data out" function should:
      • don't access global state
      • don't modify the input
      • don't bother the rest of the world
  • Inmutability
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@rosstuck
rosstuck / EventGenerator.php
Created March 20, 2014 16:04
Simple EventGenerator trait that you might use with domain events
<?php
trait EventGenerator
{
protected $pendingEvents = array();
protected function raise($event)
{
$this->pendingEvents[] = $event;
}
@danvine
danvine / preview.sh
Created April 19, 2014 15:20
Simple bash workflow script for managing ever growing api documented using blueprintapi.org
#!/usr/bin/env bash
# Be sure to install the apiary gem; https://github.com/apiaryio/apiary-client
# gem install apiary
# You'll need to get a token here; https://login.apiary.io/tokens
APIARY_API_KEY=
# Your apiname here; docs.$APINAME.apiary.io
APINAME=
@alexbilbie
alexbilbie / README.md
Last active August 29, 2015 14:11
StackPHP basic API versioned routes example

Setup

$ composer install
$ php -S localhost:8000

Version 1.0 call:

curl -X "GET" "http://localhost:8000/index.php/foo" -H "Accept: 1.0"