Skip to content

Instantly share code, notes, and snippets.

View midnai's full-sized avatar

Jhosbel Aguilar midnai

View GitHub Profile
// Crop imagenes, las imagenes tienen buena resolucion pero no tienen un estandar en los anchos altos
// Se necesita imagenes cuadradas, actualmente la mayoria tienen espacio a los costados
// Paso 1, escalar todas los altos de todas las imagenes, el ancho debe ser proporcional
// Paso 2, reprocesar las imagenes escaladas posicionarse al centro con -gravity center, y tomar 2400px
// la imagen quedara cuadrada (rescalada)
// Se usa ImageMagick en macbook (Instalar con Brew: brew instal imagemagick)
// Se usan los siguientes comandos:
// (modificar los folderes a requerimiento, las imagenes procesadas se generan con el mismo nombre)
$ magick 'original/*.jpg' -quality 100 -set filename:f '%t' -scale x2400 x2400/'%[filename:f].jpg'
@midnai
midnai / Jquery-document-ready.js
Created August 2, 2018 20:04
Jquery-document-ready
$(document).ready(function() {
//do jQuery stuff when DOM is ready
});
jQuery(document).ready(function($) {
//do jQuery stuff when DOM is ready
});
$(function(){
//jQuery code here
@midnai
midnai / Block Attributes.php
Created February 19, 2018 17:28
Drupal 8 - Block Attributes
/**
* {@inheritdoc}
*/
public function build() {
return [
'#theme' => 'cfc_footer_block',
'#attributes' => [
'class' => ['footer'],
],
'#cache' => [
@midnai
midnai / Format date.php
Created February 19, 2018 15:53
Drupal 8 - Format a timestamp to a custom format
public function formatDate($date)
{
$date = new \DateTime($date);
$date = $date->getTimestamp();
return \Drupal::service('date.formatter')->format($date, '', 'd \d\e F \d\e Y');
}
@midnai
midnai / Resume.twig
Created February 11, 2018 00:13
Get a resume from a big text in twig
{% for d in data %}
{% set text = d.resumen |split(' ') %}
{% set t2 = '' %}
{% if text|length > 10 %}
{% for t in text|slice(0, 10) %}
{% set t2 = t2 ~ ' ' ~ t %}
{% endfor %}
{% set t2 = t2 ~ '...' %}
{% else %}
{% set t2 = text|join(' ') %}
@midnai
midnai / nodes of taxonomy.php
Created February 8, 2018 06:29
get nodes of taxonomy term(s) in drupal 8
function getNodesByTaxonomyTermIds($termIds){
$termIds = (array) $termIds;
if(empty($termIds)){
return NULL;
}
$query = \Drupal::database()->select('taxonomy_index', 'ti');
$query->fields('ti', array('nid'));
$query->condition('ti.tid', $termIds, 'IN');
$query->distinct(TRUE);
@midnai
midnai / drupal_conditions.php
Created February 8, 2018 06:28
Some drupal 8 conditions
$query->condition('myfield', array(1, 2, 3), 'IN');
$query->condition('myfield', array(5, 10), 'BETWEEN');
$query->condition('myfield', array(1, 2, 3), 'NOT IN');
$query->isNull('myfield');
$query->isNotNull('myfield');
@midnai
midnai / First_and_last_date.php
Last active February 8, 2018 06:26
last day of the month from date
$date = new DateTime('now');
$date->modify('last day of this month');
echo $date->format('Y-m-d');
$date->modify('last day of 1 month');
echo $date->format('Y-m-d');
@midnai
midnai / .js
Created July 22, 2017 00:02
Get a substring using regex to remove the part you don't want
var str = '/?token=123ADV';
var result = str.replace(/^(.*)?\=/g,'');
//result = 123ADV
(function($) {
$.fn.getHiddenDimensions = function(boolOuter) {
var $item = this;
var props = { position: 'absolute', visibility: 'hidden', display: 'block' };
var dim = { 'w':0, 'h':0 };
var $hiddenParents = $item.parents().andSelf().not(':visible');
var oldProps = [];
$hiddenParents.each(function() {
var old = {};