Skip to content

Instantly share code, notes, and snippets.

View antoniocapelo's full-sized avatar

Capelo antoniocapelo

View GitHub Profile
@antoniocapelo
antoniocapelo / batch-wav-to-mp3
Created November 6, 2019 17:32
Batch wav to mp3
for file in *.wav; do lame -V2 "$file" "${file%.wav}".mp3 -b 128; done
@antoniocapelo
antoniocapelo / tmux-dev.sh
Created August 26, 2019 09:58
tmux dev session
#!/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 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) => {
@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 / use-scroll-listener.js
Last active July 8, 2019 09:57
Custom React Hook for setting a passive scroll listener and get updated scrollY and scroll direction information
/**
* 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);
:set backupcopy=yes
@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;
}
@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 / bearerHttpInterceptor
Created February 13, 2015 21:14
AngularJS HTTP Interceptor for Bearer Token Auth Requests
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 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