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
<script>
export default {
name: 'v-form',
props: [
'route',
'method',
'data',
'sync',
],
data() {
@lkmadushan
lkmadushan / translator.applescript
Last active August 9, 2018 10:33
Translate English to Sinhala AppleScript (Using Automator in Mac)
on run {input, parameters}
set output to "http://translate.google.com/#auto/si/" & urldecode(input as string)
return output
end run
on urldecode(x)
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'"
do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode
@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
@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 / .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 / 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 / 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 / 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 / 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 / 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"