Skip to content

Instantly share code, notes, and snippets.

View kapv89's full-sized avatar

kapil verma kapv89

  • Bangalore, India
  • 05:00 (UTC +05:30)
View GitHub Profile
@kapv89
kapv89 / api.dev
Created September 29, 2013 15:18
nginx api conf
server {
server_name api.foo.dev;
listen 80;
access_log /var/log/nginx/api.foo.dev.access.log;
error_log /var/log/nginx/api.foo.dev.error.log;
root /home/user/Projects/foo/server/api/public;
@kapv89
kapv89 / cors-nginx.conf
Created September 29, 2013 15:08
cors-nginx
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,$cors_headers';
add_header 'Access-Control-Expose-Headers' $cors_headers;
# dafuq are these
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';

We are gonna be using php5.5 , so upgrade your systems to that.

  1. http://laravel.com/docs/contributing#coding-guidelines , we follow these, along with PSR-0 and PSR-1.

  2. use Foo (aliasing) etc statements should start from the 3rd line. Each class that needs to be used in a namespace has to be aliased in a separate line.

  3. Aliasing is important. You shouldn't be using more than two Namespace Separators (\) in the code that you right in your classes. Try to restrict the count of those namespace separators to one.

  4. No accessing global namespace (ie, \Foo is not allowed, you need to alias the class Foo via use Foo). The only exception for this is php spl exception classes.

@kapv89
kapv89 / SingleTableInheritance.php
Created July 28, 2013 23:39
Abstract Eloquent Use Case
class Order extends AbstractEloquent {
protected $isSuperType = true;
protected $typeField = 'class';
}
namespace Order;
class Delivery extends Order {
protected $isSubType = true;
}
@kapv89
kapv89 / AbstractEloquent.php
Last active December 20, 2015 08:29
Single Table inheritance model
use Illuminate\Database\Eloquent;
use Illuminate\Database\Eloquent\Builder;
abstract class AbstractEloquent extends Eloquent\Model {
protected $isSuperType = false; // set true if super-class model
protected $isSubType = false; // set true in inherited models
protected $typeField = 'type'; //override as needed, only set on the super-class model
/**
* Provide an attributes to object map
@kapv89
kapv89 / gist:5817677
Last active December 18, 2015 17:19
An ajax service free of all the angular http hassles (implements promises jquery style)
$provide.factory('$ajax', function ($rootScope) {
return function (options, callbacks, ctx) {
if(typeof(callbacks) === 'function') {
callbacks = { success: callbacks, error: function (data) { console.log(data) } };
}
options.success = function (data) {
ctx ? callbacks.success.call(ctx, data) : callbacks.success(data);
$rootScope.$digest();
.when('/cart/pickup', {
bodyTmplUrl: '/tmpls/cart/pickup.html',
widgetTmplUrl: '/tmpls/cart/orderer.html'
})
.when('/cart/delivery', {
bodyTmplUrl:'/tmpls/cart/delivery.html',
widgetTmplUrl: '/tmpls/cart/orderer.html'
})
.when('/login', {
bodyTmplUrl: '/tmpls/auth/login.html'
angular.module('sorter').controller('AppCtrl', function ($scope, $uri, $route, $location, $window) {
var navItem = function (slug) {
var item = {
title : slug[0].toUpperCase() + slug.slice(1),
slug : slug,
uri : $uri.page(slug)
};
item.isActive = function () {
<div class="row sorter-container" ng-app="sorter" ng-controller="AppCtrl">
<div class="span10">
<div class="row">
<div class="span10">
<ul class="nav nav-pills">
<li ng-repeat="item in navItems" ng-class="item.isActive() && 'active' || ''">
<a href="{{item.uri}}">{{item.title}}</a>
</li>
</ul>
</div>
@kapv89
kapv89 / gist:5817622
Created June 19, 2013 20:11
a sample router
angular.module('sorter').config(function ($routeProvider, $locationProvider) {
// code fuplicated here, cos can't find a way to use custom service in config
var $uri = (function () {
var pageBase = '/admin/classification/sorter/app/', tmplBase = '/js/sorter/tmpls/',
apiBase = '/admin/classification/sorter/api/'
return {
page: function (uri) { return pageBase + uri; },
tmpl: function (uri) { return tmplBase + uri; },
api: function (uri) { return apiBase + uri; }