Skip to content

Instantly share code, notes, and snippets.

View Maqsim's full-sized avatar

Max Diachenko Maqsim

View GitHub Profile
@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
};
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 / 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',
@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 / 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: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]);