Skip to content

Instantly share code, notes, and snippets.

View robdecker's full-sized avatar

Rob Decker robdecker

View GitHub Profile

1. Using parseInt() - slow

parseInt() parses a string and returns a whole number. Spaces are allowed. Only the first number is returned.
This method has a limitation though. If you parse the decimal number, it will be rounded off to the nearest integer value and that value is converted to string. One might need to use parseFloat() method for literal conversion.

myString = '129' 
console.log(parseInt(myString)) // expected result: 129

a = 12.22

For a quick local server:

npm install browser-sync --save-dev

In package.json:

"scripts": {
  "server": "browser-sync start --directory --server --files '*.js, *.html, *.css'"
}
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";

parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port;     // => "3000"
parser.pathname; // => "/pathname/"
parser.search;   // => "?search=test"
parser.hash; // => "#hash"

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@robdecker
robdecker / (1) info.md
Last active January 29, 2021 20:21
[Breakpoint & grid system] #sass

Breakpoint & grid system

Uses @include-media and some Bootstrap grid mixins (but has no Bootstrap dependencies).

Example usage

Tiles component

@robdecker
robdecker / debug.twig
Last active January 19, 2021 18:50 — forked from zakiya/debug.twig
[Debugging Twig in Drupal] #d8 #twig
{# ~ Core ~ #}
{# {{ dump() }} #}
{# {{ dump(page) }} #}
{# ~ Devel~ #}
{# {{ kint()}} #}
{# {{ kint(page)}} #}
{# {{ devel_dump(page) }} #}
{# {{ devel_breakpoint() }} #}
@robdecker
robdecker / debug.php
Last active January 19, 2021 18:50 — forked from zakiya/debug.php
[Debugging php in Drupal] #d8
<?php>
function myfunction($app) {
// ~~ Core.
// debug($app);
// dump($app);
// var_dump($app);
// ~~ Devel + kint library + settings
// dpr($app);
// kint($app);
@robdecker
robdecker / 1.md
Created November 25, 2020 20:43
[Drupal performance] #d8

Core

  • Internal Page Cache: anonymous users
  • Internal Dynamic Page Cache: anonymous and logged in users (includes dynamic content)
  • BigPipe
  • /admin/config/development/performance: set cache age & css/js aggregation

Contrib

@robdecker
robdecker / 1.md
Created November 25, 2020 01:16
[Drupal links] #d8
@robdecker
robdecker / 1.js
Created November 24, 2020 23:20
[Prevent the Administrative Toolbar from popping out as a sidebar when screen width is reduced] #d8
(function($, Drupal, document, window) {
/**
* Prevents the Administrative Toolbar from popping out as a sidebar when
* screen width is reduced.
*/
Drupal.behaviors.customToolbarResizeTweak = {
attach: function (context) {
window.matchMedia('(min-width: 975px)').addListener(function(event) {
event.matches ? $('#toolbar-item-administration', context).click() : $('.toolbar-item.is-active', context).click();