Skip to content

Instantly share code, notes, and snippets.

View alfredoem's full-sized avatar

Alfredo Espiritu alfredoem

  • Lima/Perú
View GitHub Profile
@alfredoem
alfredoem / 0_reuse_code.js
Created March 3, 2017 22:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@alfredoem
alfredoem / basic_coding_standard.md
Last active January 9, 2017 14:24
Basic Coding Standard
  1. StudlyCaps for class names, namespaces and file names of classes
  2. camelCase for property, method and variable names
  3. UPPER_SNAKE_CASE for constants
  4. snake_case for service and parameter names in the Symfony service container and for names of templates and configuration files
'use strict';
var gulp = require('gulp');
var path = require('path');
var livereload = require('gulp-livereload');
var API_HTML = 'index.html';
var API_DEST = './public/project/reference/v1';
function raml2html(options) {
@alfredoem
alfredoem / Homestead.yaml
Created January 4, 2017 15:49
Homestead per project config
---
box: laravel/homestead-7
version: 0.2.1
ip: "192.168.10.20"
memory: 2048
cpus: 1
name: antifraud
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
@alfredoem
alfredoem / api-pagination-response-example.json
Created January 4, 2017 13:43
API endpoint pagination data in response body or header
{
"page": 1,
"pageSize": 2,
"rowCount": 380,
"pageCount": 190
}
@alfredoem
alfredoem / lumen_tricks.php
Created October 14, 2016 14:49
Laravel/Lumen Tricks
# Get Routes Parameters
/**
* Get a given parameter from the route.
*
* @param $name
* @param null $default
* @return mixed
*/
function route_parameter($name, $default = null)
@alfredoem
alfredoem / php_tricks.php
Created October 13, 2016 20:10
PHP Tricks
// Search recursive
array_search($value, array_column($resource, 'key'))
<?php
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
// you want to allow, and if so:
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');// cache for 1 day
}
@alfredoem
alfredoem / laravel-ajax-pagination.js
Last active July 26, 2016 14:47
Laravel - Pagination with jQuery.ajax
$(document).on('click', '.pagination a', function (e) {
$('.pagination').find('li').removeClass('active disabled');
$(this).parent().addClass('active');
let page = $(this).attr('href').split('page=')[1];
let request = $.ajax({url : 'todo?page=' + page, dataType: 'json'});
request.done(function (res) {
// handle res
<script>
(function(){
fetch('/endpoint', {method: 'get'}).then(function (response) {
return response.json();
})
.then(function (body) {
console.log(body);
});