Skip to content

Instantly share code, notes, and snippets.

Avatar

Capelo antoniocapelo

View GitHub Profile
View batch-wav-to-mp3
for file in *.wav; do lame -V2 "$file" "${file%.wav}".mp3 -b 128; done
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
You can’t perform that action at this time.