Skip to content

Instantly share code, notes, and snippets.

View kevinquillen's full-sized avatar

Kevin kevinquillen

View GitHub Profile
@kevinquillen
kevinquillen / PagerService.php
Created September 6, 2016 17:05
Example of creating a reusable object that provides the Drupal pager easily. See SearchResults.php for an example.
<?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 October 27, 2016 15:18
Applying classes and attributes to navigation under certain depth conditions
{#
/**
* @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.
@kevinquillen
kevinquillen / .zshrc
Created December 21, 2016 23:09
my zshrc file
# 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 December 21, 2016 23:13
zsh agnoster customizations
# 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
@kevinquillen
kevinquillen / .tmux.conf
Created December 21, 2016 23:25
my 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 January 8, 2017 17:07
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.
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 March 31, 2017 15:25
Example htaccess rule to force all traffic over HTTPS
# 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 June 2, 2017 20:56
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.
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 June 10, 2017 03:48
my vimrc file
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 July 10, 2017 20:39
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.
<?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) {