Skip to content

Instantly share code, notes, and snippets.

View jvadillo's full-sized avatar
💭
Code, Learn & Teach

Jon jvadillo

💭
Code, Learn & Teach
View GitHub Profile
@jvadillo
jvadillo / splitCSV.js
Created March 8, 2020 17:39
Split CSV
function splitCsv(str) {
return str.split(',').reduce((accum,curr)=>{
if(accum.isConcatting) {
accum.soFar[accum.soFar.length-1] += ','+curr
} else {
accum.soFar.push(curr)
}
if(curr.split('"').length % 2 == 0) {
accum.isConcatting= !accum.isConcatting
}
@jvadillo
jvadillo / readme.md
Last active October 14, 2019 07:28
Laravel: How to add new column to existing table using migration

Lanzar el comando:

php artisan make:migration add_columnA_to_tableX

Esto creará la migración add_columnA_to_tableX:

class AddcolumnAToTableX extends Migration
@jvadillo
jvadillo / RedirectIfAuthenticated.php
Created October 21, 2018 11:06
Redirect after login depending on user role
//Edit the following function (RedirectIfAuthenticated.php):
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
//return redirect('/inicio');
if(Auth::user()->hasAnyRole('admin')){
return redirect()->route('datos');
}
else if (Auth::user()->hasAnyRole('club','equipo')){
@jvadillo
jvadillo / examples.php
Created October 21, 2018 11:00
Named routes in laravel
// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');
$url = route('profile', ['id' => 1]);
@jvadillo
jvadillo / UserController.php
Last active October 3, 2018 22:23
Laravel form field validators
use Illuminate\Support\Facades\Validator;
/* Primer se definen los mensajes de error */
$messages = [
'required' => 'El campo :attribute es obligatorio.',
/* Mensaje específico para el campo "email-acceso" */
'email-acceso.unique' => 'El email de acceso ya existe.',
'unique' => 'El :attribute ya existe.',
];
@jvadillo
jvadillo / UserController.php
Created September 23, 2018 10:29
Handle search with filters in PHP with Laravel an Eloquent
public function filter(Request $request, User $user)
{
$user = $user->newQuery();
// Search for a user based on their name.
if ($request->has('name')) {
$user->where('name', $request->input('name'));
}
// Search for a user based on their company.
@jvadillo
jvadillo / MySQL_Enable_Logs.ini
Created December 20, 2017 08:00
Activate logs in Xampp-Mysql
# The MySQL server
[mysqld]
#Enable Slow Query Log
long_query_time = 1
slow_query_log_file = "C:/slowquery.log"
#Do NOT Start Logging on Startup
slow_query_log = 1
@jvadillo
jvadillo / comments.php
Created December 9, 2017 12:37
PHP Comments
Functions:
/**
* Does something interesting
*
* @param Place $where Where something interesting takes place
* @param integer $repeat How many times something interesting should happen
*
* @throws Some_Exception_Class If something interesting cannot happen
* @author Monkey Coder <mcoder@facebook.com>
@jvadillo
jvadillo / session.js
Created November 10, 2017 09:51
Access to PHP SESSION datda from JavaScript
You can produce the javascript file via PHP. Nothing says a javascript file must have a .js extention. For example in your HTML:
<script src='javascript.php'></script>
Then your script file:
<?php header("Content-type: application/javascript"); ?>
$(function() {
$( "#progressbar" ).progressbar({
value: <?php echo $_SESSION['value'] ?>
@jvadillo
jvadillo / fetch-jsonp-example.js
Created August 2, 2017 07:23
How to use fetch-jsonp library
import fetchJsonp from 'fetch-jsonp';
function handleSearch(user){
//let url = 'https://api.github.com/users/'+user+'/repos';
const token = '304163526.e0b4176.e924858e024645989aae580c6523aee0';
let url = 'https://api.instagram.com/v1/tags/akebaso/media/recent?access_token=304163526.e0b4176.e924858e024645989aae580c6523aee0';
fetchJsonp(url, {
method: 'GET',
mode: 'no-cors',