Skip to content

Instantly share code, notes, and snippets.

View gtrufitt's full-sized avatar

Gareth Trufitt gtrufitt

View GitHub Profile
@gtrufitt
gtrufitt / index.js
Last active February 25, 2020 13:06
Add thread link to threads in Google Chat
const insertThreads = () => {
const roomId = document.querySelector('[data-soft-view-id]').getAttribute('data-soft-view-id')
document.querySelectorAll('[data-topic-id]').forEach((topic) => {
const topicId = topic.getAttribute('data-topic-id');
if (document.querySelectorAll(`[data-gu-thread="${topicId}"]`).length === 0 && !document.querySelector('[data-stream-group-id*="dm/"]')) {
topic.insertAdjacentHTML('beforeend', `<a data-gu-thread="${topicId}" href="https://chat.google.com${roomId}/${topicId}">Thread link</a>`)
}
});
};
@gtrufitt
gtrufitt / settimeout.js
Last active March 16, 2017 14:54
Test setTimouet
function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu until time's up
}
sleep(2000)
@gtrufitt
gtrufitt / WebpackBabelPreact.md
Last active February 8, 2017 16:34
Module build failed: ReferenceError: Unknown plugin "transform-class-properties"

Preact-render-to-string, Webpack and Babel

This is with webpack 2, preact, preact-compat

Getting this error:

ERROR in [path]/~/preact-render-to-string/dist/index.js
Module build failed: ReferenceError: Unknown plugin "transform-class-properties" specified in "[path]/node_modules/preact-render-to-string/.babelrc" at 0, attempted to resolve relative to "[path]/node_modules/preact-render-to-string"
 at [path]/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17
@gtrufitt
gtrufitt / steady-on.js
Created July 13, 2016 14:31 — forked from desbo/steady-on.js
steady on
function Queue() {
this.queue = [];
}
/**
* Add an item to the queue
*
* @param {Anything} item item to add
* @return {Number} queue length
@gtrufitt
gtrufitt / x-browser inline-block with no whitespace
Last active December 18, 2015 01:49
Inline-block that works down to ie7 (maybe 6 I dunno), and removes the random white space between the elements.
/* Inline list */
.m-inline-list--item, .m-inline-elements > * {
display: inline-block;
}
.lt-ie8 .m-inline-list--item, .lt-ie8 .m-inline-elements > * {
zoom: 1;
display: inline;
}
@gtrufitt
gtrufitt / Fancy Price - Pennies
Created April 10, 2013 15:44
Wrap a span around the pennies on a price
// Fancy price - add span around the pennies for styling
$.fancyPrice = function(selector){
$(selector).each(function(){
var price = $(this).html();
var decimalPosition = price.indexOf('.');
var afterDecimal = price.substr(decimalPosition,3);
var newPrice = price.replace(afterDecimal,'<span>' + afterDecimal + '</span>');
$(this).html(newPrice);
});
};
@gtrufitt
gtrufitt / Fancy Price - Symbol
Created April 10, 2013 15:43
Use jQuery to add a span around a currency symbol (for currencies with the symbol as the first character and only one char)
// Fancy price - add span around the symbol for styling
$.fancyPrice = function(selector){
$(selector).each(function(){
var text = $.trim($(this).html()),
symbol = text.substr(0,1),
newText = text.replace(symbol, '<span class="symbol">' + symbol + '</span>');
$(this).html(newText);
});
};