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 / MyModuleMenuLink.php
Created May 15, 2020 01:26
Menu item title dynamically based on user role.
@edutrul
edutrul / _readme.md
Created April 27, 2020 00:02 — forked from gka/_readme.md
PHP Endpoint for Github Webhook URLs

PHP Endpoint for Github Webhook URLs

If you love deploying websites using Github, but for some reason want to use your own server, this script might be exactly what you need.

  1. Put github.php somewhere on your PHP-enabled web server, and make it accessible for the outside world. Let's say for now the script lives on http://example.com/github.php
@edutrul
edutrul / README.md
Created April 26, 2020 19:54
Troubleshoot git webhook in Drupal 8

Make sure:

  • web/github/github.php has correct permissions

In github webhooks make sure you add domain

@edutrul
edutrul / git-php-webhook.php
Created April 26, 2020 17:07 — forked from marcelosomers/git-php-webhook.php
A basic webhook for deploying updates to repos on Github to your local server
<?php
/**
* This script is for easily deploying updates to Github repos to your local server. It will automatically git clone or
* git pull in your repo directory every time an update is pushed to your $BRANCH (configured below).
*
* Read more about how to use this script at http://behindcompanies.com/2014/01/a-simple-script-for-deploying-code-with-githubs-webhooks/
*
* INSTRUCTIONS:
* 1. Edit the variables below
* 2. Upload this script to your server somewhere it can be publicly accessed
@edutrul
edutrul / replace_image_src.php
Last active March 9, 2020 16:12
Replace image src -- Drupal
$html = '<img src="/stories/archives/2020/january/images/example-an-image.jpg">';
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
$new_src = 'sites/{site_name}/files';
$new_html = preg_replace('(src="(.*?)")','src="' . $new_src . '$1"', $html);
print $new_html;
// Outputs: "<img src="sites/{site_name}/files/stories/archives/2020/january/images/example-an-image.jpg">"
@edutrul
edutrul / from_byte_array_image_to_download_file.php
Last active March 2, 2020 00:03
Convert image byte array json object to download it into a file
<?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_file = implode(array_map('chr', $result->asset->file->data));
$file_path = $result->asset->file->path;
file_put_contents($file_path, $raw_file);
@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.