Provides tips for the student for the given submission,
 based on the `rules`.
423561
def assist_with(submission)
      @rules
        .select { |it| it.matches?(submission) }
        .map { |it| it.message_for(submission.attemps_count) }
    end
543040
def relevant_rules_for_match(self, action, subject):
        """"""
        matches = []
        for rule in self.rules:
            rule.expanded_actions = self.expand_actions(rule.actions)
            if rule.is_relevant(action, subject):
                matches.append(rule)

        return self.optimize(matches[::-1])
174750
public function onBeforeWrite()
    {
        // save submitter if a Member is logged in
        $currentMember = Security::getCurrentUser();
        if (!$this->SubmitterID && $currentMember) {
            $this->SubmitterID = $currentMember->ID;
        }

        parent::onBeforeWrite();
    }
645944
function tip(title, content, actions, type) {
  if (curTip) {
    curTip.close(() => {
      setTimeout(() => {
        AppContainer.remove(topViewDialogKey);
        setTimeout(() => {
          creatTip(title, content, actions);
        }, 0);
      }, 200);
    });
  } else {
    creatTip(title, content, actions, type);
  }
}
158703
public function setupRules()
    {
        $this->rules->addMany([
            'keyword' => [
                new Rule(new WordMatcher($this->_keywords, ['escape' => false, 'separated' => true]))
            ],

            'constant' => new Rule(new WordMatcher(['False', 'True', 'Nothing']), ['priority' => 3]),
            'comment'  => new Rule(new CommentMatcher(['--'], [['{-', '-}']]), ['priority' => 20]),

            'symbol.type' => new Rule(new RegexMatcher('/\b(_*[A-Z]\w*)\b/'), ['priority' => 1]),
            'symbol.function' => [
                new Rule(new RegexMatcher('/(_*[a-z]\w*)\s*::/')),
                new Rule(new RegexMatcher('/[;\n](_*[a-z]\w*).*?=/'))
            ],
            'operator.named' => new Rule(new RegexMatcher('/(`\w+`)/')),

            'string'   => CommonFeatures::strings(['single' => '\'', 'double' => '"']),

            'number'          => new Rule(new RegexMatcher('/\b(\d+(?>(?>\.|e[+-]?)\d+)?|0o[0-7]+|0x[0-9a-f])\b/i'), ['context' => ['!string', '!comment']]),
            'operator.escape' => new Rule(new RegexMatcher('/(\\[\\0\'|bnrtZ%_])/'), ['context' => ['string']]),
            'operator'        => new Rule(new RegexMatcher('/([^\r\n\s\w\"\'\`\[\]\(\)\{\}]+)/'), [
                'priority' => -1,
                'context'  => ['!comment', '!string']
            ])
        ]);
    }
1184598
private void ruleset( String[] sel, CssFormatter formatter ) {
        formatter = formatter.startBlock( sel );
        appendPropertiesTo( formatter );

        for( Formattable prop : properties ) {
            if( prop instanceof Mixin ) {
                ((Mixin)prop).appendSubRules( null, formatter );
            }
        }

        for( Rule rule : subrules ) {
            rule.appendTo( formatter );
        }
        formatter.endBlock();
    }
478143
public function setupRules()
    {
        parent::setupRules();

        $this->rules->validator = new Validator(
            ['!format.block.code', '!format.monospace', '!operator.escape', '!operator', '!tag']
        );

        $this->rules->addMany([
            'format.header' => [
                new Rule(new RegexMatcher('/^\s{0,3}(#+.+?)\r?$/m')),
                new Rule(new RegexMatcher('/^([^\r\n]+?)^(?:-+|=+)\R?$/m'))
            ],
            'format.italics'   => new Rule(
                new RegexMatcher('/(?:^|[^*_])(?P<italics>(?P<i>[*_])(?>[^*_\r\n]|(?:(?P<b>[*_]{2})(?>[^*_\r\n]|(?&italics))*?\g{b}))+\g{i})/'), [
                    'italics' => Token::NAME
                ]
            ),
            'format.bold'  => new Rule(
                new RegexMatcher('/(?P<bold>(?P<b>\*\*|__)(?>[^*_\r\n]|(?:(?P<i>[*_]{2})(?>[^*_\r\n]|(?&bold))*?\g{i}))+\g{b})/', [
                    'bold' => Token::NAME
                ])
            ),
            'format.strike'    => new Rule(new RegexMatcher('/(~~.+?~~)/')),
            'format.monospace' => [
                new Rule(new RegexMatcher('/(?:[^`]|^)(`.*?`)/')),
                new Rule(new RegexMatcher('/(``.*?``)/')),
                new Rule(new RegexMatcher('/^((?:(?: {4,}|\t).*?(?>\R|$)+?)+)/m')),
            ],

            'operator.list.ordered'   => new Rule(new RegexMatcher('/^\s*(\d+[.)])/m')),
            'operator.list.unordered' => new Rule(new RegexMatcher('/^\s*([-+*])/m'), [
                'context' => ['none'],
                'priority' => 1
            ]),

            'string.quote'       => new Rule(new RegexMatcher('/((?:^>.*?\R)+)/m')),
            'format.block.code'  => [
                new Rule(
                    new DelegateRegexMatcher(
                        '/^```(.*?)\R(.*?)\R^```/ms',
                        function($match, TokenFactoryInterface $factory) {
                            $lang = KeyLighter::get()->getLanguage($match[1][0]);
                            yield $factory->create(Token::NAME, ['pos' => $match[0][1], 'length' => strlen($match[0][0])]);
                            yield $factory->create(
                                "language.{$lang->getIdentifier()}", [
                                    'pos'    => $match[2][1],
                                    'length' => strlen($match[2][0]),
                                    'inject' => $lang,
                                    'class'  => LanguageToken::class,
                                ]
                            );
                        }
                    ), [
                        'context'     => Validator::everywhere(),
                        'postProcess' => true,
                        'priority'    => 1000
                    ]
                ),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/')),

            'operator.horizontal' => new Rule(new RegexMatcher('/^\s{,3}(([-*_])( ?\2)+)\R/m'), [
                'priority' => 2
            ]),

            'symbol.link'  => new Rule(new RegexMatcher('/[^!](\[(?:[^\[\]]|!\[.*?\]\(.*?\))*\])/i')),
            'symbol.url'   => new Rule(new RegexMatcher('#(<(https?://|[^/])[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|]>|https?://[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|])#i'), [
                'priority' => 0,
            ]),
            'symbol.image' => new Rule(new RegexMatcher('/(!)(\[.*?\])\(.*?\)/i', [
                1 => 'operator.image',
                2 => '$.title',
            ])),
        ]);
    }
736391
public function setupRules()
    {
        $this->rules->addMany([
            'call' => new Rule(new RegexMatcher('/^\h*(\w[\w\.]*)/im')),
            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [
                'context' => Validator::everywhere()
            ]),

            'keyword.format' => new Rule(
                new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [
                    'context' => ['string']
                ]
            ),
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!operator.escape', '!comment', '!string'],
            ]),

            'symbol' => [
                'type'  => new Rule(new WordMatcher(['byte', 'word', 'dword', 'qword']), ['name' => 'builtin']),
                'label' => new Rule(new RegexMatcher('/([a-z]\w+:)/i'), ['priority'=>3])
            ],

            'comment' => [
                new Rule(new CommentMatcher([';'], []), ['priority' => 2])
            ],

            'variable.register' => new Rule(new RegexMatcher('/\b('.implode('|', $this->registers).')\b/i')),
            'number' => new Rule(new RegexMatcher('/\b(-?[0-9][0-9a-fA-F]*[tTdDhHOoqQbByY]?)\b/i')),
            'operator' => [
                'punctuation' => new Rule(new RegexMatcher('/(,)/'), ['priority' => 0]),
                new Rule(new RegexMatcher('/([*+-])/'), ['priority' => 0]),
            ],
        ]);
    }
