Skip to content

Instantly share code, notes, and snippets.

@maztch
maztch / vi-commands.md
Created October 7, 2021 07:31
Vi commands for linux editor

#Vi commands list

Commands and their Description

k : Moves the cursor up one line. j : Moves the cursor down one line. h : Moves the cursor to the left one character position. l : Moves the cursor to the right one character position. 0 or | : Positions cursor at beginning of line. $ : Positions cursor at end of line.

@maztch
maztch / docker-clean.sh
Last active May 25, 2019 11:20
Remove all docker images and containers
#!/bin/bash
#stop all containers
docker kill $(docker ps -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
https://github.com/phpstan/phpstan
https://github.com/phpstan/phpstan-strict-rules
https://github.com/rectorphp/rector
https://github.com/phpDocumentor/phpDocumentor2
https://github.com/FriendsOfPHP/PHP-CS-Fixer
https://github.com/karlosagudo/fixtro
https://github.com/vimeo/psalm
https://github.com/phpmetrics/phpmetrics
@maztch
maztch / sw.js
Created April 25, 2019 17:30 — forked from ireade/sw.js
Handle broken images with the service worker
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open("precache").then((cache) => cache.add("/broken.png"))
);
});
function isImage(fetchRequest) {
return fetchRequest.method === "GET" && fetchRequest.destination === "image";
}
@maztch
maztch / cors.js
Created September 10, 2018 11:00
node CORS route sample
// all our previous code should be here
// this array is used for identification of allowed origins in CORS
const originWhitelist = ['http://localhost:3000', 'https://example.net'];
// middleware route that all requests pass through
router.use((request, response, next) => {
console.log('Server info: Request received');
let origin = request.headers.origin;
@maztch
maztch / waitfor.js
Created June 7, 2018 09:20
wait for jquery on async load (or other class)
function doSomething() {
console.log('do something with jQuery');
}
var waitInterval = window.setInterval(function () {
try {
if (jQuery === 'function') {
clearInterval(waitInterval);
doSomething();
}
@maztch
maztch / queue checker
Last active October 28, 2017 09:32
a process count check for php-enqueue/enqueue-bundle
<?php
/**
* It's just a sample helper
* I'm sure it can be done better...
**/
class QueueHelper
{
static public function check(){
$out = [];
@maztch
maztch / brew-perms.sh
Created April 10, 2017 09:52 — forked from jaibeee/brew-perms.sh
Configure homebrew permissions to allow multiple users on MAC OSX. Any user from the admin group will be able to manage the homebrew and cask installation on the machine.
#!/bin/sh
# Configure homebrew permissions to allow multiple users on MAC OSX.
# Any user from the admin group will be able to manage the homebrew and cask installation on the machine.
# allow admins to manage homebrew's local install directory
chgrp -R admin /usr/local
chmod -R g+w /usr/local
# allow admins to homebrew's local cache of formulae and source files
chgrp -R admin /Library/Caches/Homebrew
@maztch
maztch / ads_block_detect.js
Created March 3, 2017 08:42
Detects ads blockers
var adBlockEnabled = false;
var testAd = document.createElement('div');
testAd.innerHTML = '&nbsp;';
testAd.className = 'adsbox';
document.body.appendChild(testAd);
window.setTimeout(function() {
if (testAd.offsetHeight === 0) {
adBlockEnabled = true;
}
testAd.remove();
@maztch
maztch / magento_clean.sql
Created November 30, 2016 11:15
Delete test data (sales, customers, logs) and reset index for tables
# Tested on Magento CE 1.4.1.1 - 1.9.2.4
SET FOREIGN_KEY_CHECKS=0;
##############################
# SALES RELATED TABLES
##############################
TRUNCATE `db5j_sales_flat_creditmemo`;
TRUNCATE `db5j_sales_flat_creditmemo_comment`;
TRUNCATE `db5j_sales_flat_creditmemo_grid`;