Skip to content

Instantly share code, notes, and snippets.

View webcultist's full-sized avatar

Eugen Kraft webcultist

View GitHub Profile
@JamieMason
JamieMason / group-objects-by-property.md
Created September 14, 2018 07:38
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active July 18, 2024 09:20
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for...i or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@jeromecoupe
jeromecoupe / webstoemp-gulpfile.js
Last active January 21, 2024 16:28
Gulp 4 sample gulpfile.js. For a full explanation, have a look at https://www.webstoemp.com/blog/switching-to-gulp4/
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@Greg-Boggs
Greg-Boggs / functions.php
Last active April 7, 2018 19:56
Helper function to get renderable region for Drupal 8
<?php
// Example usage: $build = blocks_get_blocks_by_region('sidebar_first');
function blocks_get_blocks_by_region($region_name) {
$build = [];
$blocks = entity_load_multiple_by_properties('block', ['theme' => $GLOBALS['theme'], 'region' => $region_name]);
uasort($blocks, 'Drupal\block\Entity\Block::sort');
foreach ($blocks as $key => $block) {
@rlandas
rlandas / gulpinstall.sh
Created August 21, 2015 06:02
GULP : Uninstalling and Installing GULP global and local
npm uninstall -g gulp
npm install -g gulp
npm uninstall --save-dev gulp
npm install --save-dev gulp
@satya164
satya164 / quantity-query.scss
Last active September 7, 2023 20:06
Quantity Queries in Sass
@mixin quantity-query($selector, $type, $amount, $max: null) {
@if $type == at-least {
#{$selector}:nth-last-child(n+#{$amount}),
#{$selector}:nth-last-child(n+#{$amount}) ~ #{$selector} { @content; }
} @else if $type == at-most {
#{$selector}:nth-last-child(-n+#{$amount}):first-child,
#{$selector}:nth-last-child(-n+#{$amount}):first-child ~ #{$selector} { @content; }
} @else if $type == between {
@if type-of($max) != "number" {
@error "Max value must be a number for quantity-query.";
@alefi87
alefi87 / environment-install.md
Last active October 21, 2018 11:18
OS X 10.10 Yosemite, Apache, PHP 5.6, MySQL, Memcache, SSL setup with Homebrew
@bdombro
bdombro / Drupal_Text_to_Textarea.drush.php
Last active May 23, 2016 18:29
Drupal_Text_to_Textarea.drush.php
<?php
/**
* Change a field from textfield to textarea
* Unlike other guides online, this one actually corrects the blob values
* Run this using drush: `drush scr <filepath>`
*/
$field_name = "field_test_text_field_2";
@benoitboucart
benoitboucart / gist:f80090c87fa97f4e4098
Last active December 19, 2023 22:14
How to use Jekyll with Gulp
/**
* For more information see this tutorial: http://blog.webbb.be/use-jekyll-with-gulp/
*
* Libs import
* --> How to install? npm install --save-dev gulp-minify-html
* @type {[type]}
*/
var gulp = require('gulp'),
path = require('path'),