Skip to content

Instantly share code, notes, and snippets.

View Tiriel's full-sized avatar

Benjamin Zaslavsky Tiriel

View GitHub Profile
@Tiriel
Tiriel / proper_parse_str.php
Last active August 2, 2016 09:27
Custom function for URL parsing
<?php
/**
* Custom version of parse_str function to avoid overriding of multiple definitions in query string
*
* @param $string
* @return array
*/
function proper_parse_str($string)
{
$array = array();
@Tiriel
Tiriel / class_casting.php
Last active September 7, 2016 12:21
Class casting function from StackOverflow
<?php
/**
* Class casting
*
* @param string|object $destination
* @param object $sourceObject
* @return object
*/
function cast($destination, $sourceObject)
{
@Tiriel
Tiriel / array_to_xml.php
Created October 19, 2016 09:19
Function found on StackOverflow
<?php
// function defination to convert array to xml
function array_to_xml( $data, &$xml_data ) {
foreach( $data as $key => $value ) {
if( is_numeric($key) ){
$key = 'item'.$key; //dealing with <0/>..<n/> issues
}
if( is_array($value) ) {
$subnode = $xml_data->addChild($key);
array_to_xml($value, $subnode);
@Tiriel
Tiriel / Slugifier.php
Created November 9, 2016 15:13
Small sluggifier static function. Simply call Slugifier::slugify($string)
<?php
class Slugifier
{
public static function slugify($string)
{
$aArray = array('à', 'â', 'ä');
$eArray = array('é', 'è', 'ê', 'ë');
$iArray = array('î', 'ï');
$oArray = array('ô', 'ö');
$uArray = array('ù');
@Tiriel
Tiriel / request_dump.sh
Last active January 6, 2017 08:56
Symfony Request dump
object(Symfony\Component\HttpFoundation\Request)#4 (21) {
["attributes"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#7 (1) {
["parameters":protected]=>
array(6) {
["id"]=>
string(5) "11832"
["provider"]=>
NULL
@Tiriel
Tiriel / set-and-get.php
Last active September 15, 2017 21:42
Universal __set and __get methods
<?php
/**
* @param $name
* @param $value
* @return $this
*/
function __set($name, $value)
{
$reflected = new \ReflectionClass($this);
$property = $reflected->getProperty($name);
@Tiriel
Tiriel / utilities.js
Last active August 28, 2017 09:10
NodeJS utilities (outgoing requests interceptor, unhandledRejection monitor)
'use-strict';
/**
* Debug toolbox startng point
* Usage :
* const utilities = require('path-to-utilities.js');
* utilities.requestLogger(require('http'));
* utilities.unhandledRejectionMonitor();
*/
module.exports.requestLogger = function(httpModule){
let original = httpModule.request;
@Tiriel
Tiriel / encryption.js
Last active June 21, 2024 07:53
Symetric encryption/decryption for PHP and NodeJS communication
'use strict';
const crypto = require('crypto');
const AES_METHOD = 'aes-256-cbc';
const IV_LENGTH = 16; // For AES, this is always 16, checked with php
const password = 'lbwyBzfgzUIvXZFShJuikaWvLJhIVq36'; // Must be 256 bytes (32 characters)
function encrypt(text, password) {
@Tiriel
Tiriel / deepcompare.php
Created August 26, 2017 12:52
Deep recursive comparing tool
<?php
class DeepCompare
{
/**
* Deep recursive comparison tool.
* Function ca be used as basis for comparison and update tool. Un-static function and add updating tools (setters)
*
* @param $var1
* @param $var2
@Tiriel
Tiriel / onename.txt
Created September 30, 2017 12:19
Blockstack ID
Verifying that "bzaslavskytiriel.id" is my Blockstack ID. https://onename.com/bzaslavskytiriel