Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Coffee in. Code out.

Alexandre Reis dreanmer

💭
Coffee in. Code out.
View GitHub Profile
@dreanmer
dreanmer / client.js
Created October 7, 2021 05:19
Node.js: call method on forked process and get response through socket (vanilla)
View client.js
const net = require('net');
// send message to server (forked process)
process.send({
event: 'spawned',
data: {
client: 'is loading'
}
});
@dreanmer
dreanmer / fizzBuzzNoIf.php
Last active August 15, 2017 15:01
Fizz Buzz solution zero if
View fizzBuzzNoIf.php
<?php
$result = array_diff( range( 0, 100, 1 ), range( 0, 100, 3 ), range( 0, 100, 5 ) ) +
array_fill_keys( range( 0, 100, 15 ), 'FizzBuzz' ) +
array_fill_keys( range( 0, 100, 5 ), 'Buzz' ) +
array_fill_keys( range( 0, 100, 3 ), 'Fizz' );
ksort( $result );
unset( $result[ 0 ] );
echo implode( "\n", $result );
@dreanmer
dreanmer / fizBuzzRegex.php
Last active August 15, 2017 15:04
Fizz Buzz solution one if (with regex)
View fizBuzzRegex.php
<?php
$result = '';
for($i=1;$i<=100;$i++){
if(!($i%3)){
$result .= 'm';
}
$result .= $i . "\n";
}
$result = preg_replace("/m\d*(0|5)\n/", "FizzBuzz\n", $result);
$result = preg_replace("/\d*(0|5)\n/", "Buzz\n", $result);