Skip to content

Instantly share code, notes, and snippets.

View ravanscafi's full-sized avatar
:shipit:
ship it

Ravan Scafi ravanscafi

:shipit:
ship it
View GitHub Profile
@ravanscafi
ravanscafi / max_parallelism.php
Created November 30, 2016 16:39
Proof of Concept: Max Parallel execution in PHP, awaiting for all children to return before exiting.
<?php
$maxChildren = 4;
$totalChildren = 20;
$pids = [];
echo "Max parallel children: {$maxChildren}\nTotal children: {$totalChildren}\n\n";
for ($i = 1; $i <= $totalChildren; $i++) {
if (count($pids) >= $maxChildren) {
$pid = pcntl_wait($status);
@ravanscafi
ravanscafi / _readme.md
Last active June 22, 2019 14:42
Proper way to use LiveReload with Laravel Elixir

Proper way to use LiveReload with Laravel Elixir

Features

  • It works without touching laravel-elixir source files, so it will not break on updates.
  • It runs only on watch task, so that when you run other tasks, livereload will not start and hang the console.
  • It performs soft-reloads on CSS changes, instead of a full page reload.

Instructions

  1. npm install gulp-livereload if you still don't have it.
  2. Create an elixir.json file on the root of your project (where your gulpfile.js is located)
@ravanscafi
ravanscafi / css-color-for-string.php
Last active April 23, 2024 15:47
Random Color from Input's MD5 Hash
<?php
/**
* Generate a consistent* random color for a text input.
* Consistent because it's based on MD5 hash for the input.
* Since both MD5 and CSS colors uses hexa, a substring of the MD5 can be used.
* Clever, huh?
*
* PS: you can get any substring of length 3 (for less colors) or 6 (for more colors) from your hash. Just don't
* randomize it, or you will loose consistency.
@ravanscafi
ravanscafi / char_list.php
Last active July 4, 2016 05:09
PHP: Return all unique characters present in an array of strings.
<?php
/**
* Return all unique characters present in an array of strings.
* It ignores spaces due to join().
* e.g.:
* ['abc', 'g', 'def', 'abcd'];
* > 'abcdefg'
*
* @param array $array