Skip to content

Instantly share code, notes, and snippets.

@thamas
thamas / THEMENAME.theme
Last active June 9, 2023 11:57
Display taxonomy term in Drupal Twig template translated
<?php
/**
* Implemets hook_preprocess_node().
*
* Create variable from translated taxonomy term name.
* Code by @tikaszvince.
*/
function THEMENAME_preprocess_node(&$variables) {
/** @var Drupal\node\Entity\Node $node */
@zhiyzuo
zhiyzuo / jsd.py
Last active May 12, 2022 10:58
Jensen-Shannon Divergence in Python
import numpy as np
import scipy as sp
def jsd(p, q, base=np.e):
'''
Implementation of pairwise `jsd` based on
https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence
'''
## convert to np.array
p, q = np.asarray(p), np.asarray(q)
@LittleCoding
LittleCoding / myelement.html.twig
Created September 27, 2016 13:37
Current URL path via Twig in Drupal 8
{#
/**
* @file
* Get the current URL path via Drupal 8 route name and twig function.
*/
#}
<a href="{{ url('<current>') }}">Current page</a>
@mxstbr
mxstbr / Readme.md
Last active June 25, 2024 18:16
Enable tab completion for JSX with Emmet in Atom

Enable tab completion for JSX with Emmet in Atom

This guide assumes you have the emmet and language-babel packages already installed in Atom

Gif of the tab completion working

  1. Open the keymap.cson file by clicking on Atom -> Keymap… in the menu bar
  2. Add these lines of code to your keymap:
'atom-text-editor[data-grammar~="jsx"]:not([mini])':
@dannguyen
dannguyen / guardian-articles-day-api.md
Last active November 23, 2023 12:28
How to use The Guardian's API to download article data for content analysis (in Python 3.x)

How to use The Guardian's API to download article data for content analysis (in Python 3.x)

The Guardian offers an API as deep and robust as the New York Times Article API when it comes to content analysis.

The Guardian's API offers more than "1.7 million pieces of content", with published items as far back as 1999. You can register as a developer here, which gets you 5,000 API hits a day and an API key that looks something like this:

zzzyyyyy-9a9z-999z-z999-9e8a83922516

The Guardian has a handy interactive explorer to interactively tweak the query parameters.

@MattReimer
MattReimer / build.sh
Created October 24, 2012 17:22
Drush install Script
#!/usr/bin/env drush php-script --everything -v
<?php
// ---------------------------------------
// CREDENTIALS ETC.
// ---------------------------------------
$dir = "public_html";
$theme_dir = "public_html/sites/all/themes";
$makefile = "site.make";
@geedelur
geedelur / capistrano_windows.textile
Created July 30, 2012 16:13
Cygwin + Ruby + RubyGems => Deploy with Capistrano from Windows
@kahlil
kahlil / gradient-triangles.css
Created September 16, 2010 10:09
Ingenius solution to create a CSS triangle with a gradient.
/* Code is by A.J. Cates (http://ajcates.com). Find his post here: http://forr.st/~XGU */
#gradient-triangle {
width: 60px;
height: 60px;
position: absolute;
top: 3em;
left: -30px;
clip: rect(auto 30px 60px auto);
}