- https://speakerdeck.com/willroth/50-laravel-tricks-in-50-minutes
- https://www.reddit.com/r/laravel/comments/3to60i/50_laravel_tricks/
- 1. Automatic Model Validation
| public function run() { | |
| DB::unprepared(File::get('path/to/SQL/file')); | |
| } |
| <?php | |
| //https://github.com/laravel/framework/issues/2093#issuecomment-39154456 | |
| use Illuminate\Database\Eloquent\Model as Eloquent; | |
| use Illuminate\Database\Eloquent\Relations\Pivot; | |
| class User extends Eloquent { | |
| public function groups() { | |
| return $this->belongsToMany('Group'); |
| import os | |
| from time import time | |
| import urllib | |
| import multiprocessing | |
| from progressbar import ProgressBar | |
| img_dir = '/home/luke/datasets/sbu/images' | |
| def get_sbu_urls(): | |
| # read in urls |
| // Run this in the F12 javascript console in chrome | |
| // if a redirect happens, the page will pause | |
| // this helps because chrome's network tab's | |
| // "preserve log" seems to technically preserve the log | |
| // but you can't actually LOOK at it... | |
| // also the "replay xhr" feature does not work after reload | |
| // even if you "preserve log". | |
| window.addEventListener("beforeunload", function() { debugger; }, false) |
| # Elasticsearch Cheatsheet - an overview of commonly used Elasticsearch API commands | |
| # cat paths | |
| /_cat/allocation | |
| /_cat/shards | |
| /_cat/shards/{index} | |
| /_cat/master | |
| /_cat/nodes | |
| /_cat/indices | |
| /_cat/indices/{index} |
| <?php | |
| function getRandomTimestamps($backwardDays = null) | |
| { | |
| if ( is_null($backwardDays) ) | |
| { | |
| $backwardDays = -800; | |
| } |
| from datetime import datetime | |
| from elasticsearch_dsl import ( | |
| DocType, | |
| String, | |
| Integer, | |
| Float | |
| ) | |
| def _suffix(): |
| <?php | |
| /* | |
| * Place this with the rest of your rules. | |
| * Doesn't need to be in an array as there are no pipes. | |
| * Password is required with a minimum of 6 characters | |
| * Should have at least 1 lowercase AND 1 uppercase AND 1 number | |
| */ | |
| $rules = [ | |
| 'password' => 'required|min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/' | |
| ]; |