Skip to content

Instantly share code, notes, and snippets.

@ptitb
ptitb / Drupal8-theme-snippets.php
Last active July 22, 2016 11:36
Drupal 8 *.theme file snippets for Twig template
<?php
use Drupal\image\Entity\ImageStyle;
use \Drupal\file\Entity\File;
function theme_preprocess_page(&$vars) {
if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof \Drupal\node\NodeInterface) {
// Get imagestyle url for use in Twig template
@ptitb
ptitb / ssh-commands.sh
Last active November 6, 2018 18:27
SSH Commands
// Generate ssh key
ssh-keygen -t rsa
// Copy public key
cat ~/.ssh/id_rsa.pub
// Apply online patch
curl https://www.drupal.org/files/issues/core-views_row_class_number_missing-2669394-6-D8.patch | patch -p1
// SCP all files including hidden from current directory
{% for row in rows %}
{% set parity = cycle(['odd', 'even'], loop.index0) %}
#drush dl admin_toolbar paragraphs google_analytics weight token link_css devel entity_reference_revisions pathauto video_embed_field ctools simple_sitemap twig_tweak
drush dl admin_toolbar paragraphs google_analytics token link_css devel entity_reference_revisions pathauto video_embed_field ctools simple_sitemap twig_tweak draggableviews viewsreference crop focal_point linkit publishcontent cer field_group
const fs = require("fs");
const five = require("johnny-five");
const board = new five.Board({
port: "/dev/ttyACM0"
});
const SerialPort = require('serialport');
const Printer = require('thermalprinter');
const nodeWebcam = require( "node-webcam" );
// If we get errors about mysql
"ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock"
@ptitb
ptitb / svg_encode_variable.scss
Created November 12, 2019 15:35
Sass mixin svg
@function triangleDown-svg-factory($fill-color) {
@return '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="' + $fill-color + '" d="M2.611 5.393c-.17-.216-.084-.393.191-.393h10.397c.275 0 .361.177.191.393l-5.08 6.464c-.17.216-.452.216-.622 0l-5.077-6.464z"/></svg>'
}
@mixin triangleDown($fillColor: rgba(#ffffff, 1), $left: center, $top: center) {
background: transparent url(svg-encode(triangleDown-svg-factory($fillColor))) $left $top no-repeat;
}
// Thanks to Hugo Giraudel for his str-replace function (http://www.sassmeister.com/gist/1b4f2da5527830088e4d)
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@ptitb
ptitb / useEmitter.ts
Created September 30, 2024 18:37 — forked from eserdinyo/useEmitter.ts
Built in eventbus composable for nuxt 3
// composables/useEmitter.ts
export default function () {
const hooks = useNuxtApp().hooks;
return {
emit: hooks.callHook,
on: hooks.hook,
}
}