Skip to content

Instantly share code, notes, and snippets.

Avatar

Jozef Cipa jozefcipa

View GitHub Profile
@jozefcipa
jozefcipa / redact-sensitive.js
Last active Jun 9, 2020
Replace sensitive data in JSON (logs)
View redact-sensitive.js
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]'
}
})
@jozefcipa
jozefcipa / json-processor.js
Last active Nov 3, 2022
Process large JSON files with streams
View json-processor.js
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 = {}
@jozefcipa
jozefcipa / chunk.js
Last active Oct 11, 2020
Process lots of promises effectively
View chunk.js
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
}
View watcher.sh
#!/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
View exception.blade.php
{* resources/views/mail/exception.blade.php *}
{!! $exceptionHtml !!}
View YourController.php
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
View Handler.php
// 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();
@jozefcipa
jozefcipa / ExceptionOccured.php
Last active Nov 9, 2017
Sending exceptions in Laravel to mail
View ExceptionOccured.php
<?php
// app/Mail/ExceptionOccured.php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
@jozefcipa
jozefcipa / .eslintrc.js
Last active Aug 29, 2018
Compiling Sass with autoprefixer, ReactJS, JSX, ES6, gzip compression, eslint, sourcemaps, livereload, html minifying, link hashes, vendor dependencies in separate bundle file
View .eslintrc.js
// 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"],