Skip to content

Instantly share code, notes, and snippets.

View alash3al's full-sized avatar

Mohammed Al Ashaal alash3al

View GitHub Profile
@alash3al
alash3al / simple-space-ship.html
Created November 25, 2015 11:43
just move+falling-balls animations
<!-- www.alash3al.xyz -->
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #000;
overflow: hidden;
}
@alash3al
alash3al / file-downloader-sample.go
Last active January 4, 2016 10:56
just for fun ;), i'm "www.alash3al.xyz"
package main
import(
"fmt"
"net/http"
"os"
"sync"
"io"
)
@alash3al
alash3al / downloadCurrent.js
Last active November 2, 2015 18:00
just run it in the console, and the browser will show you the download dialog
// copy & paste in the browser console "F12" and press ENTER
// then the browser will show you the download dialog
// this script makes use of HTML5 'download' attribute
// by Mohammed Al Ashaal <www.alash3al.xyz>
(function(){
dl = document.createElement("a")
dl.href = window.location
dl.download = ""
dl.click()
})()
@alash3al
alash3al / inspectUserLocation.php
Last active September 14, 2015 13:16
Extract the "most valid" ip-address from the client-request, then uses a `GEO-IP` service to fetch its information .
<?php
/*
* Extract the "most valid" ip-address from the client-request
* then uses a `GEO-IP` service to fetch its information .
*
* To extract the "most valid" ip-address, it loops over all http-headers
* from the client-request, then gets the ip that matches this pattern
* "^([0-9]+){3}\.([0-9]+){3}\.([0-9]+){3}\.([0-9]+){3}$"
* this is done becaouse each proxy server "may" send a http-header
* i.e: "HTTP_X_FORWARDED_FOR", "HTTP_VIA" ... etc .
@alash3al
alash3al / milliseconds.php
Created August 20, 2015 19:30
milliseconds - return current Unix timestamp with milliseconds for php just like javascript's Date.now()
<?php
/*
* Return current Unix timestamp with milliseconds
*
* @author Mohammed Al Ashaal <github/alash3al, fb/alash3al, tw/m7medalash3al>
* @return float "due to INT limitaions"
*/
public function milliseconds()
{
list($a, $b) = explode(' ', microtime());

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:

@alash3al
alash3al / smtp.php
Last active July 27, 2016 05:33
PHP mail() alternative, smtp()
<?php
/**
* Send a mail using smtp server
*
* @param array $options [from, to, server, tls, subject, message .. etc]
* @param array $headers for custome headers as key value pairs [key is case insensetive]
*
* @author Mohammed Al Ashaal <fb.com/alash3al, is.gd/alash3al, github.com/alash3al>
* @copyright (c) 2015, Mohammed Al Ashaal
@alash3al
alash3al / parse_str.js
Created February 20, 2015 21:22
Parse a string and split it into key value pairs, the php parse_str()
/**
* Parses the string into variables
*
* @param mixed $string
* @param mixed $equal
* @param mixed $separator
*
* @author Mohammed Al Ashaal <is.gd/alash3al>
* @version 1.0.0
*
@alash3al
alash3al / parse_url.js
Last active August 29, 2015 14:15
Parse a url and return its components, php parse_url() for javascript
/**
* Parse a url and return its components
*
* @param string $url
* @return Object
*
* @author Mohammed Al Ashaal <is.gd/alash3al>, inspired by PHP
* @version 1.0.0
*/
function parse_url($url)
@alash3al
alash3al / file2base64.js
Last active August 29, 2015 14:15
javascript file2base46, return an uploaded file as base64 encoded
/**
* File2Base64
*
* @param string file the path of the files
* @param string mim_type the type of the file e.g: 'image/png'
* @param callable callback the callback that handle the base64encoded string
*
* @author Mohammed Al Ashaal
* @version 1.0.0
*/