Skip to content

Instantly share code, notes, and snippets.

View kapv89's full-sized avatar

kapil verma kapv89

  • Bangalore, India
  • 14:49 (UTC +05:30)
View GitHub Profile
@kapv89
kapv89 / ajax.js
Created October 15, 2013 22:10
a jquery.ajax based replacement for angular http layer
define(function () {
return [
'$rootScope', '$q', 'session',
function ($rootScope, $q, session) {
var ajax = function (options) {
var deferred = $q.defer();
var success = function (data, status, xhr) {
@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:5915618
Last active June 6, 2016 00:17
As yet untested, ajax service for angular operating on jQuery.ajax to avoid all cross browser hassles
define(function () {
return [
'$rootScope', '$q', 'session',
function ($rootScope, $q, session) {
var ajax = function (options) {
var promise = (function () {
var deferred = $q.defer();
@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 () {