$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);
$block_manager = \Drupal::service('plugin.manager.block');
#!/usr/bin/php | |
<?php | |
/** | |
* @file | |
* A Git pre-commit hook script to check files for PHP syntax errors and Drupal | |
* coding standards violations. Requires phpcs and Coder Sniffer: | |
* | |
* @see https://drupal.org/node/1419988 | |
* |
var elements = document.getElementsByTagName("*"); // Grab all elements, since the actual note content elements have no ID are seemingly randomly generated class IDs | |
var keepTitle = []; | |
var keepContent = []; | |
var x = 0; | |
for (var i=0; i < elements.length; i++) { // Loop through all elements | |
if (elements[i].hasAttribute("contenteditable") && elements[i].getAttribute("contenteditable") == "false") { // Elements with 'contenteditable' attr set to false in the Keep page are fortunately only note title and contents | |
if (x % 2 == 0) { // Simple means of separating title from contents | |
if (elements[i].innerHTML == "") { // Make it clear if the field was empty | |
keepTitle.push("(empty)"); | |
} |
I implemented for my own use case - not fully tested - use at your own risk
This is how I improved performance of django-import-export
when importing a large set of new rows.
#!/bin/bash | |
# Raspberry Pi stress CPU temperature measurement script. | |
# | |
# Download this script (e.g. with wget) and give it execute permissions (chmod +x). | |
# Then run it with ./pi-cpu-stress.sh | |
# | |
# NOTE: In recent years, I've switched to using s-tui. See: | |
# https://github.com/amanusk/s-tui?tab=readme-ov-file#options | |
# Variables. |
get current user in drupal 8 | |
Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code. | |
$current_user = \Drupal::currentUser(); | |
$uid = $current_user->id(); | |
It returns user id of current user. | |
$user_mail = $current_user->getEmail(); | |
It returns user email id. |
#!/bin/bash | |
# https://retropie.org.uk/forum/topic/2295/runcommand-warning-if-voltage-temperature-throttling | |
#Flag Bits | |
UNDERVOLTED=0x1 | |
CAPPED=0x2 | |
THROTTLED=0x4 | |
HAS_UNDERVOLTED=0x10000 | |
HAS_CAPPED=0x20000 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> | |
<a href="whatsapp://send?phone=14384766790" class="float" target="_blank"> | |
<i class="fa fa-whatsapp my-float"></i> | |
</a> |
#!/usr/bin/env bash | |
# Install libaries | |
cd /var/www/backend | |
virtualenv -p python3 venv | |
source venv/bin/activate | |
pip install -r requirements.txt | |
python manage.py migrate | |
python manage.py collectstatic --no-input |
# https://hakibenita.com/how-to-turn-django-admin-into-a-lightweight-dashboard | |
from django.contrib import admin | |
from django.db.models import Count, Sum, Min, Max, DateTimeField | |
from django.db.models.functions import Trunc | |
from . import models | |
def get_next_in_date_hierarchy(request, date_hierarchy): |