...
enum ResultCode {
RESULT_CODE_CHROME_START = content::RESULT_CODE_LAST_CODE,
// An invalid command line url was given.
RESULT_CODE_INVALID_CMDLINE_URL = RESULT_CODE_CHROME_START,
// The process is of an unknown type.
RESULT_CODE_BAD_PROCESS_TYPE,
// A critical chrome file is missing.
...
export interface SessionInterface {
bot: BotInterface;
state: SessionStateInterface;
initialState: SessionStateInterface;
SID: string;
isNew: boolean;
inDialog: boolean;
user: UserInterface;
send(message: any, options?: any): Promise<any>;
resetState(): void;
setState(state: SessionStateInterface): void;
}
export interface SessionStateInterface {
[key: string]: any;
}
interface SessionConstructorPropsInterface {
bot: BotInterface;
initialState?: SessionStateInterface;
}
export class Session implements SessionInterface {
bot: BotInterface;
user: UserInterface;
state: SessionStateInterface;
initialState: SessionStateInterface;
SID: string;
isNew: boolean;
inDialog: boolean;
constructor({ bot, initialState }: SessionConstructorPropsInterface) {
this.isNew = true;
this.bot = bot;
this.initialState = initialState || {};
this.state = Object.assign({}, initialState);
}
send(message: any, options: any): Promise<void> {
this.isNew = false;
return this.bot.adapter.send(message, options);
}
resetState(): void {
this.state = Object.assign({}, this.initialState);
}
setState(state: SessionStateInterface): void {
Object.keys(state).forEach((key) => {
this.state[key] = state[key];
});
}
}
main.use(/\/login/i, async ({message, session}: BotContextInterface, next) => {
// Здесь я сохраняю состояние
session.setState({
processLogin: true,
processLoginStep: 'login'
})
// Если мне нужно получить состояние
console.log(session.state.processLogin)
});
Array.prototype.splice(1)
//мой код
var notNormalString = 'эЙ, кАК деЛа?';
var littleString = notNormalString.toLowerCase();
littleString;
var littleStringSlice = littleString.slice(1);
var bigLetter = littleString[0];
bigLetter = bigLetter.toUpperCase();
var normalString = bigLetter + littleStringSlice;
console.log(normalString)
//конец моего кода
...
/*
** Customize the progress bar color
*/
loading: false,
modules: [],
...
Vue.use(Quasar, {
lang,
iconSet,
config: {
iconSet,
screen: {
bodyClasses: true
},
loadingBar: {
color: 'purple',
size: '0px',
position: 'bottom'
}
}
})
<?php
namespace App\Security\Administrator\Voter;
use App\Entity\User;
use App\Entity\UserGroup;
use Exception;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* Class UserVoter
* @package App\Security\Administrator\Voters
*/
class UserVoter extends Voter implements IVoter
{
public const CREATE_USERS = 'create_users';
public const EDIT_USERS = 'edit_users';
public const DELETE_USERS = 'delete_users';
public const VIEW_USERS = 'view_users';
public const VIEW_CONTACTS = 'view_contacts';
public const SET_PRIVILEGES_USERS = 'set_privileges_users';
/**
* @param string $attribute
* @param mixed $subject
* @return bool
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, $this->getAttributes())) {
return false;
}
return true;
}
/**
* @param string $attribute
* @param mixed $subject
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
$permissions = [];
try {
if (is_a($user->getGroup(), UserGroup::class)) {
$permissions = $user->getGroup()->getPermissions();
}
foreach ($permissions as $permission) {
if (in_array($permission, $this->getAttributes())) {
return true;
}
}
return false;
}catch (Exception $exception) {
return false;
}
}
/**
* @return string[]
*/
public function getAttributes()
{
return [
self::CREATE_USERS,
self::EDIT_USERS,
self::DELETE_USERS,
self::VIEW_USERS,
self::VIEW_CONTACTS,
self::SET_PRIVILEGES_USERS
];
}
}
...
$this->denyAccessUnlessGranted(UserVoter::CREATE_USERS, null, "Вам запрещено создавать пользователей.");
...
class UserVoter extends Voter implements IVoter
{
public const CREATE_USERS = 'create_users';
public const EDIT_USERS = 'edit_users';
public const DELETE_USERS = 'delete_users';
public const VIEW_USERS = 'view_users';
public const VIEW_CONTACTS = 'view_contacts';
public const SET_PRIVILEGES_USERS = 'set_privileges_users';
...
...
$permissions = [];
try {
if (is_a($user->getGroup(), UserGroup::class)) {
$permissions = $user->getGroup()->getPermissions();
}
foreach ($permissions as $permission) {
if (in_array($permission, $this->getAttributes())) {
return true;
}
}
return false;
}catch (Exception $exception) {
return false;
}
...
Чтобы вычислить процентное отношение чисел, нужно одно число разделить на другое и умножить на 100%. Число 12 составляет 40% от числа 30. Например, книга содержит 340 страниц. Вася прочитал 200 страниц.
pages = 340
read = 200
percent = (read / pages) * 100
procedure TMainForm.ButtonClick(Sender: TObject);
var
men: TMatchCollectionEnumerator;
begin
men := TRegEx.Matches('one two three', '\w+').GetEnumerator;
while men.MoveNext do
begin
men.Current.Value
end;
men.Free;
end;
$re = '/[eps]/m';
$str = 'help me please';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);