Skip to content

Instantly share code, notes, and snippets.

View mehdichaouch's full-sized avatar
🤖
Happiness Developer

Mehdi Chaouch mehdichaouch

🤖
Happiness Developer
View GitHub Profile
@nikic
nikic / objects_arrays.md
Last active April 24, 2025 06:50
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:

@jbleuzen
jbleuzen / pre-commit.sh
Created February 25, 2013 09:28
Quick and dirty pre-commit for git
### pre-commit.sh
# Store git index status
git stash -q --keep-index
PWD=`pwd`
$PWD/bin/run_tests.sh
# Store tests result
RESULT=$?
function run()
{
// Récupération des objets "Gamepad" connectés
var gamepads = navigator.getGamepads();
for (var i = 0, c = gamepads.length; i < c; ++i)
{
var pad = gamepads[i];
pad.buttons; // Array de boutons
@adamjohnson
adamjohnson / publickey-git-error.markdown
Last active January 30, 2025 00:44
Fix "Permission denied (publickey)" error when pushing with Git

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "[email protected]". Th
@lionelgaillard
lionelgaillard / gist:5785508
Last active December 18, 2015 12:48
Automatically dump your MySQL database on commit
#!/bin/bash
DBUSER="dbuser"
DBPASS="dbpass"
DB="dbname"
DUMPPATH="."
mysqldump -u $DBUSER -p$DBPASS $DB > $DUMPPATH/$DB.sql
git add $DUMPPATH/$DB.sql
@jnaskali
jnaskali / new_gist_file
Created June 28, 2013 15:22
Google spreadsheet row update timestamp script
// Originally from http://webapps.stackexchange.com/questions/37408/google-docs-auto-updating-column-showing-last-modify-date
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var r = s.getActiveCell();
if( r.getColumn() != 2 ) { //checks the column
var row = r.getRow();
var time = new Date();
time = Utilities.formatDate(time, "GMT+02:00", "d.M.y, h:m");
SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
};
@SeanCannon
SeanCannon / array_flatten.php
Last active October 28, 2024 18:01
PHP array_flatten() function. Convert a multi-dimensional array into a single-dimensional array.
<?php
/**
* Convert a multi-dimensional array into a single-dimensional array.
* @author Sean Cannon, LitmusBox.com | [email protected]
* @param array $array The multi-dimensional array.
* @return array
*/
function array_flatten($array) {
if (!is_array($array)) {
@hofmannsven
hofmannsven / README.md
Last active April 1, 2025 06:51
Git CLI Cheatsheet
@robwilkerson
robwilkerson / vagrant-provision-php.ini.sh
Created November 5, 2013 01:54
Modify php.ini to turn on errors for debugging and disable the short open tag.
# Show PHP errors
sed -i -r -e 's/short_open_tag = On/short_open_tag = Off/g' /etc/php5/fpm/php.ini
sed -i -r -e 's/error_reporting = E_ALL & ~E_DEPRECATED/error_reporting = E_ALL | E_STRICT/g' /etc/php5/fpm/php.ini
sed -i -r -e 's/display_errors = Off/display_errors = On/g' /etc/php5/fpm/php.ini
@akeemw
akeemw / prepare-commit-msg
Last active January 26, 2016 15:53 — forked from shytikov/commit-msg
Usage: Add "prepare-commit-msg" to your repos ".git/hooks"
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# Unless we are on the master or develop branch.
#
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
TEXT=$(cat "$1" | sed '/^#.*/d')