Skip to content

Instantly share code, notes, and snippets.

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

Alexandre Behaghel AlexGeb

🏠
Working from home
View GitHub Profile
ffmpeg -ss 30 -i input.mp4 -an -filter:v "setpts=0.09*PTS" result.mkv
@AlexGeb
AlexGeb / app.js
Created October 1, 2018 08:47
List of Formik forms :
import React, { Component } from "react";
import { Formik, FastField, ErrorMessage } from "formik";
import * as Yup from "yup";
const schemaForm1 = Yup.object().shape({
email: Yup.string()
.email("Invalid email")
.required("Required"),
password: Yup.string()
.min(2, "Too Short!")
@AlexGeb
AlexGeb / api.py
Last active January 20, 2020 23:32
Deploy monorepo flask app now v2
from flask import Flask, Blueprint
from flask_cors import CORS
from flask_restplus import Resource, Api, fields
from flask_restplus.reqparse import Argument
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
CORS(app)
app.wsgi_app = ProxyFix(app.wsgi_app)
blueprint = Blueprint('api', __name__, url_prefix='/api')
@AlexGeb
AlexGeb / PercentageNumber.js
Last active January 4, 2019 09:43
NumberFormat for displaying percentage with '%' suffix
function PercentageNumber(props) {
const { value, inputRef, onChange, fieldName, ...other } = props;
return (
<NumberFormat
{...other}
value={value * 100}
decimalScale={2}
getInputRef={inputRef}
onValueChange={values => {
onChange(values.value / 100);
// @flow
export const deepUndefinedSearch = (obj: any): boolean =>
obj instanceof Object && obj.constructor === Object
? Object.keys(obj)
.map(key => {
if (obj[key] instanceof Array) {
return (
obj[key].map(o => deepUndefinedSearch(o)).filter(o => !o)
.length === 0
@AlexGeb
AlexGeb / ProjectTasksTabWrap.js
Created January 25, 2019 15:41
Proper way of using createSelector from 'reselect'
// @flow
import { compose } from 'recompose';
import { connect } from 'react-redux';
import { fetchTasks } from 'redux/entities/tasks/actions';
import { selectTasksByProjectId } from 'redux/entities/tasks/selectors';
import ProjectTasksTab from './ProjectTasksTab';
// This hook has the same behavior of useState, but takes a method as second parameter
// to be called with the state value on component unmount.
const useStateOnUnmount = <StateType>(
initialState: ?StateType,
onUnmount: (?StateType) => any,
) => {
const stateRef = useRef(initialState);
/* eslint-disable no-unused-vars */
const [_, setState] = useState(stateRef.current);
// Number with 2 decimals maxi
const regex = /^[0-9]*(\.[0-9]{1,2})?$/
"1.12".match(regex) // true
".1".match(regex) // true
".".match(regex) // false
".123".match(regex) // false
const binomialCoefficient = (n: number, k: number): number => {
if (k < 0 || k > n) {
return 0;
}
if (k === 0 || k === n) {
return 1;
}
if (k === 1 || k === n - 1) {
return n;
}
@AlexGeb
AlexGeb / effectFromFpTs.ts
Last active November 22, 2023 13:33
fp-ts to effect conversions
import { Context, Effect, pipe } from 'effect';
import { either } from 'fp-ts';
import { ReaderTaskEither } from 'fp-ts/ReaderTaskEither';
import { TaskEither } from 'fp-ts/TaskEither';
export const effectFromEither = either.matchW(Effect.fail, Effect.succeed);
export const effectFromTaskEither = <E, A>(
program: TaskEither<E, A>,
): Effect.Effect<never, E, A> =>