Skip to content

Instantly share code, notes, and snippets.

View abonello's full-sized avatar

Anthony Bonello abonello

View GitHub Profile
@abonello
abonello / DatePicker.js
Last active December 30, 2021 21:38 — forked from stevensacks/DatePicker.js
React Bulma DatePicker
import {addDays, format, isAfter, isBefore, startOfDay} from 'date-fns';
import React, {Component, Fragment} from 'react';
import classes from 'classnames';
import DatePickerDialog from './DatePickerDialog';
import Dialog from 'components/Dialog';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {getDisabled} from '../../../utils/component';
import PropTypes from 'prop-types';
import './index.css';
@abonello
abonello / output
Created December 30, 2021 20:26 — forked from rxaviers/output
List of all JavaScript timezones (date.toString()) on linux node.js
/usr/share/zoneinfo/Hongkong
> Wed Jan 01 2014 00:00:00 GMT+0800 (HKT)
> Mon Sep 01 2014 00:00:00 GMT+0800 (HKT)
/usr/share/zoneinfo/Pacific/Easter
> Wed Jan 01 2014 00:00:00 GMT-0500 (EASST)
> Mon Sep 01 2014 00:00:00 GMT-0600 (EAST)
/usr/share/zoneinfo/Pacific/Norfolk
> Wed Jan 01 2014 00:00:00 GMT+1130 (NFT)
@abonello
abonello / onpubcom_array_date_sort.js
Created December 30, 2021 20:24 — forked from onpubcom/onpubcom_array_date_sort.js
How to Sort an Array of Dates with JavaScript
<script type="text/javascript">
// First let's create an array of JavaScript Date
// objects.
// More info about the Date class:
// http://w3schools.com/js/js_obj_date.asp
var dates = [
new Date(2010, 4, 10, 10, 07, 16),
new Date(2010, 4, 8, 9, 16, 09),
new Date(2010, 3, 30, 0, 15, 49),
@abonello
abonello / getDates.js
Created December 30, 2021 20:22 — forked from miguelmota/getDates.js
Get dates in between two dates with JavaScript.
// Returns an array of dates between the two dates
function getDates (startDate, endDate) {
const dates = []
let currentDate = startDate
const addDays = function (days) {
const date = new Date(this.valueOf())
date.setDate(date.getDate() + days)
return date
}
while (currentDate <= endDate) {
@abonello
abonello / format.date.js
Created December 30, 2021 20:21 — forked from ptquang86/format.date.js
JavaScript Date Format
//http://blog.stevenlevithan.com/archives/date-time-format
//http://stevenlevithan.com/assets/misc/date.format.js
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
@abonello
abonello / useSafeState.tsx
Created December 30, 2021 20:18 — forked from codemile/useSafeState.tsx
Here is a useSafeState hook that ignores state changes after a component has been unmounted.
import {
DependencyList,
Dispatch,
MutableRefObject,
SetStateAction,
useCallback,
useEffect,
useRef,
useState
} from 'react';
@abonello
abonello / strings.ts
Created December 30, 2021 20:18 — forked from codemile/strings.ts
Some handy string functions written in TypeScript
/**
* "document_id" -> "document id"
* "documentId" -> "document id"
*/
export const toSpaces = (str: string): string =>
str && str
.replace(/[-_]/g, ' ')
.replace(/([A-Z])/g, ' $1');
/**
@abonello
abonello / useLogger.tsx
Created December 30, 2021 20:18 — forked from codemile/useLogger.tsx
A simple logging hook for React
import {useMemo} from 'react';
/**
* Prevents React.DOM from replacing methods inside hooks.
*/
const ref = {
log: console.log,
error: console.error,
debug: console.debug
};
@abonello
abonello / useInterval.tsx
Created December 30, 2021 20:17 — forked from codemile/useInterval.tsx
A interval hook you can use in your ReactJS projects
import {DependencyList, useEffect, useMemo} from 'react';
export const useInterval = (
callback: () => void,
ms: number,
deps: DependencyList
) => {
const all_deps = useMemo(
() => [callback, ms, ...deps],
// eslint-disable-next-line react-hooks/exhaustive-deps
@abonello
abonello / Repeater.tsx
Created December 30, 2021 20:17 — forked from codemile/Repeater.tsx
Repeater triggers the onRepeat event multiple times at the speed interval.
import {FC, useEffect} from 'react';
export interface RepeaterProps {
disabled?: boolean;
emitFirst?: boolean;
onRepeat: () => void;
speed: number;