Skip to content

Instantly share code, notes, and snippets.

@maztch
maztch / light-css.txt
Created October 7, 2016 09:22
ligth-css
<script>
window.addEventListener('devicelight', function(e) {
var lux = e.value;
if (lux < 50) { // luz tenue
document.body.className = 'tenue';
}
if (lux >= 50 && lux <= 1500) { //luz normal
document.body.className = 'normal';
}
@maztch
maztch / iterm2.md
Created November 4, 2016 08:31
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
Previous Tab + Left Arrow
Next Tab + Right Arrow
Go to Tab + Number
Go to Window + Option + Number
Go to Split Pane by Direction + Option + Arrow
Go to Split Pane by Order of Use + ] , + [
@maztch
maztch / backupdb.sh
Created November 16, 2016 12:51
database backup script
#!/bin/bash
# this script makes a database backup and delete files older than 15 days
# to make script execuable use 'chmod +x backupdb.sh'
# change username, password and database for yours and modify your path if needed
mysqldump -u [username] -p[password] [database_name] > /root/backups/db_backup_`date +"%Y%m%d%H%M%S"`.sql
# change '-mtime +15' to keep more or less days (and path if needed)
find /root/backups/* -mtime +15 -exec rm {} \;
@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`;
@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 / 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 / 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 / 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 / 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";
}
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