These are the most useful Regular Expressions that I find myself using on a regular basis
Test to see if a string is a valid website address or not.
/* | |
* This script will look for all images on a page and prevent right clicking on an image. | |
*/ | |
const images = document.getElementsByTagName('img'); | |
for(var i = 0; i < images.length; i++) { | |
images[i].addEventListener('contextmenu', event => event.preventDefault()); | |
} | |
// Note: I threw this script together as requested by a subscriber. I personally don't recommend doing |
so ~/.vim/plugins.vim " Source from plugins | |
set nocompatible " Disable vi-compatibility | |
syntax on " Enable syntax highlighting | |
" Pathogen plugin specific | |
execute pathogen#infect() | |
filetype plugin indent on " Pathogen | |
set background=dark " Set bg to dark |
# | |
# REQUIRES: | |
# - server (the forge server instance) | |
# - event (the forge event instance) | |
# - sudo_password (random password for sudo) | |
# - db_password (random password for database user) | |
# - callback (the callback URL) | |
# |
git
git add
git add --all
git apply
git add --patch
git add --update
git branch
git branch -a
git branch -d
git blame -b -w
_.mixin({ | |
chunks: function(arr, size) { | |
var len = arr.length, | |
chunk_len = Math.ceil(len/size), | |
chunks = []; | |
for (var i = 0; i < chunk_len; i++) { | |
chunks.push(arr.slice(i*size, (i+1)*size)); | |
} | |
return chunks; | |
} |
<?php | |
public function setSlugAttribute($value) | |
{ | |
$slug = str_slug($value); | |
$original = $slug; | |
$count = 2; | |
while (static::whereSlug($slug)->exists()) { | |
$slug = "{$original}-" . $count++; |
<?php | |
/** | |
* For this to work you don't need to do anything, | |
* just add this Sluggable Trait inside your Model | |
*/ | |
namespace App\Traits; |
<?php | |
/** | |
* PHP v7+ | |
* Remember for this to work, in your controller you need to do: | |
* $model->slug = request('title') | |
* columns name are: title and slug | |
*/ | |
namespace App\Traits; |
Steps to install and run PostgreSQL using Homebrew (Mac OS X) (if you aren't using version 9.1.5, change line 6 with the correct version)
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
brew update
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/
9.4.6/bin -B /usr/local/Cellar/postgresql/
9.4.6/bin -d /usr/local/var/postgres -D /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/
9.4.6/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start