152793
def main(args):
  
  print_in_box('Validating submission ' + args.submission_filename)
  random.seed()
  temp_dir = args.temp_dir
  delete_temp_dir = False
  if not temp_dir:
    temp_dir = tempfile.mkdtemp()
    logging.info('Created temporary directory: %s', temp_dir)
    delete_temp_dir = True
  validator = submission_validator_lib.SubmissionValidator(temp_dir,
                                                           args.use_gpu)
  if validator.validate_submission(args.submission_filename,
                                   args.submission_type):
    print_in_box('Submission is VALID!')
  else:
    print_in_box('Submission is INVALID, see log messages for details')
  if delete_temp_dir:
    logging.info('Deleting temporary directory: %s', temp_dir)
    subprocess.call(['rm', '-rf', temp_dir])
486246
def store_rule(self, rule_id, rule):
        
        if rule_id not in self.rules:
            self.rules[rule_id] = rule
            self.rule_cnt += 1
399414
def make_student(user):
    '''
    
    '''
    tutor_group, owner_group = _get_user_groups()
    user.is_staff = False
    user.is_superuser = False
    user.save()
    owner_group.user_set.remove(user)
    owner_group.save()
    tutor_group.user_set.remove(user)
    tutor_group.save()
651740
def top_submitters(self, num):
        """"""
        num = min(num, len(self.submitters))
        if num <= 0:
            return ''

        top_submitters = sorted(
            iteritems(self.submitters),
            key=lambda x: (-sum(y.score for y in x[1]),
                           -len(x[1]), str(x[0])))[:num]

        retval = self.post_header.format('Top Submitters\' Top Submissions')
        for (author, submissions) in top_submitters:
            retval += '1. {}, {} submission{}: {}\n'.format(
                self._points(sum(x.score for x in submissions)),
                len(submissions),
                's' if len(submissions) != 1 else '', self._user(author))
            for sub in sorted(
                    submissions, key=lambda x: (-x.score, x.title))[:10]:
                title = self._safe_title(sub)
                if sub.permalink in sub.url:
                    retval += tt('  1. {}').format(title)
                else:
                    retval += tt('  1. [{}]({})').format(title, sub.url)
                retval += ' ({}, [{} comment{}]({}))\n'.format(
                    self._points(sub.score), sub.num_comments,
                    's' if sub.num_comments != 1 else '',
                    self._permalink(sub))
            retval += '\n'
        return retval
915709
def graded_submissions(self):
        '''
            
        '''
        qs = self._valid_submissions().filter(state__in=[Submission.GRADED])
        return qs
769090
def apply(self):
        """"""
        user_type = self.rb_choice.get()
        if user_type == 'student' or user_type == 'tutor':
            self.result = user_type
94383
def _set_rules(self, rules: dict, overwrite=True):
        """"""

        if not isinstance(rules, dict):
            raise TypeError('rules must be an instance of dict or Rules,'
                            'got %r instead' % type(rules))

        if overwrite:
            self.rules = Rules(rules, self.default_rule)
        else:
            self.rules.update(rules)
1001685
function(rules) {
      return _.some(rules, function(rule) {
        return _.some(rule.resources, function(resource) {
          return checkResource(resource) && !_.isEmpty(_.intersection(rule.verbs ,(["*", "create", "update"])));
        });
      });
    }
819739
def your_tips_on_tip_submission_form(context):
    
    context = copy(context)
    site_main = context['request'].site.root_page

    most_recent_tip = (YourTipsArticlePage.objects
                       .descendant_of(site_main)
                       .order_by('-latest_revision_created_at')
                       .first())

    most_popular_tip = (YourTipsArticlePage.objects
                        .descendant_of(site_main)
                        .filter(votes__gte=1)
                        .order_by('-total_upvotes')
                        .first())

    context.update({
        'most_popular_tip': most_popular_tip,
        'most_recent_tip': most_recent_tip,
        'your_tip_page_slug': get_your_tip(context).slug
    })
    return context