Skip to content

Instantly share code, notes, and snippets.

View sc0ttkclark's full-sized avatar
🍕
Working hard reviewing and deploying code

Scott Kingsley Clark sc0ttkclark

🍕
Working hard reviewing and deploying code
View GitHub Profile
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
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:

@mnem
mnem / git_fetch_pull_all_subfolders.sh
Created December 6, 2011 14:35
Simple bash script for fetching and pulling all repos in the executed folder to the latest of the branch they are on
#!/bin/bash
################
# Uncomment if you want the script to always use the scripts
# directory as the folder to look through
#REPOSITORIES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPOSITORIES=`pwd`
IFS=$'\n'
@knu
knu / gist:111055
Created May 13, 2009 14:38
How to mass-rename tags and push them with Git
# Rename tags named foo-bar-#.#.# to v#.#.# and push the tag changes
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
@sc0ttkclark
sc0ttkclark / 0-README.md
Last active March 3, 2024 09:22
PhpStorm.app (Toolbox) Mac integration with Tower.app for diff and merge

Toolbox PhpStorm.app Mac integration with Tower.app for diff and merge

How to use this

  1. Add CompareTools.plist and phpstorm-toolbox.sh files in the ~/Library/Application Support/com.fournova.Tower3/CompareTools/ directory. You may need to mkdir ~/Library/Application\ Support/com.fournova.Tower3/CompareTools if the folder does not already exist
  2. Update the phpstorm-toolbox.sh to use your username for the /Users/yourusername/ path and the correct version number (PhpStorm > About > Build #PS-XXX.XXXXX.XX where XXX.XXXXX.XX is the version number to use).
  3. Run chmod +x ~/Library/Application\ Support/com.fournova.Tower3/CompareTools/phpstorm-toolbox.sh
  4. Go into Tower.app Preference > Git Config > Select "PhpStorm" for "Diff tool" and "Compare tool", you can optionally enable "Perform directory diff"
@Thinkscape
Thinkscape / gist:1136563
Created August 10, 2011 11:05
Very simple performance comparison - arrays vs objects (PHP 5.3.6)
# php -v
PHP 5.3.6 (cli) (built: Mar 17 2011 20:58:15)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
655040
# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $o = new ArrayObject; $o->name = "Adam"; $o->age = 35; $s[] = $o;} echo memory_get_peak_usage(); ' | php
887984
@sc0ttkclark
sc0ttkclark / 0-README.md
Last active December 1, 2023 10:12
PhpStorm.app (Standalone) Mac integration with Tower.app for diff and merge - https://youtrack.jetbrains.com/issue/WI-26090

PhpStorm.app (Standalone) Mac integration with Tower.app for diff and merge

How to use this

  1. Add CompareTools.plist and phpstorm.sh files in the ~/Library/Application Support/com.fournova.Tower3/CompareTools/ directory. You may need to mkdir ~/Library/Application\ Support/com.fournova.Tower3/CompareTools if the folder does not already exist
  2. Run chmod +x ~/Library/Application\ Support/com.fournova.Tower3/CompareTools/phpstorm.sh
  3. Go into Tower.app Preference > Git Config > Select "PhpStorm" for "Diff tool" and "Compare tool", you can optionally enable "Perform directory diff"

Other variations

<?php
/* Sample Register Helper fields
Register Helper Add On (https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/)
Add this to your customization plugin for PMPro Customizations: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
or
@nkt
nkt / Results.md
Last active September 27, 2023 08:24
ReactPHP vs Node.js

wrk -t4 -c400 -d10s http://127.0.0.1:1337/

PHP

Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
 Latency 7.02ms 6.94ms 82.86ms 85.27%
@jtsternberg
jtsternberg / README.md
Last active June 8, 2023 16:53
Create a theme options page with CMB2
@sc0ttkclark
sc0ttkclark / my-custom-pods-block-1.php
Last active December 4, 2022 10:21
Pods Blocks API examples for register a custom block type or a custom block collection. Screencast: https://share.skc.dev/12uJvZL1
<?php
/**
* Plugin Name: My Custom Pods Block
* Plugin URI: https://gist.github.com/sc0ttkclark/73930f5a4b8f093d4c0d500bdb1eca5b
* Description: Custom block built using the Pods Block PHP API. No Javascript needed!
* Author Name: Scott Kingsley Clark
* Author URI: https://skc.dev/
*/
/**