This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cloneDeepWith from 'lodash.clonedeepwith' // or import { cloneDeepWith } from 'lodash' | |
function redactSensitiveData(data, sensitiveKeys) { | |
return cloneDeepWith(data, value => { | |
if (value && typeof value === 'object') { | |
sensitiveKeys.forEach(key => { | |
if (value[key]) { | |
value[key] = '[redacted]' | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs' | |
import { Transform } from 'stream' | |
import JSONStream from 'JSONStream' | |
// Custom transform stream | |
const transformer = new Transform({ | |
objectMode: true, | |
transform(jsonItem, encoding, callback) { | |
// your logic goes here... | |
// const updatedItem = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chunk from 'lodash.chunk' | |
export const processInChunks = async (array, handlerFn, { chunkSize = 5 } = {}) => { | |
const result = [] | |
for (const dataChunk of chunk(array, chunkSize)) { | |
result.push(...await Promise.all(dataChunk.map(handlerFn))) | |
} | |
return result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Process watcher | |
# Watches for processes if they run, if not, launch them again | |
# chmod +x /path/to/your/project/watcher.sh | |
# crontab -e | |
# * * * * * /path/to/your/project/watcher.sh # Schedules watcher to run every minute | |
# Define program to run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{* resources/views/mail/exception.blade.php *} | |
{!! $exceptionHtml !!} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
// ... | |
} catch(Exception $e) { | |
// explicitly report an exception | |
// in Laravel < 5.5 | |
app(\App\Exceptions\Handler::class)->report($e); | |
// since Laravel 5.5 is available new helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/Exceptions/Handler.php | |
public function report(Exception $exception) | |
{ | |
// log errors only in production mode and it's not http exception | |
if (env('APP_ENV') == 'production' && !$this->isHttpException($exception)) { | |
// parse html from response | |
$exceptionHtml = $this->render(null, $exception)->getContent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/Mail/ExceptionOccured.php | |
namespace App\Mail; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Mail\Mailable; | |
use Illuminate\Queue\SerializesModels; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: .js extension used here only for syntax highlighting, DO NOT use in development !!! | |
{ | |
"env": { | |
"browser": true, | |
"es6": true, | |
"node": true | |
}, | |
"parser": "babel-eslint", | |
"rules": { | |
"quotes": [2, "single"], |