Skip to content

Instantly share code, notes, and snippets.

@Muzietto
Muzietto / ChartUsingCustomTooltip.js
Last active September 29, 2022 14:53
Recharts Tooltip: how to show only the value of ONE data point inside a tooltip
import React from 'react';
import {
LineChart,
Line,
XAxis,
YAxis,
CartesianGrid,
ReferenceLine,
Tooltip,
} from 'recharts';
@Muzietto
Muzietto / .tmux-creating-panes-at-start.conf
Last active September 27, 2024 13:02
.tmux.conf to create a pane layout at start - NB: launch it with `tmux attach`, and not plain `tmux`
# THIS IS THE PANE LAYOUT CREATED
# pane numbers are relative to the end of the actions
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
# | pane 0 | pane 1 |
# | | |
# | |- - - - - - - - |
# | | pane 2 |
# | | |
# | |- - - - - - - - |
# | | pane 3 |
@Muzietto
Muzietto / useDelayedEffect.js
Last active March 21, 2022 17:18
useDelayedEffect - using setTimeout in React functional components (custom hook)
import { useEffect, useRef } from 'react';
function useDelayedEffect(effect, changingStateVars = [], delay = 1000) {
const mutable = useRef();
const delayedEffect = () => {
mutable.current = setTimeout(effect, delay);
return () => {
clearTimeout(mutable.current);
@Muzietto
Muzietto / css2git2file.sh
Last active June 25, 2019 06:35
Sending git commands about history to a file
#! /bin/bash
for file in `find . -name "*.scss"`; do git log --stat --oneline --pretty=format:"%cd" $file >> pippo3.txt; echo '------' >> pippo3.txt; done
for file in `find . -type f -name "*.js" ! -name "*.stories.js"`; do git log --stat --oneline --pretty=format:"%cd" $file >> pippo4.txt; echo '------' >> pippo4.txt; done
@Muzietto
Muzietto / wget_urls_from_file.sh
Created January 26, 2019 19:00
Shellscript to read urls from a text file and download them one after the other (with some rest in between)
cat urls.txt | while read url; do wget -mpEkL "$url"; sleep 2; done
@Muzietto
Muzietto / Icon.js
Created November 15, 2018 16:21
Scalable import of FontAwesome icons in generic icon component, with Storybook story
import React from 'react';
import PropTypes from 'prop-types';
import './Icon.scss';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
const Icon = ({ icon: iconName, color, backgroundColor, ...rest }) => {
const faIconName = `fa${iconName.replace(/./, c => c.toUpperCase())}`;
const faIcon = require(`@fortawesome/pro-light-svg-icons/${faIconName}.js`)[faIconName];
return (
@Muzietto
Muzietto / animations.js
Last active August 30, 2018 07:37
Simple Swiping Up, compare with the White Rabbit (https://codepen.io/rachelnabors/pen/eJyWzm)
export function playSwipeInAnimation(element, height) {
const ANIMATION_DURATION = 500;
const TIMING = {
duration: ANIMATION_DURATION,
fill: 'forwards',
easing: 'cubic-bezier(0.42,0,0.58,1)',
};
@Muzietto
Muzietto / Preferences.sagas.js
Last active August 29, 2018 09:19
Sagas to write localstorage and read it back. Gotta save info in state instead...
import { call, put, takeLatest, take, race } from 'redux-saga/effects'
import {
SWITCH_BIOMETRIC_UNLOCK_REQUEST,
SWITCH_BIOMETRIC_UNLOCK_REJECTED,
SWITCH_BIOMETRIC_UNLOCK_SUCCESS,
} from './Preferences.actions'
import {
CLOSE_PASSWORD_MODAL,
OPEN_PASSWORD_MODAL,
PASSWORD_VALIDATED,
@Muzietto
Muzietto / DataField.js
Last active August 29, 2018 06:52
React + OnsenUI - Making the form smaller and scrollable when the keyboard pops up. Bonus points because friggin onsenui' Input has no onFocus prop.
import React from 'react'
import ReactDOM from 'react-dom'
import { Input } from 'react-onsenui'
export default class DataField extends React.Component {
componentDidMount() {
this.focusHandler = this.mainInputFocusEventHandler.bind(this)
if (this.mainInput) {
@Muzietto
Muzietto / unobfuscatedRaygunScript.js
Last active December 15, 2017 13:11
This is how Raygun manages to peek into window.onerror and dispatch the error to its servers
!function (
window,
document,
scriptString,
minifiedRaygunScript,
rg4jsString,
domScriptElement,
firstStriptTag,
windowOnError
) {