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.
@matason
matason / image-markup.html
Created November 11, 2015 14:26
Captioned and un-captioned image markup
<!-- Captioned image -->
<figure class="image pull-right"><img alt="Hello" height="75" src="img/test-image.png" width="100" />
<figcaption>Caption</figcaption>
</figure>
<!-- Un-captioned image -->
<img alt="Hello" class="pull-right" height="75" src="img/test-image.png" width="100" />
@matason
matason / test
Created May 15, 2015 05:53
Isolated httpfs test
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main (int argc, char *argv[]) {
FILE *f;
FILE *ret;
int c;
@matason
matason / php_stomp.c
Created May 6, 2015 04:29
zend_object_store_get_object to Z_OBJ_P
diff --git a/php_stomp.c b/php_stomp.c
index 5e6f1e7..d9537b2 100755
--- a/php_stomp.c
+++ b/php_stomp.c
@@ -32,9 +32,10 @@
#include "ext/standard/php_smart_string.h"
#define FETCH_STOMP_OBJECT \
- i_obj = (stomp_object_t *) zend_object_store_get_object(stomp_object TSRMLS_CC); \
+ stomp_object_t *i_obj; \
#include <stdio.h>
char * cards [2] [2] = {"0000", "1000", "0111", "1111"};
int main ()
{
printf("Address of cards is %p\n", &cards);
printf("Which can also be written %p\n", cards[0]);