Skip to content

Instantly share code, notes, and snippets.

View trafficinc's full-sized avatar

Ron trafficinc

  • Greater Philadelphia
View GitHub Profile
@trafficinc
trafficinc / ChildtoParentDataPass.js
Last active January 11, 2021 14:08
React: Pass data from Child to Parent Component
import React, { Component } from "react";
import { render } from "react-dom";
const styles = {
fontFamily: "sans-serif",
textAlign: "center"
};
class ChildComponent extends Component {
state = {
@trafficinc
trafficinc / PHPping.php
Created December 19, 2020 16:56
Ping Website on Mac/Linux with PHP
<?php
class Ping {
private $host;
private $ttl;
private $timeout;
public $commandOut;
private $localhost = false;
public function __construct($host, $ttl = 255, $timeout = 10) {
@trafficinc
trafficinc / ReallySimplePHPprofiling.php
Created December 18, 2020 00:53
Simple PHP Profiling Performance
<?php
/* ----- Profiling.php ----- */
class Profiling {
public $messages = [];
protected $profile;
protected $current_time;
public function __construct($profile) {
@trafficinc
trafficinc / php-event-listener-example.php
Created July 14, 2020 16:33 — forked from im4aLL/php-event-listener-example.php
PHP event listener simple example
<?php
class Event {
private static $events = [];
public static function listen($name, $callback) {
self::$events[$name][] = $callback;
}
public static function trigger($name, $argument = null) {
foreach (self::$events[$name] as $event => $callback) {
@trafficinc
trafficinc / ObjectPrettyPrint.js
Created July 11, 2020 00:33
Pretty print a javascript obect.
var obj = {
module: 'ceo',
children: [
{
module: 'VP of Happiness',
children: [{ module: 'Manager of P' },{ module: 'Manager of III' }]
},
{
module: 'VP of Finance',
@trafficinc
trafficinc / deleteObjectFromArray.js
Last active October 13, 2022 13:15
Delete Object from Array/Collection
let startTime = new Date();
// delete an object in a array/collection
const collection = [
{id:3, name:"Item #1",age:32},
{id:4, name:"Item #2",age:33},
{id:5, name:"Item #3",age:34},
{id:6, name:"Item #4",age:35},
{id:7, name:"Item #5",age:36},
{id:8, name:"Item #6",age:47},
];
@trafficinc
trafficinc / updateCollectionArray.js
Last active October 13, 2022 13:16
Update JavaScript Object in Collection
let startTime = new Date();
// updating an object in a array/collection
let collection = [
{id:3, name:"Item #1",age:32},
{id:4, name:"Item #2",age:33},
{id:5, name:"Item #3",age:34},
{id:6, name:"Item #4",age:35},
{id:7, name:"Item #5",age:36},
{id:8, name:"Item #6",age:47},
];
@trafficinc
trafficinc / helperTypeFunctions.js
Created July 7, 2020 20:20
JS Type checking helper functions
function isDefined(val) {
return typeof val !== 'undefined';
}
function isUndefined(val) {
return typeof val === 'undefined';
}
function isNull(val) {
return val === null && typeof val === 'object';
@trafficinc
trafficinc / formatToRegex.php
Created June 14, 2020 13:14
Format To RegEx String
<?php
function formatToRegex(string $format): string {
$result = preg_quote($format, '/');
$result = str_replace('%d', '\d+', $result);
$result = str_replace('%s', '[^\r\n]+', $result);
return "/^$result$/s";
}
$output = "Mr. Jones";
@trafficinc
trafficinc / php-diff.php
Created June 14, 2020 13:07
PHP Array Diff
<?php
// Array Diff
class DiffElem
{
const TYPE_KEEP = 0;
const TYPE_REMOVE = 1;
const TYPE_ADD = 2;