Skip to content

Instantly share code, notes, and snippets.

@turnerd18
turnerd18 / HelloController.php
Created April 13, 2017 14:16
Drupal 8 example module to override page template from within a custom module
<?php
// goes in src/Controller/HelloController.php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
class HelloController extends ControllerBase {
public function content() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
}
@turnerd18
turnerd18 / stopwatch.py
Created November 6, 2020 22:04
Python stopwatch timing
tic = time.perf_counter()
products_json = [foo.to_json2() for foo in foos]
toc = time.perf_counter()
print(f"Hydrated foos: {toc - tic:0.4f} seconds")
https://pl.kotl.in/UacGP9iw3
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
val numbers = arrayOf(13,79,74,35,76,12,43,71,87,72,23,91,31,67,58,61,96,16,81,92,41,6,32,86,77,42,0,55,68,14,53,26,25,11,45,94,75,1,93,83,52,7,4,22,34,64,69,88,65,66,39,97,27,29,78,5,49,82,54,46,51,28,98,36,48,15,2,50,38,24,89,59,8,3,18,47,10,90,21,80,73,33,85,62,19,37,57,95,60,20,99,17,63,56,84,44,40,70,9,30)
val boards = arrayOf(