Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ricardo Seromenho seromenho

🏠
Working from home
View GitHub Profile
@seromenho
seromenho / index.js
Created Feb 13, 2020
Get Node VM results from an async script
View index.js
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 Feb 26, 2016
array_walk_recursive working for objects.
View recursive_array_walk_recursive.php
<?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 Aug 29, 2015
PHP Luhn Validator (from Symfony)
View LuhnValidator.php
<?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)) {
You can’t perform that action at this time.