How to keep GitHub Fork Updated (no merge - the right way)

Here is solution how to keep your forks updated without merge and clean history

git clone[username]/[repo].git
git remote add upstream[username2]/[repo].git

When something change in forked repo

git fetch upstream
git checkout [branch]
git rebase upstream/[branch]

Convert JSON data to valid PHP code

Do you need convert JSON data to valid PHP code without pain? I've got a short script for that! My simple solution used var_export() function. This function generates almost valid, well formatted PHP code from usual JSON data. Invalidity of code can be fix with one regular expression, which replace stdClass::__set_state/ with (object).

Take a closer look at example data. I have here currency.json - PHP code should look something like this:

 return array (
  'USD' =>
     'symbol' => '$',
     'name' => 'US Dollar',
     'symbol_native' => '$',
     'decimal_digits' => 2,
     'rounding' => 0,
     'code' => 'USD',
     'name' => 'US dollars',
  'CAD' =>

It's can be done in only four lines of PHP code:

$data = json_decode(file_get_contents(__DIR__ . '/currency.json'));
$code = var_export((array)$data, true);
$code = "<?php\n return " . preg_replace('/stdClass::__set_state/', '(object)', $code) . ';';
file_put_contents(__DIR__ . '/currencies.locale.php', $code);

If you need call some function (like gettext) above the variable, just add more regular expression:

$data = json_decode(file_get_contents(__DIR__ . '/currency.json'));
$code = var_export((array)$data, true);

// add gettext function call
$code = preg_replace("/'name' => '(.+)'/", "'name' => __('$1')", $code);
$code = preg_replace("/'name_plural' => '(.+)'/", "'name' => __('$1')", $code);

// save PHP code
$code = "<?php\n return " . preg_replace('/stdClass::__set_state/', '(object)', $code) . ';';
file_put_contents(__DIR__ . '/currencies.locale.php', $code);

Upgrade all npm packages to latest versions

This is similar to npm-check interactive update mode. It provides an easy way to update outdated packages

yarn upgrade-interactive --latest 
[1/? Choose which packages to update. (Press <space> to select, <a> to toggle all, <i> to inverse selection)

❯◯ autoprefixer      6.7.7  ❯  7.0.0
 ◯ webpack           2.4.1  ❯  2.5.1

 ◯ bull              2.2.6  ❯  3.0.0-alpha.3
 ◯ fs-extra          3.0.0  ❯  3.0.1
 ◯         1.7.3  ❯  1.7.4
 ◯  1.7.3  ❯  1.7.4

How to clean flash drive before unmount on Mac

How to clean flash drive and delete all hidden (dot) files on mac before unmount? It's simple, save follow commands as flash:


if [ -n "$1" ]; then
  read -r -p "Clean /Volumes/$1/ and unmount? [y/N] " response
  if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then      
    find /Volumes/$1/ -name '._*' -type f -delete
    rm -rf /Volumes/$1/.Spotlight-V100/
    rm -rf /Volumes/$1/.Trashes/
    diskutil unmount /Volumes/$1/
    echo "Done..."
  echo "Flash drive name missing"

Then change the access mode of a file chmod +x flash. To unmount a clean flash drive just run ./flash Flashka (Flashka is name od drive).

Wordpress - get post excerpt

$excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));