Skip to content

Instantly share code, notes, and snippets.

View cm's full-sized avatar

Christian Burland cm

  • London, United Kingdom
  • 23:29 (UTC +01:00)
View GitHub Profile
@cm
cm / challange2.py
Last active November 7, 2020 21:39
# My translation from javascript
def encode(message, offset):
baseChars = list('abcdefghijklmnopqrstuvwxyz')
messageChars = list(message)
for i in range(len(messageChars)):
baseIndex = baseChars.index(messageChars[i])
messageChars[i] = baseChars[(baseIndex + offset) % len(baseChars)]
return(''.join(messageChars))
@cm
cm / await-class.js
Last active September 29, 2020 17:34
Observes an element and fires callback when element is updated with a given class.
// Observes an element and fires callback when element is updated with a given class.
// If the element already contains that class callback is immediately without creating
// the mutation observer. This is useful for observing dom modifications by a third party.
function awaitClass (elem, elemClass, callback) {
let observer = new MutationObserver(function (mutationList) {
mutationList.forEach(function (mutation) {
if (
mutation.attributeName === 'class' &&
mutation.target.classList.contains(elemClass)
@cm
cm / bgset.js
Last active September 22, 2020 08:52
Responsive background images for https://github.com/aFarkas/lazysizes
/**
* Expects html attribute of 'data-bgset' with a json object as it's content.
* bgset='{"desktop_image":"desktop.jpg","mobile_image":"mobile.jpg"}'
*/
document.addEventListener('lazybeforeunveil', function(e) {
var attribute = e.target.getAttribute('data-bgset'),
backgrounds = attribute ? JSON.parse(attribute) : null;
function loadBackground () {
e.target.style.backgroundImage = window.innerWidth >= 768 ?
@cm
cm / konamify.js
Last active August 17, 2019 11:11
Observe for Konami code input and then execute callback.
window.konamify = function (cb) {
var k = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13], i = 0;
window.addEventListener('keydown', function (e) {
i = (e.keyCode === k[i]) ? i + 1 : 0;
if (i === k.length) cb();
});
};
@cm
cm / Config.php
Last active August 19, 2019 14:56
Magento 2 Custom Sort Options
<?php
namespace Vendor\Module\Plugin\Catalog\Model;
class Config
{
public function afterGetAttributeUsedForSortByArray(
\Magento\Catalog\Model\Config $catalogConfig,
$options
) {
@cm
cm / static-build-gulpfile.js
Last active March 10, 2019 15:34
Basic gulpfile for static builds.
const gulp = require('gulp')
const connect = require('gulp-connect')
const sass = require('gulp-sass')
/**
* Paths to source files...
*/
const htmlPath = './public/'
const scssPath = './scss/'
const scssOutput = './.tmp/css'
@cm
cm / trim.html
Last active April 11, 2018 14:47
Trim string in textarea to word count limit, whilst preserving whitespace.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<textarea value="150" name="" id="" cols="50" rows="1"></textarea>
@cm
cm / station-codes.json
Last active January 16, 2018 17:03
All nlc format station codes
{"environment":"rh-api-live","version":"1.2.488.211","rhendpoint":"https://www.retailhubservices.com/RetailHub-2.1.14","data":[{"name":"Abbey Road Dlr","code":"ZAL","nlc":"0750","isfgw":false,"isgroup":false,"isalias":false,"tod":false},{"name":"Abbey Wood","code":"ABW","nlc":"5131","isfgw":false,"isgroup":false,"isalias":false,"tod":true},{"name":"Aber","code":"ABE","nlc":"3813","isfgw":false,"isgroup":false,"isalias":false,"tod":true},{"name":"Abercynon","code":"ACY","nlc":"3801","isfgw":false,"isgroup":false,"isalias":false,"tod":false},{"name":"Aberdare","code":"ABA","nlc":"3982","isfgw":false,"isgroup":false,"isalias":false,"tod":true},{"name":"Aberdeen","code":"ABD","nlc":"8976","isfgw":false,"isgroup":false,"isalias":false,"tod":true},{"name":"Aberdour","code":"AUR","nlc":"9090","isfgw":false,"isgroup":false,"isalias":false,"tod":true},{"name":"Aberdovey","code":"AVY","nlc":"4435","isfgw":false,"isgroup":false,"isalias":false,"tod":false},{"name":"Abererch","code":"ABH","nlc":"4440","isfgw":false,"isgr
@cm
cm / learngo.go
Last active July 21, 2017 10:12
Regist...
// Single line comment
/* Multi-
line comment */
// A package clause starts every source file.
// Main is a special name declaring an executable rather than a library.
package main
// Import declaration declares library packages referenced in this file.