Skip to content

Instantly share code, notes, and snippets.

View Maqsim's full-sized avatar

Max Diachenko Maqsim

View GitHub Profile
@Maqsim
Maqsim / gist:6218702
Last active December 21, 2015 00:18
Is $subject available for $access_level?
<?php
function isSubjectAvailableToRole($subject, $access_level) {
// 9 - Expert
// {N} - {Role}
$denied = array(
9 => array('price')
);
return ! in_array($subject, $denied[$access_level]);
@Maqsim
Maqsim / replace.sql
Last active December 22, 2015 05:19
mysql> UPDATE files SET href =
IF(POSITION("assignments/uploaded_files" IN href) ,
CONCAT(
"http://www.assignmentexpert.com/uploads/users_files" ,
SUBSTR(
href ,
POSITION("assignments/uploaded_files" IN href) + 26 ,
LENGTH(href) - 26
)
) ,
@Maqsim
Maqsim / gist:6607100
Last active December 23, 2015 08:19
Allow and deny permissions
<?php
/**
* Give or deny access for some user level
* Examples:
* "+(4)" --> [4]
* "+(user, 4)" --> [1, 4]
* "+(10) -(2, operators) +(all)" --> [1,2,3,4,7,10]
* "+(all)-(3)" --> [1,2,4,7,10]
* "-(all)" --> []
@Maqsim
Maqsim / prettifier.php
Last active December 24, 2015 13:49
Prettify respone from DB via filters
<?php
public function _prettify_order_response($order)
{
// Load dependencies
$subjects = $this->subjects;
// Init field->filter array
$nice_response = array(
'id' => 'task_id',
SELECT
(COUNT(`task_id`) / 66413) * 100 AS percent,
(SELECT `title` FROM `cats` WHERE `cat_id` = `tasks`.`cat_id`) as category
FROM `tasks`
GROUP BY `cat_id`
ORDER BY `percent` DESC
@Maqsim
Maqsim / $resolve.js
Created February 3, 2014 14:19
Angular Resolves Inside Controller
module.controller('ControllerName', [
'$scope',
'$q',
function (
$scope,
$q
) {
var initResources = function (resources) {
// init after data loading
};
.directive("currencyInput", ['$filter', '$timeout', function ($filter, $timeout) {
return {
replace: false,
restrict: "A",
require: "?ngModel",
link: function (scope, element, attrs, ngModel) {
if (!ngModel) {
return;
}
@Maqsim
Maqsim / gist:a660b5624d05249b704c
Created May 15, 2015 17:59
Set all title by max height
var maxTitleHeight = angular
.element('.tracker_title')
.map(function() {
return angular.element(this).height();
});
maxTitleHeight = Math.max.apply(this, maxTitleHeight);
angular
.element('.tracker_title')
@Maqsim
Maqsim / hex-to-bgr.js
Created February 13, 2018 23:12
HEX to BGR
'#ff2233'.substr(1).match(/.{2}/g).reverse().join('')
@Maqsim
Maqsim / api-wrapper.js
Created March 4, 2018 00:51
Custom API wrapper (minimalistic concept) for any RESTful API to minimize and beautify your code
class WhateverAPI {
constructor(baseUrl, clientID, accessToken) {
this._baseUrl = baseUrl;
this._clientID = clientID;
this._accessToken = accessToken;
this._baseUrl += this._baseUrl.slice(-1) !== '/' ? '/' : '';
}
resolveUrl(path) {
return this._baseUrl + path + `?client_id=${this._clientID}&access_token=${this._accessToken}`;