Skip to content

Instantly share code, notes, and snippets.

@chupzzz
chupzzz / array2csv.php
Created April 26, 2017 12:54
Convert array to CSV and return it
function array2csv($array) {
$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
fputcsv($csv, $array, ';');
rewind($csv);
return stream_get_contents($csv);
}
@chupzzz
chupzzz / match_path.php
Created June 23, 2017 19:34
Match (check) given path for pattern/mask (like in Drupal blocks system).
<?php
$path = current_path();
$path_alias = drupal_lookup_path('alias', $path);
$patterns = '' . PHP_EOL . 'node/n' . PHP_EOL . 'blog/*';
if (drupal_match_path($path, $patterns) || drupal_match_path($path_alias, $patterns)) {
// Do things.
}
@chupzzz
chupzzz / taxonomy_node_count.php
Last active July 7, 2017 18:26
Drupal 7: Get Taxonomy node count
<?php
/**
* @param tid
* Term ID
* @param child_count
* TRUE - Also count all nodes in child terms (if they exists) - Default
* FALSE - Count only nodes related to Term ID
* @param node_type
* Count only nodes of one type (string).
*/
@chupzzz
chupzzz / taxonomy_find_term_by_parent.php
Created August 6, 2017 12:19
Find taxonomy term child (by name) limited by parent term (Drupal 7).
<?php
/**
* Find taxonomy term (by name) limited by parent term.
*
* In many cases you may need to find children in exact term (parent).
* Here we do this in efficent way with precise query (not like taxonomy_get_tree()
* where all the terms loading.
*
* @param $name
* @param $parent
@chupzzz
chupzzz / variables.styl
Created August 30, 2017 07:20 — forked from shengt/variables.styl
Media queries variables for stylus
// Media queries breakpoints
// --------------------------------------------------
// Extra small screen / phone
$screen-xs ?= 480px
$screen-phone ?= $screen-xs
// Small screen / tablet
$screen-sm ?= 768px
$screen-tablet ?= $screen-sm
@chupzzz
chupzzz / menuHover.vue
Created February 10, 2024 06:57
Quasar 2 menu on hover (Vue 3)
<template>
<q-button
label="Hover button"
@mouseenter="menuOver = true; checkMenu()" @mouseleave="menuOver = false; checkMenu()"
>
<q-menu
transition-show="jump-up" transition-hide="jump-down"
anchor="top middle" self="bottom middle"
:offset="[0, 2]"
no-parent-event v-model="menuStatus"
@chupzzz
chupzzz / SupabaseLite.js
Created September 25, 2024 16:18
Supabase: LITE JS request without official lib
// Supabase credentials. Can be found in the settings of your project
const supaUrl = 'https://base-id.supabase.co'
const supaKey = 'public-key-hash'
/**
* Retrieve a row from table by its ID.
*
* @param {string} table Table where we're looking for our row.
* @param {string} id The ID of the row to retrieve.
* @returns {Promise<*|{}>} The row object with the given ID, or `undefined` if it was not found.