Skip to content

Instantly share code, notes, and snippets.

View antoniocapelo's full-sized avatar

Capelo antoniocapelo

View GitHub Profile
@antoniocapelo
antoniocapelo / classModulePattern
Last active August 29, 2015 14:06
Class Creation - Module Pattern
(function( global ) {
var ModPattern = function() {
function api1 (argument) {
return this.publicInstanceValue++;
}
function api2 (argument) {
return privateInstanceValue++;
}
@antoniocapelo
antoniocapelo / newExtendClass
Created September 14, 2014 23:14
Another method of extending classes in Javasript
function BaseClass () {
this.doSomething = function () {
};
}
BaseClass.prototype.someObject = {};
BaseClass.prototype.sharedSomething = function () {
};
@antoniocapelo
antoniocapelo / edit_express_app.js
Created November 2, 2014 17:08
Editing express generated app.js to serve static files generated by grunt
// view engine setup - erased
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');
app.use(favicon(path.join(__dirname,'dist','favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
@antoniocapelo
antoniocapelo / js_screenshot
Created December 7, 2014 18:15
Snippet for capturing screenshot
(function (exports) {
function urlsToAbsolute(nodeList) {
if (!nodeList.length) {
return [];
}
var attrName = 'href';
if (nodeList[0].__proto__ === HTMLImageElement.prototype
|| nodeList[0].__proto__ === HTMLScriptElement.prototype) {
attrName = 'src';
}
@antoniocapelo
antoniocapelo / node-server-service.conf
Created December 31, 2014 19:16
task for nodeJS powered site
description "task for nodeJS powered site"
author "António Capelo - antonio.c.capelo@gmail.com"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
@antoniocapelo
antoniocapelo / queryStringToObject.js
Last active February 28, 2016 13:27
Transforming query string params into object
function getParamsObj(url) {
return url
.split('?')[1]
.split('&')
.map(function(el) {
return el.split('=');
})
.reduce(function(prevVal, currVal) {
prevVal[currVal[0]] = currVal[1]
.split(',')
@antoniocapelo
antoniocapelo / pipelinefsstyle.css
Last active April 8, 2016 10:09
pipelinefsstyle
body {
padding: 10px;
background: url('https://i.ytimg.com/vi/09nTwccQTUA/maxresdefault.jpg');
background-size: cover;
font-size: 25px;
margin: 0 auto;
width: 100px;
background-position: center;
}
:set backupcopy=yes
@antoniocapelo
antoniocapelo / useWindowSize.js
Created April 10, 2019 22:32
Custom React Hook for setting a window resize listener and get updated dimensions
const useWindowSize = () => {
const [dimensions, setDimension] = useState({
width: window.innerWidth,
height: window.innerHeight,
});
useEffect(() => {
const handler = () => {
const {innerWidth, innerHeight} = window;
setDimension({ width: innerWidth, height: innerHeight})
@antoniocapelo
antoniocapelo / tsx-default-html-props.tsx
Created May 2, 2019 17:06
TSX component extending default HTML props
import React from 'react';
import { styled } from '@material-ui/styles';
import AppBar from '@material-ui/core/AppBar';
type CustomProps = { show: boolean };
// Let's imagine MyComponent is a special type of button...
type MyComponentProps = CustomProps & React.HTMLProps<HTMLButtonElement>;
const MyComponent = ({show, ...rest}: MyComponentProps) => {