Skip to content

Instantly share code, notes, and snippets.

@stevenwadejr
stevenwadejr / wtf.php
Created May 15, 2019 15:02
WTF PHP Array Initialization
<?php
$arr_1 = ['foo'];
$arr_2[] = 'foo';
var_dump(
$arr_1,
$arr_2
);
@stevenwadejr
stevenwadejr / blocking.php
Created June 28, 2018 17:39
Async Guzzle
<?php
require_once 'vendor/autoload.php';
function client()
{
static $client;
$client = $client ?? new GuzzleHttp\Client;
return $client;
}
@stevenwadejr
stevenwadejr / amphp.php
Last active May 8, 2018 13:56
HTTP Coroutines
<?php
function makeRequest(int $delay)
{
$client = new Amp\Artax\DefaultClient;
echo "Making request [delay = $delay]\n";
$response = yield $client->request('https://mockbin.org/delay/' . $delay);
echo "Response received [delay = $delay]\n";
@stevenwadejr
stevenwadejr / upstate.php
Created January 3, 2018 16:46
This is the very first PHP script I ever wrote (circa 2007)
<?php
$hostname = "localhost";
$db_user = "swade_steven";
$db_password = "yeahman";
$db_table = "upstate_show";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db("swade_information");
@stevenwadejr
stevenwadejr / foreach-list.php
Created June 27, 2017 20:44
Using `list()` inside of a `foreach` loop
<?php
$identifiers = [
['contact', 1],
['company', 2],
['contact', 4],
['company', 3]
];
foreach ($identifiers as list($type, $id)) {
echo ucfirst($type) . ' - ' . $id . "\n";
<?php
class SayNothing
{
public function howToAct()
{
return 'If you can\t say anything nice, then don\'t say anything at all';
}
}
@stevenwadejr
stevenwadejr / jQuery Chain Custom Functions
Last active November 1, 2018 09:52
Sometimes I want to execute some custom code while chaining on a jQuery element and maintain that chainability.
$.fn.chain = function(func) {
func.apply(this);
return this;
}
$('#my-div')
.fadeIn()
.chain(function(){
// Do something here
// You can even use $(this) on your original element
/**
* Simple demo for adding swipe detection on a table view row. Since the row is simply a container
* of views, you'll want to generally create a hidden view the size of the row and add your swipe listener
* to this view for detection. We need to improve Titanium so you don't have to do this in the future...
*/
var win = Ti.UI.createWindow();
var data = [];
for (var c=0;c<10;c++)
{