Skip to content

Instantly share code, notes, and snippets.

View andregoncalves's full-sized avatar
🏠
Working from home

Andre Goncalves andregoncalves

🏠
Working from home
View GitHub Profile
@andregoncalves
andregoncalves / aspect.css
Last active November 18, 2017 11:57
CSS maintain block aspect ratio
<style>
.aspect-ratio {
padding-top: calc(1 / (16 / 9) * 100%);
position : relative;
}
.aspect-wrapper {
position: absolute;
top:0;
left:0;
@andregoncalves
andregoncalves / colors.js
Created March 6, 2018 11:28
[Devtools console colors] #devtools
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
@andregoncalves
andregoncalves / example.js
Created March 25, 2018 10:52
[Throttling and debouncing] #js
// Throttling
// ES6 code
function throttled(delay, fn) {
let lastCall = 0;
return function (...args) {
const now = (new Date).getTime();
if (now - lastCall < delay) {
return;
}
lastCall = now;
@andregoncalves
andregoncalves / speed.js
Created May 10, 2018 09:23
[Page load time] measure page load time in js #devtools #js
(function(){
const t = window.performance && performance.timing;
if (!t) {
return;
}
const loadTime = (t.loadEventEnd - t.navigationStart) / 1000;
alert(`This page loaded in ${loadTime} seconds`);
}())
@andregoncalves
andregoncalves / warning.css
Created May 26, 2018 11:19
[CSS rule to display warning icon with unicode] #css
.invalid-feedback:before {
content: '⚠️'
}
@andregoncalves
andregoncalves / class_decorator.ts
Last active May 3, 2021 07:07 — forked from remojansen/class_decorator.ts
[TypeScript Decorators] #typescript
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}