Skip to content

Instantly share code, notes, and snippets.

View d0t15t's full-sized avatar

Isaac Bigsby Trogdon d0t15t

View GitHub Profile
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
@mattschaff
mattschaff / ExampleCrudAdminForm.php
Created December 12, 2019 22:31
Drupal 8: CRUD admin form (AJAX add, delete)
<?php
namespace Drupal\example\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Implements hook_entity_base_field_info().
*
* - Provides a base field that displays the current workflow state on nodes.
* This field is intended to be used to expose this information.
*/
function state_machine_workflow_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
/** @var \Drupal\state_machine_workflow\WorkflowHelper $workflowHelper */
@slivorezka
slivorezka / get_image_path_with_image_style.php
Created November 8, 2016 10:40
Drupal 8: Get Image URL / URI with Image Style
<?php
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
// File ID.
$fid = 123;
// Load file.
$file = File::load($fid);
// Get origin image URI.
$image_uri = $file->getFileUri();
// Load image style "thumbnail".
@JeffTomlinson
JeffTomlinson / MyService.php
Last active December 22, 2021 07:49
Drupal 8 Logger Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Logger\LoggerChannelFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services
@leymannx
leymannx / drupal_8_menu_get_object.php
Created August 19, 2016 11:38
Drupal 8 menu get object
<?php
$node = Drupal::request()->attributes->get('node');
?>
@nkgokul
nkgokul / drush_sql_dump_with_timestamp.sh
Last active March 29, 2019 13:36
Drush SQL dump with timestamp
drush sql-dump > project_dev1.$(date +%Y%m%d\-%H%M).sql
drush sql-dump > ${PWD##*/}-$(date +%Y-%m-%d\-%H-%M).sql
@simplethemes
simplethemes / youtube-url.php
Created November 21, 2013 23:00
Extracts YouTube video ID from various URL structures
<?php
$url = array (
'http://youtu.be/dQw4w9WgXcA',
'http://www.youtube.com/embed/dQw4w9WgXcB',
'http://www.youtube.com/watch?v=dQw4w9WgXcC',
'http://www.youtube.com/?v=dQw4w9WgXcD',
'http://www.youtube.com/v/dQw4w9WgXcE',
'http://www.youtube.com/e/dQw4w9WgXcF',
'http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcG',
@juampynr
juampynr / mymodule.info
Last active June 9, 2023 21:53
Drupal 7 Views 3 custom field handler
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc
@nery
nery / jQueryGeoIp.js
Created January 25, 2013 18:14
A ajax call to get a postal code from a geo location
var getLocation = function() {
if (navigator.geolocation) {
//get current position and pass the results to getPostalCode
return navigator.geolocation.getCurrentPosition();
} else {
return false;
}
};