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
@edutrul
edutrul / from_byte_array_image_to_display_browser.php
Last active February 15, 2023 18:37
PHP Convert byte array to php image and display to browser
<?php
// https://example.com/api/v1/file?id=8972893948981
// Displays the following json object:
// {"asset":{"file":{"data":[-119,80,78,71,13,10,26,10,0,0,0,13,73,,,,, etc
// Here's the php cone snippet to display to image in the browser.
$result = json_decode(file_get_contents($full_url));
$raw_png = implode(array_map('chr', $result->asset->file->data));
header('Content-Type: image/png');
print $raw_png;
die ($raw_png);
@edutrul
edutrul / download-a-file-in-drupal9-drupal8.php
Last active December 2, 2022 12:48
How to download a file programmatically using guzzle in Drupal 8 / Drupal 9
<?php
$external_file = 'https://www.example.com/test.png'
$destination = 'sites/default/files/a-directory/test.png';
/** @var GuzzleHttp\Psr\Response $response */
$response = \Drupal::httpClient()->get($external_file, ['sink' => $destination]);
// file gets downloaded under /sites/default/files/a-directory/test.png
@edutrul
edutrul / php-library-that-does-something.php
Created August 21, 2019 04:03
Php class library from Melissa
<?php
include_once dirname(__FILE__) . '/abstract_export_renderer.php';
abstract class AbstractWordRenderer extends AbstractExportRenderer
{
abstract protected function getGridPagePart();
public function RenderPage(Page $Page)
{
@edutrul
edutrul / privacy_policy_firefighters_peru.md
Created December 30, 2018 17:02
Privacy policy firefighters Perú

Privacy Policy

Eduardo Telaya built the Bomberos Perú app as a Free app. This SERVICE is provided by Eduardo Telaya at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Bomberos Perú unless otherwise defined in this Privacy Policy.

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;