Skip to content

Instantly share code, notes, and snippets.

View ftorre104's full-sized avatar

Federico Torre ftorre104

  • San Francisco
View GitHub Profile
@ftorre104
ftorre104 / formatTimeByHowRecent
Created September 2, 2014 15:57
User-friendly timestamp formatting
function formatTimeByHowRecent(rawTimestamp) {
var currentDate = new Date();
//reference times for different displays
var ref = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
var refday = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
var refdayNext = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
var refweek = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
refday.setDate(ref.getDate() - 1);
refdayNext.setDate(ref.getDate() + 1);
refweek.setDate(ref.getDate() - 7);
@ftorre104
ftorre104 / form-validation-snippet.jsx
Last active July 21, 2016 16:30
Form validation in react -- 2 options
// OPTION A
// Handle error/help display logic at the input's parent level
submit() {
this.setState({
emailHasBeenBlurred: true,
pwHasBeenBlurred: true
})
if (validator.email(this.state.value).help ||