Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin kevinquillen

View GitHub Profile
@kevinquillen
kevinquillen / PagerService.php
Created Sep 6, 2016
Example of creating a reusable object that provides the Drupal pager easily. See SearchResults.php for an example.
View PagerService.php
<?php
namespace Drupal\velirsearch\Service;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class PagerService implements ContainerAwareInterface {
@kevinquillen
kevinquillen / menu.html.twig
Created Oct 27, 2016
Applying classes and attributes to navigation under certain depth conditions
View menu.html.twig
{#
/**
* @file
* Theme override to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
View .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/kevinquillen/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"
@kevinquillen
kevinquillen / agnoster.zsh-theme
Last active Dec 21, 2016
zsh agnoster customizations
View agnoster.zsh-theme
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
View .tmux.conf
set -g prefix C-a
unbind C-b
bind C-a send-prefix
set -s escape-time 1
set -g base-index 1
set -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded"
@kevinquillen
kevinquillen / gist:307f9ec2f6e2b685c64f1bc6ce2b745c
Last active Jan 8, 2017
Custom bash function to generate a new markdown file for Jekyll, first arg is assumed to be post title, which becomes the filename in the format Jekyll is expecting. Auto open and save in Vim, if the post doesn't exist.
View gist:307f9ec2f6e2b685c64f1bc6ce2b745c
function new_post() {
cd ~/Sites/kevinquillen.com/_posts
today=$(date +"%F")
title=$1:l
clean_title=${title//[^a-zA-Z0-9]/-}
filename="$today-$clean_title.markdown"
if [[ ! -a ./$filename ]]; then
vim $filename -c 'w'
else
@kevinquillen
kevinquillen / .htaccess
Created Mar 31, 2017
Example htaccess rule to force all traffic over HTTPS
View .htaccess
# Force all traffic to HTTPS, except a local instance
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} !^mysite\.local$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@kevinquillen
kevinquillen / changeFieldFormatValueTo.sql
Created Jun 2, 2017
Stored procedure for MySQL - mass update *_format value tables in Drupal to a specified format. This is useful for when you change default formats on a field after the field already has values, so that the user is not presented with a blank textbox on forms.
View changeFieldFormatValueTo.sql
CREATE PROCEDURE changeFieldFormatValueTo (IN format_name VARCHAR(32))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE table_name_value VARCHAR(64);
DECLARE column_name_value VARCHAR(64);
DECLARE cursor_fields CURSOR FOR SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'field_%_format';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_fields;
@kevinquillen
kevinquillen / .vimrc
Last active Jun 10, 2017
my vimrc file
View .vimrc
set nocompatible " be iMproved, required
filetype off " required
syntax enable
set number
set showcmd
set hlsearch
set incsearch
set nobackup
set noswapfile
@kevinquillen
kevinquillen / module.php
Last active Jul 10, 2017
Importing to a SQL table from a CSV file in Drupal, so you don't have to parse exceptionally large CSVs line by line and instead can do so with MySQL querying. This snippet assumes you have read the column headers already from the CSV and passed them as parameters, as well as the temp table name you want to use.
View module.php
<?php
/**
* Creates a temporary table to hold values from an uploaded CSV.
* @param $table_name
* @param $columns
* @param $message
* @param $context
*/
function csv_import_create_temp_table($table_name, $columns) {