Skip to content

Instantly share code, notes, and snippets.

View palexandrite's full-sized avatar
🏠
Working from home

Alexander Bulatov palexandrite

🏠
Working from home
View GitHub Profile
@palexandrite
palexandrite / README.md
Created July 25, 2023 13:44 — forked from njvack/README.md
Color to hex and rgba converter

Simple canvas-based color converter

To answer this StackOverflow question I wrote this — a small solution based on a never-rendered <canvas> element. It fills a 1-pixel canvas with the provided fill-style, and then reads the RGBA values of that pixel. It will work with any CSS color -- name, rgba(), hex, or even something more exotic like a gradient or pattern. Invalid colors are always returned as transparent black. Transparent colors are treated as painted on a newly-cleared canvas.

It's been tested in modern-ish versions of IE, Chrome, Safari, and Firefox. The API is:

color_convert.to_hex(color)   # Converts color to a hex-based RGB triple; to_hex('red') returns '#ff0000'
color_convert.to_rgba(color)  # Converts color to an rgba() string; to_rgba('red') returns 'rgba(255,0,0,1)'
@palexandrite
palexandrite / index.php
Last active April 11, 2023 08:13
How to pluralize words by PHP and find an array with max set of values when we use only 0 and 1.
<?php
$array = [
[0, 0, 0, 1],
[0, 0, 1, 1],
[0, 1, 1, 1],
[1, 1, 1, 1]
];
function find($arr)
@palexandrite
palexandrite / index.php
Created April 11, 2023 08:10
Some PHP notes about new features in PHP 7.
<?php
/**
* The new feature of the list function
*/
class Foo {
public $name;
public $email;
public function __construct($arr)
@palexandrite
palexandrite / index.html
Created April 11, 2023 07:53
Upload files on a server side. Using PHP without any checks and libs.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Страница с примером передачи переменных с помощью Post</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post"> <!--для сервера-->
@palexandrite
palexandrite / jQuery - Serialize Form with File inputs
Last active January 11, 2022 10:25 — forked from oswaldoacauan/gist:7580474
jQuery - Serialize Form with File inputs
(function($) {
$.fn.serializeFiles = function() {
var form = $(this),
formData = new FormData()
formParams = form.serializeArray();
$.each(form.find('input[type="file"]'), function(i, tag) {
$.each($(tag)[0].files, function(i, file) {
formData.append(tag.name, file);
});
@palexandrite
palexandrite / SplClassLoader.php
Created September 27, 2018 15:36 — forked from jwage/SplClassLoader.php
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<?php
$html = $_POST['html'];
// Заголовки в верхнем регистре
$html = preg_replace_callback(
'(<h([1-6])>(.*?)</h\1>)',
function ($m) {
return "<h$m[1]>" . strtoupper($m[2]) . "</h$m[1]>";
},
$html
базовые команды
git clone адрес репозитория - клонировать репозиторий на локальный компютер
git commit -m 'initial commit' комит изменений в локальный репозиторий
git push -u origin master - только первый раз отправка изменений в удаленный репозиторий
git push - все последующие разы отправка изменений в удаленный репозиторий
окат изменений
git pull - скачивается актуальная версия удаленного репозитория и все изменения применяются к локальному репозиторию
checkout - перейти в другую ветку
discard - не отправлять в репозиторий те изменения которые нам не нравятся