Skip to content

Instantly share code, notes, and snippets.

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

Oleksii Abrosymov amberlex78

🏠
Working from home
View GitHub Profile
function greet(person: string, date: Date): void {
console.log(`Hello, ${person}! Today is ${date.toDateString()}.`);
}
const getFullName = (first: string, last?: string): string =>
last ? `${first} ${last}` : `${first}`;
let fullName = getFullName("John");
greet(fullName, new Date());
@amberlex78
amberlex78 / object-mutation.js
Last active February 19, 2024 00:16
Object Mutation in Javascript
const user = {
age: 22,
gender: 'male',
address: {
city: 'Kyiv'
}
}
// Copying objects
const user2 = user; // assignment of reference
@amberlex78
amberlex78 / app.js
Last active October 24, 2023 06:57
dark-light switcher
(() => {
'use strict';
// Функция для работы с localStorage
const getStoredValue = (key, defaultValue) => localStorage.getItem(key) || defaultValue;
const setStoredValue = (key, value) => localStorage.setItem(key, value);
// Функции для установки фронт-темы и фронт-иконки
const setFrontTheme = theme => document.documentElement.setAttribute('data-bs-theme', theme);
const setFrontThemeIcon = themeIcon => document.querySelector('#themeIcon').setAttribute('xlink:href', themeIcon);
@amberlex78
amberlex78 / num_2_words.php
Last active June 11, 2023 15:03
Преобразование количества "цифрой" в количество "словом"
/**
* Преобразование количества "цифрой" в количество "словом"
* Чтобы было удобнее формировать массивы со склонениями, запомните ряд чисел 1-2-5,
* а потом мысленно подставляйте их в массив: (один "рубль", два "рубля", пять "рублей")
* $num = 3;
* $words = array('новость', 'новости', 'новостей');
* echo $num . ' ' . num_2_word($num, $words); // сколько новостей
*
* @param $n
* @param $words
@amberlex78
amberlex78 / Dockerfile
Created March 17, 2023 05:46
py-hello-word-docker
FROM python:3.9-alpine
RUN mkdir /app
WORKDIR /app
COPY . /app
CMD ["python", "app.py"]
@amberlex78
amberlex78 / BladeServiceProvider.php
Last active January 21, 2022 18:39
Example BladeServiceProvider with Form::component-s for Laravel with laravelcollective
<?php
class BladeServiceProvider extends ServiceProvider
{
public function boot(): void
{
Form::component('bsText', 'collective.form.text', [
'label', 'name', 'value' => null, 'attributes' => []
]);
@amberlex78
amberlex78 / PostFetcher.php
Last active December 15, 2021 07:55
Symfony 5.4: Get all posts ids by slug of tag
<?php
namespace App\ReadModel\Blog;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
class PostFetcher
{
public function __construct(
@amberlex78
amberlex78 / AjaxController.php
Last active December 15, 2021 08:02
Symfony 5.4, PHP 8: Change bool status with error handling
<?php
namespace App\Controller\Admin;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@amberlex78
amberlex78 / mysql_version.php
Last active December 15, 2021 07:52
Laravel: Get mysql version
<?php
$v = \DB::select("select version()")[0]->{"version()"};
$v = explode('-', $v)[0];
@amberlex78
amberlex78 / display_query_or_log.md
Created August 9, 2020 07:36
Display or log query

Display or log query

Display query

Add code in a file:

\DB::enableQueryLog();

$user = App\User::get();