Skip to content

Instantly share code, notes, and snippets.

Capelo antoniocapelo

Block or report user

Report or block antoniocapelo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tmux-dev.sh
#!/bin/sh
# place this under /usr/local/bin/tmux-dev
if [ -z "$1" ]
then
echo "No session name supplied"
exit 1
fi
tmux new-session -d -s $1
@antoniocapelo
antoniocapelo / tsx-default-html-props.tsx
Created May 2, 2019
TSX component extending default HTML props
View tsx-default-html-props.tsx
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) => {
@antoniocapelo
antoniocapelo / useWindowSize.js
Created Apr 10, 2019
Custom React Hook for setting a window resize listener and get updated dimensions
View useWindowSize.js
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 / use-scroll-listener.js
Last active Jul 8, 2019
Custom React Hook for setting a passive scroll listener and get updated scrollY and scroll direction information
View use-scroll-listener.js
/**
* useScrollListener hook
* Usage: const { scrollY, scrollDirection } = useScrollListener();
*/
import { useState, useRef, useEffect } from 'react';
export function useScroll() {
const [scrollY, setScrollY] = useState(0);
const [progress, setProgress] = useState(0);
View pipelinefsstyle.css
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;
}
@antoniocapelo
antoniocapelo / queryStringToObject.js
Last active Feb 28, 2016
Transforming query string params into object
View queryStringToObject.js
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 / bearerHttpInterceptor
Created Feb 13, 2015
AngularJS HTTP Interceptor for Bearer Token Auth Requests
View bearerHttpInterceptor
app.factory('BearerAuthInterceptor', function ($window, $q) {
return {
request: function(config) {
config.headers = config.headers || {};
if ($window.localStorage.getItem('token')) {
// may also use sessionStorage
config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem('token');
}
return config || $q.when(config);
},
@antoniocapelo
antoniocapelo / node-server-service.conf
Created Dec 31, 2014
task for nodeJS powered site
View node-server-service.conf
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 / js_screenshot
Created Dec 7, 2014
Snippet for capturing screenshot
View js_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';
}
You can’t perform that action at this time.