package main
import (
"context"
"fmt"
"github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
"log"
"time"
)
var (
dir = "ПАПКА_КУДА_СОХРАНЯЮТСЯ_COOKIE"
domain = "https://freebitco.in/"
wait = 3
login = true //Выставить в false, после авторизации
)
func main() {
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.DisableGPU,
chromedp.NoDefaultBrowserCheck,
chromedp.Flag("enable-automation", true),
chromedp.Flag("use-mock-keychain", true),
chromedp.Flag("headless", !login),
chromedp.Flag("no-first-run", true),
chromedp.Flag("no-sandbox", true),
chromedp.Flag("ignore-certificate-errors", true),
chromedp.Flag("user-data-dir", dir),
)
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
taskCtx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf))
defer cancel()
if err := chromedp.Run(taskCtx); err != nil {
panic(err)
}
var reward string
err := chromedp.Run(taskCtx,
network.Enable(),
chromedp.Navigate(domain),
chromedp.Action(chromedp.ActionFunc(func(ctx context.Context) error {
time.Sleep(time.Duration(wait) * time.Second)
return nil
})),
chromedp.WaitVisible(`#play_without_captchas_button`),
chromedp.Click(`#play_without_captchas_button`, chromedp.NodeVisible),
chromedp.Action(chromedp.ActionFunc(func(ctx context.Context) error {
time.Sleep(time.Duration(wait) * time.Second)
return nil
})),
chromedp.Click(`#free_play_form_button`, chromedp.NodeVisible),
chromedp.Action(chromedp.ActionFunc(func(ctx context.Context) error {
time.Sleep(time.Duration(wait) * time.Second)
return nil
})),
chromedp.TextContent(`#winnings`, &reward),
)
if err != nil {
panic(err)
}
fmt.Println(reward)
}
<?php
$array = [
'text_1' => ['I am so clever that sometimes I do not underst'],
//'text_2' => ['It is better to be hated for what you are than f.'],
'text_3' => ['Whenever you find yourself on the .'],
'text_4' => ['Whenever you find yourself on the side of the majority.'],
'title_1' => ['Responsive design'],
'title_2' => ['Web development'],
'title_3' => ['Customer support'],
'title_4' => ['images included'],
'title_text_1' => ['Unexpected'], //Может и такое быть
'_edit_lock' => ['1570606503:1'],
'_thumbnail_id' => ['59'],
'_edit_last' => ['1'],
'single_image_1' => ['94'],
'single_image_2' => ['91'],
'single_image_3' => ['92'],
'single_image_4' => ['93'],
];
$prefixes = [];
$maxIndex = 0;
foreach (array_keys($array) as $key) {
$parts = explode('_', $key);
$index = array_pop($parts);
if (!is_numeric($index)) {
continue;
}
$prefixes[implode('_', $parts)] = null;
if ($index > $maxIndex) {
$maxIndex = $index;
}
}
$output = [];
$prefixes = array_keys($prefixes);
for ($index = 1; $index <= $maxIndex; $index++) {
$row = [];
foreach ($prefixes as $prefix) {
$key = "{$prefix}_{$index}";
$row[$key] = @$array[$key];
}
$output[] = $row;
}
var_dump($output);
<?php
interface IVisitor {
public function getResult();
public function visit(IShape $element): void;
}
interface IShape {
public function accept(IVisitor $visitor): void;
}
interface IArea extends IShape {
public function getArea(): float;
}
interface IFillColor extends IShape {
public function setFillColor(string $rgb);
public function getFillColor(): int;
}
trait TFillColor {
protected $fillColor = 0;
public function getFillColor(): int {
return $this->fillColor;
}
public function setFillColor(string $rgb) {
$this->fillColor = (int)hexdec($rgb);
}
}
class Line implements IArea {
protected $length;
public function __construct(float $length) {
$this->length = $length;
}
public function getArea(): float {
return $this->length;
}
public function accept(IVisitor $visitor): void {
$visitor->visit($this);
}
}
class Rectangle implements IShape, IFillColor {
use TFillColor;
protected $width;
protected $height;
public function __construct(float $width, float $height) {
$this->width = $width;
$this->height = $height;
}
public function getArea(): float {
return $this->width * $this->height;
}
public function accept(IVisitor $visitor): void {
$visitor->visit($this);
}
}
class Box {
/**@var IShape[] $shapes */
protected $shapes = [];
public function addShape(IShape $shape): self {
$this->shapes[] = $shape;
return $this;
}
public function executeVisitor(IVisitor $visitor) {
foreach ($this->shapes as $shape) {
$shape->accept($visitor);
}
return $visitor->getResult();
}
}
class TotalAreaWithColor implements IVisitor {
protected $total = 0;
protected $color;
public function __construct(int $color) {
$this->color = $color;
}
public function visit(IShape $element): void {
if ($element instanceof IFillColor && $element->getFillColor() === $this->color) {
$this->total += $element->getArea();
}
}
public function getResult() {
return $this->total;
}
}
$rect = new Rectangle(4, 10);
$rect->setFillColor("FF0000");
$line = new Line(10);
echo (new Box())
->addShape($rect)
->addShape($line)
->executeVisitor(new TotalAreaWithColor(hexdec("FF0000")));
$categories = [];
foreach($list as $row){
if ($row['parent_id'] == 0) {
continue;
}
$categories[$row['parent_id']][] = $row['name'];
}
foreach($categories as $names){
echo "<ul>";
foreach($names as $name){
echo "<li>{$name}</li>";
}
echo "</ul>";
}
<?php
class Response {
public function sendResponse(array $data) {
echo json_encode($data);
return true;
}
public function sendError(string $message) {
echo json_encode(['error' => $message]);
return false;
}
}
class ErrorHandler {
private $response;
public function __construct(Response $response) {
$this->response = $response;
}
public function handlerError($error_code, $message, $file = null, $line = null) {
if ($error_code) {
throw new Exception($message, $error_code);
}
return true;
}
public function handlerShutdown() {
$error = error_get_last();
if ($error) {
$this->handlerException(new Error($error['message'], $error['type']));
}
exit(0);
}
public function handlerException(Throwable $exception) {
if (ob_get_length()) {
ob_end_clean();
}
if (!headers_sent()) {
return $this->response->sendError($exception->getMessage());
}
return true;
}
}
$response = new Response();
$handler = new ErrorHandler($response);
register_shutdown_function([$handler, 'handlerShutdown']);
set_error_handler([$handler, 'handlerError']);
set_exception_handler([$handler, 'handlerException']);
#region Logic
$cnt = 0;
if ($cnt === 0) {
throw new Exception("Нулевое количество");
}
#endregion
$response->sendResponse([
'message' => "Всё окей"
]);
SELECT
p.product_id,
p.image
FROM oc_product_to_category c
INNER JOIN oc_product p ON p.product_id = c.product_id
AND p.image IS NOT NULL
WHERE c.id_categor = :categoryId
LIMIT 1
function fixArray($input){
$output = [];
foreach($input as $value){
if(preg_match("/^0(\d+.*$)/", $value, $match)){
$output[] = "0";
$output[] = $match[1];
}else{
$output[] = $value;
}
}
return $output;
}
$getPHPInfo = function () {
ob_start();
phpinfo();
$result = ob_get_contents();
ob_clean();
return $result;
};
echo "123 {$getPHPInfo()}";