Skip to content

Instantly share code, notes, and snippets.

View srgoogleguy's full-sized avatar

Sherif Ramadan srgoogleguy

View GitHub Profile
@srgoogleguy
srgoogleguy / how-to-learn.md
Created November 23, 2017 16:08
Learning How to Learn In the First Place

Remember that engineering is work, and no document will substitute for your own thinking, learning and experimentation.

How to Learn in the First Place

  1. Play with something.
  2. Read the documentation on it.
  3. Play with it some more.
  4. Read documentation again.
  5. Play with it some more.
@srgoogleguy
srgoogleguy / array-visualization.md
Last active April 19, 2023 06:32
Array Visualizations in PHP

Visualizing Array Operations in PHP

It's important to recognize that in PHP an array does not always behave like a traditional array. It's actually more representative of an ordered hashmap. Thus it maintains order, but consists of key/value pairs. A key, in a PHP array, is always unique, but can be either an integer or a string. If the string key can be cast to an integer then PHP will carry out this operation implicitly. Also, array keys do not determine the order of elements in a PHP array.

With this in mind, we can better understand how different operations, like diff, intersect, union, and merge, would be carried out on a native PHP array. Some of these operations rely on the array keys and others on the values in the array.


Table of Contents

Month, Year Standard deviations from previous month Standard deviation for the year
Jan, 2009 0.85048380530504 758.39186587293
Feb, 2009 0.17141534060412 758.39186587293
Mar, 2009 0.17668965877655 758.39186587293
Apr, 2009 0.088344829388276 758.39186587293
May, 2009 0.28085744268213 758.39186587293
Jun, 2009 0.52347607861411 758.39186587293
Jul, 2009 0.60127227165752 758.39186587293
Aug, 2009 0.2149284655267 758.39186587293
Sep, 2009 0.097574886190036 758.39186587293
@srgoogleguy
srgoogleguy / so-questions-tagged-php.csv
Created September 11, 2016 15:49
StackOverflow Questions [tagged php] By Month/Year
Month Year questions
Aug '08 162
Sep '08 492
Oct '08 623
Nov '08 507
Dec '08 481
Jan '09 645
Feb '09 775
Mar '09 909
Apr '09 976
@srgoogleguy
srgoogleguy / Classes.md
Last active April 30, 2021 14:52
PHP OOP
@srgoogleguy
srgoogleguy / http.md
Created October 31, 2014 02:46
PHP Http Interface Draft

Http Interface

The Http interface SHOULD define the standardized methods and constants upheld by implementing classes. All classes should be obligated to implement such methods and constants, but MAY NOT be limited to only these methods or constants.

The Interface Definition

abstract class HttpMessage
{
    protected $headers = array();

protected $body = "";

@srgoogleguy
srgoogleguy / time.php
Last active August 29, 2015 14:04
Time Spec
<?php
/**
* Translate a clock formatted string into a sum of seconds
* e.g. toSec("3:20") == 200
*/
function toSec($clock) {
$eq = array(1, 60, 3600, 86400);
$seconds = 0;
$parts = explode(':', $clock, count($eq));
$parts = array_reverse($parts);
#!/usr/local/bin/php
<?php
/**
* Keypad input over STDIN (using non-blocking I/O)
*/
$base = event_base_new();
$input = event_new();
googleguy@googleguy-pc:~/aa/test$ php -dvld.active=1 /tmp/static.php
Finding entry points
Branch analysis from position: 0
Return found
filename: /tmp/static.php
function name: (null)
number of ops: 9
compiled vars: none
line # * op fetch ext return operands
---------------------------------------------------------------------------------
@srgoogleguy
srgoogleguy / ref_info.c
Last active September 23, 2016 03:06
Implementation for a PHP function to find out which variables a given variable is currently referencing or referenced by. This function simply compares the zval pointer by iterating the active symbol table as opposed to simply checking the is_ref property of the zval to tell that it's a reference. This means two-way reference detection is possible.
/**
* Find which variables in the current scope reference which other variables.
*
* mixed ref_info ( string $variable_name )
* - Returns an associative array of variable names that are references of the supplied varriable name argument.
* Returns false on failure.
*/
PHP_FUNCTION(ref_info)
{
char *str;