Skip to content

Instantly share code, notes, and snippets.

View farshidrezaei's full-sized avatar
😏
How you doin'?

Farshid Rezaei farshidrezaei

😏
How you doin'?
View GitHub Profile
@farshidrezaei
farshidrezaei / url-filter.php
Last active May 16, 2019 22:32
Find URLs in String, Make Links
<?php
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// The Text that you want to filter for urls and links
$text = "The text that you want to filter is: https://github.com";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
var randomColor = Math.floor(Math.random()*16777215).toString(16);
<?php
// This is what you might have right now
Route::get('users/{id}', 'UserController@getProfile')->where('id', '[\d+]+');
Route::get('products/{id}', 'ProductController@getProfile')->where('id', '[\d+]+');
Route::get('articles/{slug}', 'ArticleController@getFull')->where('slug', '[a-z0-9-]+');
Route::get('faq/{slug}', 'FaqController@getQuestion')->where('slug', '[a-z0-9-]+');
// and many more, now imagine you'll have to change the rule
// Instead, you could have a handy list of patterns and reuse them everywhere:
// Patterns
@farshidrezaei
farshidrezaei / image-upload.vue
Created May 16, 2019 23:03
VueJS simple upload
<template>
<div>
<small>Change/Upload</small>
<input type="file" @change="onFileChange">
<button class="btn btn-success btn-xs" @click="upload">Upload</button>
</div>
</template>
@farshidrezaei
farshidrezaei / signed-url.php
Last active May 17, 2019 20:11
Simple Signed URL
<?php
//define a route that in action validate signature
Route::get('signed', function (Request $request) {
if ( ! $request->hasValidSignature() ) {
abort( 404 );
}else{
//do something
}
})->name('signed');
@farshidrezaei
farshidrezaei / orientation-lock.scss
Created September 3, 2019 12:42
Orientation Lock
@media screen and (min-width: 320px) and (max-width: 767px) and (orientation: landscape) {
html {
transform: rotate(-90deg);
transform-origin: left top;
width: 100vh;
overflow-x: hidden;
position: absolute;
top: 100%;
left: 0;
}
@farshidrezaei
farshidrezaei / laravel2js.blade.php
Created September 4, 2019 18:28
Use Laravel named routes in Vuejs
<script>
window.Laravel = @json([
'csrfToken' => csrf_token(),
'baseUrl' => url('/'),
'routes' => collect(Route::getRoutes())
->mapWithKeys(function ($route) {
@farshidrezaei
farshidrezaei / replace_faker.php
Created September 7, 2019 18:08
Replace Fakers
<?php
//Faker offers a couple of methods that let you replace placeholders in a given string with random characters:
//lexify - takes given string and replaces ? with random letters
//asciify - takes given string and replaces * with random ascii characters
//numerify - takes given string and replaces # with random digits
//bothify - combines the lexify and numerify
//You could try to use one of them, depending on the requirements you have for that random string you need. asciify uses the largest set of characters as replacement so using that one makes most sense.
//The following will give you a random string of 20 ascii characters:
@farshidrezaei
farshidrezaei / windows-port-killer.bat
Created September 10, 2019 15:42
Bat file for kill and stop a port or process.
@ECHO OFF
cls
:loop
cls
:enterPort
cls
set /P port="Enter a port. [ q => exit ] : "
If "%port%"=="q" goto endLoop
cls
echo.
@farshidrezaei
farshidrezaei / Cors.php
Created December 10, 2019 20:23
Add CORS support, Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.