Skip to content

Instantly share code, notes, and snippets.

View vyspiansky's full-sized avatar

Ihor Vyspiansky vyspiansky

View GitHub Profile
@vyspiansky
vyspiansky / twig-snippets.md
Last active May 3, 2024 12:12
Twig snippets (draft)

Twig snippets (draft)

Debug

Show variables

{{ dump() }}

{{ dump(user) }}
@vyspiansky
vyspiansky / set-user-agent-file_get_contents.php
Last active April 25, 2024 08:39
PHP: set user agent using file_get_contents()
<?php
$options = array('http' => array('user_agent' => 'custom user agent string'));
$context = stream_context_create($options);
$response = file_get_contents('http://domain/path/to/uri', false, $context);
@vyspiansky
vyspiansky / response_403_in_controller.php
Created April 18, 2024 13:08
Drupal: return a 403 response from a controller
<?php
namespace Drupal\your_module\Controller;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class YourController {
public function yourPage() {
// Some logic here...
@vyspiansky
vyspiansky / timezone-for-ukraine-in-php-8.md
Created April 12, 2024 07:05
Get a timezone for Ukraine in PHP 8+

To retrieve a timezone for Ukraine in PHP 8+

php -r "var_export(DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'UA'));"

Possible output:

array (
@vyspiansky
vyspiansky / simple-unsubscribe-successful-template.html
Created April 11, 2024 19:55
Unsubscribe successful HTML template
<html>
<head>
<title>Unsubscribe successful</title>
</head>
<body>
<h1>Unsubscribe successful</h1>
<p>Your email has been successfully unsubscribed from this list.</p>
</body>
</html>
@vyspiansky
vyspiansky / image-src-regexpr.php
Last active April 2, 2024 19:37
PHP: get image src attribute (regular expression)
<?php
// Source: http://goo.gl/qyLFbg
$html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />';
preg_match( '@src="([^"]+)"@' , $html, $match );
$src = array_pop($match);
// will return /images/image.jpg
@vyspiansky
vyspiansky / zip_folder_ignoring_redundant_files_on_mac.md
Last active February 11, 2024 09:36
Archive folder without redundant files using command line on macOS

Archive a folder without redundant files using the command line on macOS.

cd <folder_path>

where <folder_path> — a folder which should be archived.

zip -r .zip . -x "*.git*" -x "*.DS_Store"
@vyspiansky
vyspiansky / terminal_commands.md
Last active November 21, 2023 08:40
Terminal: useful commands

Some Terminal commands

Current user info

whoami

Give me your IP

@vyspiansky
vyspiansky / nodejs_start_new_project.md
Last active November 21, 2023 08:40
Start new Node.js project

How to start a new Node.js project:

npx license mit > LICENSE
npx gitignore node
npx covgen YOUR_EMAIL_ADDRESS
npm init -y

Source

@vyspiansky
vyspiansky / interleave_many_arrays.js
Last active November 21, 2023 08:39
JavaScript: interleave many arrays
// This function is quite flexible because it can handle any number of input arrays and
// doesn't require them to be of equal length. It interleaves as many elements as possible
// from each array, in the order that the arrays (and elements) were provided.
/**
* Interleaves elements of multiple arrays.
* The function takes any number of arrays as arguments.
*/
function interleaveArrays(...args) {
// Find the maximum length among all arrays