Skip to content

Instantly share code, notes, and snippets.

View attitude's full-sized avatar

Martin Adamko attitude

View GitHub Profile
@attitude
attitude / Installing Composer for production.md
Created March 21, 2024 09:41
Installing Composer for production

Q: I only have access to production via FTP. Is there an option how to install vendor packages via Composer for production?

A: Yes, you can install vendor packages via Composer for production, but it's not recommended to do it directly on the production server, especially if you only have FTP access. The recommended way is to do it locally or in a CI/CD pipeline, and then upload the vendor directory along with your application code to the production server.

Here are the steps:

  1. Run composer install --no-dev --optimize-autoloader on your local machine or in your CI/CD pipeline. This command will install only the packages required for production and optimize the autoloader for better performance.
  2. Upload the entire application, including the vendor directory, to your production server using FTP.

If you absolutely must run Composer directly on your production server and you have SSH access, you can run the composer install --no-dev --optimize-autoloader command directly on the server. However,

@attitude
attitude / chr_word.php
Created March 20, 2024 17:21
Converts an integer to a string by mapping each byte to its corresponding ASCII character.
<?php declare(strict_types = 1);
/**
* Converts an integer to a string by mapping each byte to its corresponding ASCII character.
* @license MIT
*
* @param int $int The integer to convert.
* @return string The resulting string.
* @throws \RangeException If the decoded character is out of the valid ASCII range (33-126).
*/
@attitude
attitude / word_ord.php
Created March 20, 2024 17:20
Converts a string to an integer by calculating the sum of the ASCII values of its characters.
<?php declare(strict_types = 1);
/**
* Converts a string to an integer by calculating the sum of the ASCII values of its characters.
* @license MIT
*
* @param string $string The input string to convert.
* @return int The resulting integer value.
* @throws \RangeException If the input string to encode contains an invalid character.
*/
@attitude
attitude / currentGitHash.php
Created March 18, 2024 09:58
Retrieves the current Git hash for a given .git path.
<?php
/**
* Retrieves the current Git hash for a given .git path.
*
* @param string $dotGitPath The path to the .git directory or file.
* @return string The current Git hash.
* @throws \ErrorException If there is an error reading the .git path or its contents.
*/
function currentGitHash(string $path): string {
We can't make this file beautiful and searchable because it's too large.
"additionalInfo/Accessibility/0/Wheelchair accessible entrance","additionalInfo/Accessibility/1/Wheelchair accessible parking lot","address","categories/0","categories/1","categoryName","checkInDate","checkOutDate","cid","city","claimThisBusiness","countryCode","description","googleFoodUrl","hotelDescription","hotelReviewSummary","hotelStars","imageCategories/0","imageCategories/1","imageCategories/2","imageCategories/3","imageCategories/4","imagesCount","isAdvertisement","locatedIn","location/lat","location/lng","menu","neighborhood","openingHours/0/day","openingHours/0/hours","openingHours/1/day","openingHours/1/hours","openingHours/2/day","openingHours/2/hours","openingHours/3/day","openingHours/3/hours","openingHours/4/day","openingHours/4/hours","openingHours/5/day","openingHours/5/hours","openingHours/6/day","openingHours/6/hours","peopleAlsoSearch/0/category","peopleAlsoSearch/0/reviewsCount","peopleAlsoSearch/0/title","peopleAlsoSearch/0/totalScore","peopleAlsoSearch/1/category","peopleAlsoSearch/1/re
@attitude
attitude / parseRGB.ts
Created April 1, 2022 09:13
Parses RGB string and returns tuple [R: number, G: number, B: number]
const RGB_VALUES_REGEX = new RegExp(/(rgba?)\((.+)\)/)
function parseRGBStrict(color: string): [number, number, number] | [number, number, number, number] {
const matches = color.match(RGB_VALUES_REGEX)
if (!matches) {
throw new Error("No RGB color string");
}
const scheme = matches[1]
@attitude
attitude / idealLuminanceAtIndex.ts
Created April 1, 2022 08:37
Reverse function of WCAG 2.0 that returns ideal Luminance of colour at current index (to be used with Array.map)
// Contrast ratio formula:
// (L1 + 0.05) / (L2 + 0.05), where
// L1 is the relative luminance of the lighter of the foreground or background colors, and
// L2 is the relative luminance of the darker of the foreground or background colors.
function idealLuminanceAtIndex(index: number, colorsCount: number) {
const exponent = (1 - (index * 1 / (colorsCount - 1)))
return (Math.pow(colorsCount, exponent) * 0.05 - 0.05) / (colorsCount - 1) * 20
}
@attitude
attitude / useOuterRef.ts
Created October 6, 2021 12:59
React: Use forwardRef with useRef
import { ForwardedRef, MutableRefObject, useEffect, useRef } from 'react'
function useOuterRef(outerRef: ForwardedRef<HTMLElement | null>): MutableRefObject<HTMLElement | null> {
const innerRef = useRef<HTMLElement | null>(null)
useEffect(() => {
if (!outerRef) return
if (typeof outerRef === 'function') {
outerRef(innerRef.current)
@attitude
attitude / Runnig PHP v5.3 in MAMP.md
Created July 17, 2013 16:24
You can run current version of MAMP with PHP 5.4.4 or 5.2.17. How to run 5.3+

Introduction

Lately I needed to test some code against PHP version 5.3 wich is (hopefully not forever) the highest supported version on one of my clients hosting right now. To cut the story short, I develop and test on a local MAMP server, usualy for PHP v5.4+. The free version of MAMP will let you run either v5.4.4 or v5.2.17 of PHP. To run other version you need to purchase MAMP Pro. But I haven't read/heard a single person saing about MAMP Pro worth its price tag.

Setup

My MAMP installation comes with many PHP versions preinstalled. See /Applications/MAMP/conf (Cmd+G), but you can swich only between two: the lowest and the heighest version of PHP. No option between. There are these versions in my MAMP/conf folder:

@attitude
attitude / composer.json
Last active May 7, 2021 18:48
Function to generate a slug (a normalized URL sanitized string)
{
"name": "attitude/generate_slug",
"autoload": {
"files": ["function-generate_slug.php"]
}
}