Skip to content

Instantly share code, notes, and snippets.

View ternavsky's full-sized avatar

Eugene Ternavsky ternavsky

  • https://simplecodesoftware.com/
  • Russia, Novocherkassk
View GitHub Profile
@ternavsky
ternavsky / formatJsonLogs.js
Last active January 25, 2023 16:47
VS Code macros: Format json logs - remove everything except json and format
const vscode = require('vscode');
/**
* Macro configuration settings
* { [name: string]: { ... Name of the macro
* no: number, ... Order of the macro
* func: ()=> string | undefined ... Name of the body of the macro function
* }
* }
*/
@ternavsky
ternavsky / nodeFilesWalk.js
Created December 8, 2020 16:56
Node.js read all files in folder and subfolders
const fs = require('fs');
const path = require('path');
const walkSync = (dir, callback) => {
const files = fs.readdirSync(dir);
files.forEach((file) => {
var filepath = path.join(dir, file);
const stats = fs.statSync(filepath);
if (stats.isDirectory()) {
walkSync(filepath, callback);
@ternavsky
ternavsky / Emitter.ts
Created August 2, 2018 07:56
Typescript Event Bus
import IEvent from "IEvent";
import IEventListener from "IEventListener";
export class EventEmitter
{
private listeners: { [key: string]: IEventListener[] } = {};
public on(event: Function, listener: IEventListener): void
{
if (!this.listeners[event.name]) this.listeners[event.name] = [];
@ternavsky
ternavsky / .php_cs
Created June 27, 2018 07:11
Visual Studio php-cs-fixer config. Put it somewhere and set path in php-cs-fixer extension settings.
<?php
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'method_separation' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_quote' => true,
@ternavsky
ternavsky / ApiController.php
Last active June 25, 2018 14:40
Base class for Laravel Api controller
<?php
use Backend\Classes\Controller;
use Illuminate\Http\Response;
class ApiController extends Controller {
protected $statusCode = Response::HTTP_OK;
public function setStatusCode($code)
@ternavsky
ternavsky / gist:36894cb0babd29c07e30590430c3120a
Created January 15, 2018 07:46
OctoberCMS file permissions production setup
#!/bin/bash
sudo chown -R www-data:www-data *
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 664 {} \;
sudo chmod -R g+s storage themes
sudo chmod -R ug+rwx storage themes
@ternavsky
ternavsky / atom-config
Last active September 16, 2016 05:51
My Atom Configuration by http://atom.io/packages/sync-settings
test
@ternavsky
ternavsky / CountryCodes.php
Created December 8, 2015 09:27
Class allows to get country name by 2 letters code (getNameByCode) and code by name (getCodeByName). You can add several names for country separated by "|" (ex. United States|USA) in country array. getNameByCode will return first variant. getCodeByName will check all name variants in case-insensetive manner and return code if found.
<?php
class CountryCodes
{
private static $codes = array (
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
@ternavsky
ternavsky / queue-ensure.php
Last active August 26, 2016 12:08 — forked from mauris/queue-ensure.php
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener was down, it would restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
@ternavsky
ternavsky / Inflect.php
Last active August 28, 2015 12:53 — forked from tbrianjones/Inflect.php
A PHP Class for converting English words between Singular and Plural.
<?php
// original source: http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/
/*
The MIT License (MIT)
Copyright (c) 2015
Permission is hereby granted, free of charge, to any person obtaining a copy