Skip to content

Instantly share code, notes, and snippets.

View lkmadushan's full-sized avatar
🏠
Working from home

Kalpa Madushan Perera lkmadushan

🏠
Working from home
View GitHub Profile
@lkmadushan
lkmadushan / JsonSerializer.php
Last active March 16, 2018 13:30
Remove data key from "thephpleague/fractal" serialize output.
<?php
namespace Serializers;
use League\Fractal\Serializer\ArraySerializer;
class JsonSerializer extends ArraySerializer
{
/**
* Serialize a collection
@lkmadushan
lkmadushan / Galaxy Of Tutorial Torrents
Created June 24, 2016 04:04 — forked from iHassan/Galaxy Of Tutorial Torrents
Ultimate Galaxy Of Tutorial Torrents
=============================
**http://kickass.to/infiniteskills-learning-jquery-mobile-working-files-t7967156.html
**http://kickass.to/lynda-bootstrap-3-advanced-web-development-2013-eng-t8167587.html
**http://kickass.to/lynda-css-advanced-typographic-techniques-t7928210.html
**http://kickass.to/lynda-html5-projects-interactive-charts-2013-eng-t8167670.html
**http://kickass.to/vtc-html5-css3-responsive-web-design-course-t7922533.html
*http://kickass.to/10gen-m101js-mongodb-for-node-js-developers-2013-eng-t8165205.html
*http://kickass.to/cbt-nuggets-amazon-web-services-aws-foundations-t7839734.html
@lkmadushan
lkmadushan / Pagination.vue
Last active July 5, 2016 17:48
Simple Laravel + Vue Pagination
<template>
<div>
<nav>
<ul class="pagination">
<li :class="{'disabled': currentPage <= 1}">
<a href="#" @click.prevent="changePage(currentPage - 1)" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li v-for="page in pages"
@lkmadushan
lkmadushan / install.sh
Created October 3, 2016 04:11 — forked from wdullaer/install.sh
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@lkmadushan
lkmadushan / User.php
Created November 21, 2016 09:58 — forked from Ocramius/User.php
Doctrine 2 ManyToMany - the correct way
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity()
* @ORM\Table(name="user")
*/
class User
@lkmadushan
lkmadushan / nginx.conf
Last active May 1, 2021 01:29
NGINX configuration for multi-tenant PHP application
map $http_accept $api_version {
default 0;
"application/vnd.example.v1+json" 1;
}
server {
listen 80;
listen [::]:80;
@lkmadushan
lkmadushan / setup.sh
Last active January 22, 2018 18:44
Nginx and Let's encrypt Setup
#!/usr/bin/env bash
# curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > /opt/nginx/nginx.tmpl
docker run -d -p 80:80 -p 443:443 \
--name nginx \
--restart always \
-v /etc/nginx/conf.d \
-v /etc/nginx/vhost.d \
-v /usr/share/nginx/html \
@lkmadushan
lkmadushan / .aliases
Last active August 11, 2017 09:21
Command aliases
alias ..="cd .."
alias ...="cd ../.."
alias h="cd ~"
alias c="clear"
function ubuntu() {
docker run -it --rm -v $(pwd):/opt -w /opt ubuntu:16.04 "$@"
}
@lkmadushan
lkmadushan / webpack.mix.js
Created November 24, 2017 14:54 — forked from andrewdelprete/webpack.mix.js
Laravel Mix: Tailwind CSS + PurgeCSS Example
let mix = require("laravel-mix");
let tailwindcss = require("tailwindcss");
let glob = require("glob-all");
let PurgecssPlugin = require("purgecss-webpack-plugin");
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
* https://github.com/FullHuman/purgecss-webpack-plugin
*/
@lkmadushan
lkmadushan / eloquent.md
Last active February 19, 2018 06:43
Advance eloquent eager load

Advance Eloquent

Imagine you have two models call User and Activity. The relationship between them is,

User hasMany Activity

If you want to fetch users with their last activity you often need to eager load users with their activities and grab the last one of activities. The trade off that is you are eager loading unwanted activity models and it will be a performance issue when your database grows. Following is a simple trick that you come up with eager loading the last activity of the user.

class User extends Model