Skip to content

Instantly share code, notes, and snippets.

View ichiriac's full-sized avatar
🚀

Ioan CHIRIAC ichiriac

🚀
View GitHub Profile
@ichiriac
ichiriac / scan.js
Created January 29, 2017 08:23
Scan a path with PHP files
var fs = require('fs');
// https://www.npmjs.com/package/php-parser
var parser = require('php-parser');
// https://www.npmjs.com/package/glob
var glob = require('glob');
glob("**/*.php", options, function (er, files) {
for(var i = 0; i < files.length; i++) {
var file = files[i];
try {
@ichiriac
ichiriac / usage.js
Created January 24, 2017 13:06
Quick Start / Usage / php-transpiler
// initialize the php parser factory class
var engine = require('php-parser');
var transpiler = require('php-transpiler');
var jsCode = transpiler.generate(
engine.parseCode('<?php echo "Hello World";')
);
console.log(jsCode);
npm install php-transpiler --save
@ichiriac
ichiriac / demo.js
Last active January 3, 2017 12:18
A simple usage of php-parser
var parser = require('php-parser');
// initialize a new parser instance
var instance = new parser({
parser: {
extractDoc: true,
suppressErrors: true
},
ast: {
withPositions: true
@ichiriac
ichiriac / demo.php
Created December 17, 2016 19:26
A sample PHP file for showing AST with php-parser
<?php
/**
* Some namespace & file description
*/
namespace foo {
function bar($a, $b) {
return $a + $b;
}
// will print : 5
echo bar(2, 3);
@ichiriac
ichiriac / php-parser.sh
Created December 17, 2016 18:37
Install php-parser from npm
npm install php-parser --save
@ichiriac
ichiriac / weby.php
Created October 16, 2013 17:17
Have some fun with pthreads
<?php
define('CRLF', "\r\n");
class HaveToWork extends Thread {
protected $wait;
public $socket = null;
public function __construct() {
$this->wait = true;
$this->start();
}
public function run() {
@ichiriac
ichiriac / jPrototype.php
Last active December 21, 2015 20:49
An experiment to implement the Javascript Prototype principle in PHP 5.3
<?php
class jPrototype {
protected static $prototype = array();
public static function prototype() {
if ( !self::$prototype ) {
self::$prototype = new self();
}
return self::$prototype;
}
public function __set($property, $value) {
<?php
function renderTemplate($template, $data) {
$data_keys = array_map(function($key) {
return '%' . $key . '%';
}, array_keys($data));
$data_values = array_values($data);
return str_replace($data_keys, $data_values, $template);
}
@ichiriac
ichiriac / sanitize.php
Created December 16, 2012 13:29
This function sanitize strings by removing accentuation, converting UTF8 to ASCII - helpfull for encoding URLs
/**
* Function: sanitize
* Returns a sanitized string, typically for URLs.
*
* Parameters:
* $string - The string to sanitize.
* $lowercase - Force the string to lowercase?
* $alnum - If set to *true*, will remove all non-alphanumeric characters.
*/
function sanitize($string, $lowercase = true, $alnum = false) {