Skip to content

Instantly share code, notes, and snippets.

View skounis's full-sized avatar

Stavros Kounis skounis

View GitHub Profile
@skounis
skounis / access.php
Created April 2, 2021 04:56
Access a variable in the parent scope from an anonymous function in PHP
$result = '';
fetch("SELECT title FROM tbl", function($r) use (&$result) {
$result .= $r['title'];
});
@skounis
skounis / www-do.sh
Created April 2, 2021 04:52
Run commands as www-data
sudo -u www-data /var/push.sh
@skounis
skounis / www-keys.sh
Created April 2, 2021 04:51
Assign the user www-data an SSH key
sudo mkdir /var/www/.ssh
sudo chown -R www-data /var/www/.ssh
sudo -u www-data ssh-keygen -t rsa
@skounis
skounis / untrack.sh
Created April 2, 2021 04:48
Git Untrack LFS files
git lfs untrack '<file-type>'
git rm --cached '<file-type>'
git add '<file-type>'
git commit -m "restore '<file-type>' to git from lfs"
@skounis
skounis / salt.sh
Created February 5, 2021 11:25
Generate a hash_salt with drush
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@skounis
skounis / field_value.php
Created August 27, 2020 09:51
To extract the field value in Drupal 8
// We can go the long way
$field = $group->some_field->first();
// then
$reference_entity_id = $field->getValue()['target_id'];
// But there is a better way to do it
$reference_entity_id = $group->some_field->target_id;
// The same way we can extract simple types, like string and integer
@skounis
skounis / one-time-logins.sh
Last active August 4, 2020 13:55
On time login links for all the users. Drupal
for uid in $(drush sqlq "SELECT uid FROM users"); do drush user:login --uid=$uid; done
@skounis
skounis / preprocess_links__language_block.php
Last active September 11, 2023 12:54
Drupal - Preprocess language links
<?php
phpinfo();
function fut_content_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'comment') {
if (_fut_content_prevent_comments()) {
unset($variables['comment_form']);
}
}
}
function fut_content_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {