This gist was getting a lot of comments/questions, but since there are no notifications when someone replies to a gist, I've moved the setup instructions and a bunch of sample code to a dedicated Github repo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function omit(object, fields) { | |
const shallowObject = Object.assign({}, object); | |
if (typeof fields === Array) { | |
fields.forEach(field => { | |
if (!!shallowObject[field]) delete shallowObject[field]; | |
}); | |
return shallowObject; | |
} else if (typeof fields === "string") return delete shallowObject[fields]; | |
else throw new Error(`fields ${fields} must be array or string`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? php | |
public function validate($startDate, $endDate) { | |
$rules = [ | |
'startDate' => 'date_format:Y-m-d', | |
'endDate' => 'date_format:Y-m-d', | |
]; | |
$validator = Validator::make(['startDate' => $startDate, 'endDate' => $endDate], $rules); | |
if ($validator->fails()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Draggable { | |
constructor() { | |
this.container = document.querySelector('.box__dragabble'); | |
this.box = document.querySelectorAll('.box'); | |
this._addEventListener(); | |
} | |
_addEventListener() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import Bus from '../Utils/Bus'; | |
import './index.css'; | |
export const Flash = () => { | |
let [visibility, setVisibility] = useState(false); | |
let [message, setMessage] = useState(''); | |
let [type, setType] = useState(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import './index.css'; | |
export const Flash = () => { | |
let [visibility, setVisibility] = useState(false); | |
let [message, setMessage] = useState(''); | |
let [type, setType] = useState(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('preview-emails', function () { | |
$message = (new \App\Notifications\Order\NewOrderNotification(\App\Order::first()))->toMail('[email protected]'); | |
return $message->render(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var router = express.Router(); | |
const User = require('../models/user'); | |
/* GET users listing. */ | |
router.post('/', function(req, res, next) { | |
const user = new User({ | |
email: req.body.email, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserSchema.pre('save', function(next) { | |
let user = this; | |
if(!user.isModified('password')) return next(); //password has not modified | |
bcrypt.genSalt(10, function (err, salt) { | |
bcrypt.hash(user.password, salt, function (err, hash) { | |
if(err) return next(err); | |
user.password = hash; | |
next(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const server = app.listen(3001, function() { | |
console.log('server running on port 3001'); |
NewerOlder