Skip to content

Instantly share code, notes, and snippets.

@aallan
aallan / throttled.sh
Last active May 11, 2025 18:07
Script to parse the output of the 'vcgencmd get_throttled' command on a Raspberry Pi
#!/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
@radheymkumar
radheymkumar / Get current user in drupal 8
Created October 18, 2019 04:24
Get current user in drupal 8
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.
@geerlingguy
geerlingguy / pi-cpu-stress.sh
Last active October 12, 2025 21:09
Raspberry Pi CPU temperature and throttling test script
#!/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.
@matthewhegarty
matthewhegarty / django-import-export-bulk-import.md
Last active November 18, 2024 22:03
Performance improvements for `django-import-export` bulk import

Performance improvements for bulk import

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.

  • Thinkpad T470 i5 processor (Ubuntu 18.04)
  • 20,000 new rows to be inserted
  • total import duration 5.4 seconds
@einichi
einichi / export-keep.js
Last active May 1, 2022 18:02
Exports Google Keep notes to CSV (text only), run in JS console when on keep.google.com
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)");
}
@davidjguru
davidjguru / Blocks.md
Created November 12, 2020 17:47 — forked from bdlangton/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@bserem
bserem / pre-commit
Created April 10, 2021 10:54
Run phpcs in ddev with Drupal standard on pre-commit.
#!/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
*