public function beforeSave($insert)
{
if ($this->isNewRecord || $this->isAttributeChanged('password')) {
$this->password_hash = Yii::$app->security->generatePasswordHash($this->password);
}
if ($this->isNewRecord || $this->isAttributeChanged('refresh_token')) {
$salt = Yii::$app->security->generateRandomString();
$this->refresh_token_salt = $salt;
$this->refresh_token_hash = Yii::$app->security->generatePasswordHash($this->refresh_token . $salt);
}
return parent::beforeSave($insert);
}
public function actionRefresh()
{
$refresh_token = Yii::$app->request->headers->get('Authorization');
$refresh_token = substr($refresh_token, 7);
$decoded = User::getUserDataFromJWT($refresh_token);
$user = User::find()
->where(['id' => $decoded->data->user_id])
->one();
if ($user && $user->refresh_token_salt) {
$refresh_token_hash = Yii::$app->security->generatePasswordHash($refresh_token . $user->refresh_token_salt);
if (Yii::$app->security->validatePassword($refresh_token_hash, $user->refresh_token_hash)) {
// Refresh token is valid
}
}
}
$arResult["PROPERTIES"]["articlesAuthor"]
вместо массива $arResult["PROPERTIES"]["articlesAuthor"]["VALUE"]
.<?foreach ($arResult["PROPERTIES"]["articlesAuthor"]["VALUE"] as $articlesID):?>
<?
$res = CIBlockElement::GetByID($articlesID);
if($ar_res = $res->GetNext()): ?>
<img src="<?=CFile::GetPath($ar_res["PREVIEW_PICTURE"]);?>" title=""/>
<?endif;?>
<?endforeach;?>
CREATE INDEX idx_created_at ON your_table_name (created_at);
SELECT * FROM table_name
WHERE created_at < (SELECT created_at FROM table_name WHERE id = :last_id)
ORDER BY created_at DESC
LIMIT 1000;
public function getFilesGenres() {
$files = scandir(__DIR__.'/genres');
$config = config('songscrud.genres.langs');
$resultArray = [];
foreach($config as $lang) {
foreach ($files as $file) {
if(preg_match('/\.(php)/', $file)) {
$path = __DIR__.'/genres/' . $file;
$ext = pathinfo($file, PATHINFO_FILENAME);
if ($lang === $ext) {
$array = require($path);
$resultArray = array_merge($resultArray, $array);
}
}
}
}
return $resultArray;
}
type Account interface {
GetBalance() Monetary
}
type account struct {
b Monetary
}
func (a *account) GetBalance() Monetary {
return a.b
}
func NewAccount() *account {
return &account{
b: &balance{},
}
}
func main() {
var acc Account = NewAccount()
fmt.Println(acc)
}
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string s;
int q;
cin >> s >> q;
vector<int> l(q), r(q), k(q);
for (int i = 0; i < q; ++i) {
cin >> l[i] >> r[i] >> k[i];
}
for (int i = q - 1; i >= 0; --i) {
string t = s.substr(l[i] - 1, r[i] - l[i] + 1);
s.erase(l[i] - 1, r[i] - l[i] + 1);
if (k[i] == 0) {
s = t + s;
} else {
s.insert(k[i] - 1, t);
}
}
cout << s << endl;
return 0;
}
(?=(слово\s*.*?))"(?=\n*.*»)
использует positive lookahead, чтобы найти первую двойную кавычку после слова "слово", за которой следует символ переноса строки, а затем где-то далее в тексте находится символ «. Она не заменяет текст, а только находит первую двойную кавычку, соответствующую критериям.newText = newText.replace(/(слово\s*.*?)"(?=\n*.*»)/giu, function(match, group) {
return group + "«";
});
valChan
, но все горутины уже завершили свою работу. func scanFiles(file1, file2 *bufio.Scanner, config Config) {
scanWg := new(sync.WaitGroup)
scanWg.Add(2)
file1SubStrings := make(map[string]string)
file2SubStrings := make(map[string]string)
go func() {
var substr []string
for file1.Scan() {
substr = strings.Split(file1.Text(), ":")
if len(substr) > 0 {
file1SubStrings[substr[1]] = substr[0]
}
}
scanWg.Done()
}()
go func() {
var substr []string
for file2.Scan() {
substr = strings.Split(file2.Text(), ":")
if len(substr) > 0 {
file2SubStrings[substr[0]] = substr[1]
}
}
scanWg.Done()
}()
scanWg.Wait()
if file2SubStrings != nil && file1SubStrings != nil {
wg := new(sync.WaitGroup)
valChan := make(chan struct{ k, v string })
for i := 0; i < config.Count_check; i++ {
wg.Add(1)
go findIntersections(valChan, file2SubStrings, wg, config)
}
for k, v := range file1SubStrings {
valChan <- struct{ k, v string }{k: k, v: v}
}
close(valChan)
wg.Wait()
}
}
SELECT * FROM `first` as t1
LEFT JOIN `second` as t2 ON t1.id COLLATE utf8_unicode_ci = t2.number_id COLLATE utf8_unicode_ci;
const div = document.querySelector("echo");
const ws = new WebSocket("ws://localhost:2346");
document.addEventListener('keydown', function(){
ws.send(JSON.stringify("123"));
});
ws.onmessage = response => {
let data = JSON.parse(response.data);
console.log(data);
}
<?php
use Workerman\Worker;
require_once __DIR__ . "/vendor/autoload.php";
$wsWorker = new Worker("websocket://0.0.0.0:2346");
$wsWorker->count = 4;
$wsWorker->onConnect = function($con){
echo "подключен";
};
$wsWorker->onMessage = function($con, $data) {
// Вместо отправки ответа всем подключенным пользователям отправляем его только тому, кто сделал запрос
$con->send($data);
};
$wsWorker->onClose = function($con){
echo "отключен";
};
Worker::runAll();
?>
for k, v := range z {
x[k] += v
}
func sumMaps(maps ...map[types.Category]int) map[types.Category]int {
result := make(map[types.Category]int)
// складываем значения из всех map-ов
for _, m := range maps {
for k, v := range m {
result[k] += v
}
}
return result
}
result := sumMaps(map1, map2, map3)
lst = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
result = [list(x) for x in zip(*lst)]
for row in result:
print(' '.join(row))
const Container = styled.div`
max-width: 370px;
@media (max-width: 370px) {
/* Стили для контейнера, если ширина <= 370px */
}
@media (max-width: 314px) {
/* Стили для контейнера, если ширина <= 314px */
}
@media (max-width: 270px) {
/* Стили для контейнера, если ширина <= 270px */
}
`;
const Header = styled.div`
height: 180px;
@media (max-width: 370px) {
height: 150px;
}
@media (max-width: 314px) {
height: 120px;
}
@media (max-width: 270px) {
height: 90px;
}
`;
<Container>
<Header />
</Container>