Skip to content

Instantly share code, notes, and snippets.

View seromenho's full-sized avatar
🚀
To the infinity and beyond

Ricardo Seromenho seromenho

🚀
To the infinity and beyond
View GitHub Profile
@seromenho
seromenho / index.js
Created February 13, 2020 21:27
Get Node VM results from an async script
const vm = require('vm');
(async () => {
const sandbox = {
a: 1
};
await new Promise(resolve => {
sandbox.resolve = resolve;
const code = 'Promise.resolve(2).then(result => {a = result; resolve();})';
const script = new vm.Script(code);
@seromenho
seromenho / recursive_array_walk_recursive.php
Last active February 26, 2016 15:11
array_walk_recursive working for objects.
<?php
class A
{
private $ab = 5;
public $ac = 6;
}
/**
* WARNING: This https://bugs.php.net/bug.php?id=45937 seems not yet solved
@seromenho
seromenho / LuhnValidator.php
Last active August 29, 2015 14:21
PHP Luhn Validator (from Symfony)
<?php
/**
* Validates a value using the LUHN Algorithm.
* @param string $value Value to validate. EG: Credit card number
* @return bool
*/
function isLuhn($value)
{
if (!is_string($value) || !ctype_digit($value)) {