Skip to content

Instantly share code, notes, and snippets.

View jozefcipa's full-sized avatar
🦕

Jozef Cipa jozefcipa

🦕
View GitHub Profile
@jozefcipa
jozefcipa / redact-sensitive.js
Last active June 9, 2020 14:53
Replace sensitive data in JSON (logs)
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 April 15, 2023 01:52
Process large JSON files with streams
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 October 11, 2020 22:28
Process lots of promises effectively
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
}
#!/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
{* resources/views/mail/exception.blade.php *}
{!! $exceptionHtml !!}
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
// 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 November 9, 2017 16:20
Sending exceptions in Laravel to mail
<?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 August 29, 2018 13:30
Compiling Sass with autoprefixer, ReactJS, JSX, ES6, gzip compression, eslint, sourcemaps, livereload, html minifying, link hashes, vendor dependencies in separate bundle file
// 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"],