Skip to content

Instantly share code, notes, and snippets.

@goranprijic
goranprijic / local-date.pipe.ts
Created February 22, 2017 09:28
Using local timezone in angular2 date pipe
import { PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';
import { CONFIG_LOCAL_TIMEZONE_SHIFT } from './../../environment';
export class LocalDatePipe extends DatePipe implements PipeTransform {
transform(value: any, pattern: string = 'mediumDate'): string {
return super.transform(value + CONFIG_LOCAL_TIMEZONE_SHIFT, pattern);
}
@goranprijic
goranprijic / ngNestedResource-app.js
Last active August 29, 2015 14:22
ngNestedResource-example (written for presentation)
// Post Model
angular.module('MyApp')
.factory('PostModel', function(BaseModel) {
var PostModel = BaseModel(
'/posts/:id',
{
id: '@id'
},
{
comments: 'CommentModel'
@goranprijic
goranprijic / bad-model-layer.js
Last active August 29, 2015 14:22
Example of bad Model layer in angular (written for presentation)
// Post Model
angular.module('myApp')
.factory('Post', function($resource) {
var resource = $resource(
'/posts/:id',
{
id: '@id'
},
{
'store': { method: 'POST' },
@goranprijic
goranprijic / BaseModel.php
Created December 17, 2014 10:12
Check if table is already joined in Laravel Query Builder
<?php
class BaseModel extends Eloquent {
public static function isJoined($query, $table)
{
$joins = $query->getQuery()->joins;
if($joins == null) {
return false;
}
@goranprijic
goranprijic / 1-traits.js
Last active August 29, 2015 14:05
Implementing Traits in AngularJS
angular.module('myApp')
.factory('Traits', function() {
return {
apply: function (_class, _trait) {
_.each(_trait, function (method, name) {
_class.prototype[name] = method;
});
}
}
});