Skip to content

Instantly share code, notes, and snippets.

View matason's full-sized avatar

Chris Maiden matason

View GitHub Profile
@matason
matason / max-depth-parens.php
Created April 11, 2021 12:24
Calculate maximum nesting depth of parentheses
<?php
/**
* Calculate maximum nesting depth of parentheses.
*
* @see https://www.youtube.com/watch?v=zrOIQEN3Wkk
* @see https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/
*/
$input = '(1+(2*3)+((8)/4))+1';
<?php
/**
* Example enum usage.
*
* PHP8.1 will introduce the enum keyword, it will negate the need for the of
* validation code we often see below as enum will "make invalid states
* unrepresentable"
*
* @see https://wiki.php.net/rfc/enumerations
@matason
matason / funk.php
Last active February 14, 2021 15:13
<?php
$variables['blog_post']['teaser_image'] = [];
$variables['blog_post']['thumb_image'] = [];
/** @var NodeInterface $node */
if ($node->hasField('field_hero_image')) {
/** @var \Drupal\Core\TypedData\ListInterface $fieldHeroImage */
$fieldHeroImage = $node->get('field_hero_image');
@matason
matason / magic.lisp
Last active December 27, 2018 16:39
The Magic Roundabout - A Common Lisp story about a circular list, SBCL and save-lisp-and-die
;;;; Demonstrate SBCL save-lisp-and-die.
;;; The characters of the Magic Roundabout are on the Magic Roundabout... on
;;; each execution of this program, the roundabout is *rotated* one place and
;;; the name of character at that place is printed.
;;; First load...
;;; sbcl
;;; * (load "magic.lisp")
;;; (magic)
@matason
matason / tidal.snippets
Last active May 15, 2016 18:10
UltiSnips (snippet plugin for Vim) snippets for live coding with tidalcycles/Tidal
snippet bps
bps (${1:240}/120)
endsnippet
snippet d
d${1:1} $ $0
endsnippet
snippet sound
sound "$1"
@matason
matason / taxonomy_central.module
Created January 7, 2016 14:44
POC - Can I include vocabularies from one Drupal site within another?
<?php
/**
* The name of the taxonomy central database, usually from $databases
* configuration in settings.php
*/
define('TAXONOMY_CENTRAL_DATABASE_NAME', 'vocabulary_server');
/**
* Controller class for taxonomy central vocabularies.
$thing_path = libraries_get_path('thing');
require_once($thing_path . '/thing.php');
$thing = new thing();
exit();
:help
vimtutor
http://vimcasts.org/ - simply brilliant Vim screencasts.
http://pragprog.com/book/dnvim/practical-vim - buy it!
http://vimeo.com/vimlondon - videos from Vim London sessions.
http://vim-adventures.com/ - learn Vim while playing a game, unlock levels, pay for.
http://vimgolf.com/ - Pick a challenge, fire up Vim, and show us what you got.
https://github.com/carlhuda/janus/ - the Janus Vim distribution provides a minimal working environment using the most popular plug-ins and the most common mappings.
https://drupal.org/project/vimrc - customizes the vim text editor for editing Drupal-related files.
https://drupal.org/node/29325 - Configuring Vim
@matason
matason / vimbingo
Last active December 29, 2015 02:19
Vim Bingo at DrupalCampNW13, add your name on a new line and attend my talk on Sunday to be in with a chance of winning the book Practical Vim, signed by the author Drew Neil!
czettnersandor
janetrimmer
Eli-TW
@matason
matason / .vimrc
Created September 27, 2013 10:23
noremap <Up> <NOP>
inoremap <Up> <NOP>
vnoremap <Up> <NOP>
noremap <Down> <NOP>
inoremap <Down> <NOP>
vnoremap <Down> <NOP>
noremap <Left> <NOP>
inoremap <Left> <NOP>
vnoremap <Left> <NOP>
noremap <Right> <NOP>