Skip to content

Instantly share code, notes, and snippets.

View edutrul's full-sized avatar
💭
Changing the world

Eduardo Telaya edutrul

💭
Changing the world
View GitHub Profile
void main() {
var a = 5;
var b = 11;
var result = a + b;
print(a);
print(b);
print("Este es el resultado: $result");
if (result % 2 == 0) {
print("$result es par");
@edutrul
edutrul / mymodule.module.php
Last active August 10, 2018 22:37
How to access node form fields in a hook_form_alter
<?php
$fieldPlus = 'field_layout_region2_icon';
$form[$fieldPlus]['widget']['#title'] = 'widget title';
$form[$fieldPlus]['widget'][0]['#title'] = 'widget 0 title';
$form[$fieldPlus]['widget'][0]['value']['#title'] = 'widget 0 value title';
// If something is printed first! then that should be the way to go.
dpm($form[$fieldPlus]['widget']);
@edutrul
edutrul / field_formatter_settings.php
Last active August 10, 2018 14:10
Get drupal field formatter settings
<?php
$entity_type = 'node';
$bundle = 'layout';
$field_name = 'field_layout_region1_items';
$setting_name = 'promo';
// Get selected view modes for bundle
$view_modes = \Drupal::service('entity_display.repository')
->getViewModeOptionsByBundle(
@edutrul
edutrul / deal_with_dates_in_php_and_drupal.php
Created June 13, 2018 05:05
Deal with dates in php and drupal 7
<?php
// Title: Convert to correct timezone.
// Set default time.
$date = new DateTime('2018-05-17 22:29:00', new DateTimeZone('UTC'));
print $date->format('Y-m-d H:i:s') . "\n"; // 2018-05-17 22:29:00
// Now convert to correct timestamp.
$date->setTimezone(new DateTimeZone('Australia/Brisbane'));
print $date->format('Y-m-d H:i:s') . "\n"; // 2018-05-18 08:29:00
// ----------------------------------------------------------------
@edutrul
edutrul / babies_main_dart_correct_google.dart
Created June 6, 2018 05:27
babies_main_dart_correct_google.dart (this is correct version rather than in https://codelabs.developers.google.com/codelabs/flutter-firebase/#8 )
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
const MyApp();
@override
Widget build(BuildContext context) {
@edutrul
edutrul / dar_class_example.dart
Created June 2, 2018 15:01
Dart class example
class Point {
// num is the parent class of `double` and `int`.
num x;
num y;
num z;
/**
* This is like
* Point(num x, num y, num z) {
this.x = x;
this.y = y;
@edutrul
edutrul / dart_first_steps.dart
Created June 2, 2018 14:01
Dart language first steps
var _nobleGases = [0, 1];
/* Short way for functions in a single line of code, for instance:
* bool isNoble(int atomicNumber) {
* return _nobleGases[atomicNumber] != null;
* }
* // Becomes:
* bool isNoble(int atomicNumber) => _nobleGases[atomicNumber] != null;
*/
bool isNoble(int atomicNumber) => _nobleGases[atomicNumber] != null;
@edutrul
edutrul / layoutuid_main.dart
Created May 20, 2018 05:22
layoutuid_main.dart
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Widget titleSection = new Container(
@edutrul
edutrul / index.php
Created April 18, 2018 23:25
webscrapping example
<?php
// mkdir webscrapping folder
// cd webscrapping
// Then run composer require fabpot/goutte
// then create index.php with below content
require __DIR__ . '/vendor/autoload.php';
@edutrul
edutrul / inAnyPartOrHookToUpdateOrSave.php
Created March 17, 2018 20:28
How to validate programmatically using a known constraint UniqueField
<?php
$data = [
'type' => 'article',
'title' => 'THis is an article test programmatically created',
'field_email' => [
'value' => '[email protected]'
]
];
$node = \Drupal::entityTypeManager()->getStorage('node')->create($data);
$violations = $node->validate();