Skip to content

Instantly share code, notes, and snippets.

View 2bj's full-sized avatar
🏠
Working from home

Bakyt 2bj

🏠
Working from home
View GitHub Profile
@2bj
2bj / play.online.kg.html
Created March 31, 2016 11:53
play.online.kg, 2003год
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<meta name="Author" content="BJ">
<meta http-equiv="imagetoolbar" content="no">
@2bj
2bj / db-open
Created March 26, 2016 00:06 — forked from helderco/db-open
Script to open a mysql database in Sequel Pro from a service in docker-compose.
#!/bin/bash
set -e
show_help() {
cat << EOF
Usage: ${0##*/} [-u USER] [-p PASS] [-P PORT] [-H HOST] [DATABASE]
${0##*/} -h
Open a standard connection in Sequel PRO.
@2bj
2bj / redis-delallbykey
Created November 3, 2015 08:51 — forked from mattweyant/redis-delallbykey
Delete all keys from Redis matching a regular expression
# All credit: http://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-with-redis
redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL
php artisan --help OR -h
php artisan --quiet OR -q
php artisan --version OR -V
php artisan --no-interaction OR -n
php artisan --ansi
php artisan --no-ansi
php artisan --env
// -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
php artisan --verbose
@2bj
2bj / redis-delkeys.sh
Last active August 29, 2015 14:19 — forked from jdp/redis-delkeys.sh
#!/bin/sh
#
# Usage: ./redis-delkeys.sh [-h host] [-p port] [-n db] pattern
#
# Matches keys with the KEYS command matching pattern
# and deletes them from the specified Redis DB.
set -e
HOST="localhost"
@2bj
2bj / NSString+Extend.h
Created March 31, 2015 16:34
NSString+Extend
//
// NSString+Extend.h
//
// Created by Bakyt on 31.03.15.
// Copyright (c) 2015 Bakyt. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (Extend)

#Laravel 5 Simple ACL manager

Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.

If the user has a 'Root' role, then they can perform any actions.

Installation

Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
jQuery.each( [ ["update", "PATCH"], ["delete", "DELETE"] ], function( i, method ) {
jQuery[method[0]] = function (url, data, callback, type) {
if (jQuery.isFunction(data)) {
type = type || callback;
callback = data;
data = undefined;
} else {
if (data === undefined) {
data = {_method: method[1]};
} else {

Источник

Трюки Eloquent для лучших репозиториев

Одна из лучших вещей в написании кода - очевидность хороших практик, ведь если им не следовать, возникает раздражение. Очень надоедает, когда вам нужно писать одну и ту же вещь снова и снова. Когда вы чувствуете себя недовольным из-за повторения одних и тех же вещей, наступает время абстракции.

В типичном приложении вы, вероятно, имеете множество Репозиториев для работы с вашей системой хранения. Когда вы используете Laravel, вы проводите много времени работая с Eloquent. Тем не менее, поверьте мне, когда у вас есть множество Репозиториев, вам быстро надоедает многократно писать одни и те же методы для доступа к данным.

В этом руководстве я хочу рассмотреть некоторые паттерны для абстракции основных методов, которые вы больше не будете повторять в каждой реализации ваших Репозиториев. Я также покажу, как мы можем использовать гибкость Eloquent и его Query Builder для написания действител