Skip to content

Instantly share code, notes, and snippets.

View ejemplo_imagemagick.js
// 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'
View Jquery-document-ready.js
$(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
@octobel
octobel / Block Attributes.php
Created Feb 19, 2018
Drupal 8 - Block Attributes
View Block Attributes.php
/**
* {@inheritdoc}
*/
public function build() {
return [
'#theme' => 'cfc_footer_block',
'#attributes' => [
'class' => ['footer'],
],
'#cache' => [
@octobel
octobel / Format date.php
Created Feb 19, 2018
Drupal 8 - Format a timestamp to a custom format
View Format date.php
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');
}
@octobel
octobel / Resume.twig
Created Feb 11, 2018
Get a resume from a big text in twig
View Resume.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(' ') %}
@octobel
octobel / nodes of taxonomy.php
Created Feb 8, 2018
get nodes of taxonomy term(s) in drupal 8
View nodes of taxonomy.php
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);
@octobel
octobel / drupal_conditions.php
Created Feb 8, 2018
Some drupal 8 conditions
View drupal_conditions.php
$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');
@octobel
octobel / First_and_last_date.php
Last active Feb 8, 2018
last day of the month from date
View First_and_last_date.php
$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');
@octobel
octobel / .js
Created Jul 22, 2017
Get a substring using regex to remove the part you don't want
View .js
var str = '/?token=123ADV';
var result = str.replace(/^(.*)?\=/g,'');
//result = 123ADV
View top&bottomScrollBar.js
(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 = {};
You can’t perform that action at this time.