Skip to content

Instantly share code, notes, and snippets.

View gormus's full-sized avatar
💭
Never be cruel, never be cowardly.

Osman Gormus gormus

💭
Never be cruel, never be cowardly.
View GitHub Profile
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@gormus
gormus / index.html
Created April 15, 2017 02:26
YouTube Video as a DIV Background // source https://jsbin.com/kaleraw
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>YouTube Video as a DIV Background</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<style id="jsbin-css">
html {
overflow-y: scroll;
@glaszig
glaszig / mkp2pblocklist
Last active January 30, 2022 00:30
creates a blocklist for your p2p endeavors
#!/usr/bin/env sh
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2020 glaszig <glaszig@gmail.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
@duanehutchins
duanehutchins / split-string-into-rows.sql
Last active March 8, 2023 20:59
MySQL split comma-separated string into rows
-- split-string-into-rows.sql
-- Duane Hutchins
-- https://www.github.com/duanehutchins
-- Split a string into a mysql resultset of rows
-- This is designed to work with a comma-separated string (csv, SET, array)
-- To use a delimiter other than a comma:
-- Just change all the occurrences of ',' to the new delimiter
-- (four occurrences in SET_EXTRACT and one occurrence in SET_COUNT)
@crittermike
crittermike / ExampleModuleController.php
Last active June 17, 2021 12:55
Example of overriding a route controller in Drupal 8
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;
@lukechilds
lukechilds / get_latest_release.sh
Created August 9, 2016 19:43
Shell - Get latest release from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Usage
# $ get_latest_release "creationix/nvm"
# v0.31.4
@johannez
johannez / allow_email_login.php
Last active February 24, 2021 01:07
Drupal 8 - Allow login by email
<?php
/**
* Implements hook_form_alter().
*/
function MODULE_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
// Allow login with email.
array_unshift($form['#validate'], 'MODULE_user_login_form_validate');
// Change the field label.
$form['name']['#title'] = new \Drupal\Core\StringTranslation\TranslatableMarkup('Email or Username');
@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@gormus
gormus / Change Drupal installation profile.md
Created February 9, 2016 20:38
Change Drupal installation profile
$ drush vset install_profile standard

$ drush rr
$ drush cc all

$ drush sqlq "DELETE FROM `system` WHERE filename LIKE 'profiles/pantheon/pantheon.profile'"
$ drush sqlq "UPDATE `system` SET status=1 WHERE filename LIKE 'profiles/standard/standard.profile'"
@gormus
gormus / jquery-csrf.js
Last active August 29, 2015 14:26 — forked from vorushin/jquery-csrf.js
Small jQuery plugin for adding csrf-token to Ajax/Ajaj requests
$.ajaxSetup({
beforeSend: function(xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {