Skip to content

Instantly share code, notes, and snippets.

@ndamnjanovic
ndamnjanovic / hide_angular_expression
Last active August 29, 2015 13:55
hiding angular expressions on load
Angular expressions are crucial while developing Angular application.
Sometimes, while working with them, you may see double curlies
which are actually displayed on page, while it is loading.
Common scenario are titles, headings and different flash messages,
which contain Angular expressions, but which are not always rendered 'on time'.
e.g.
<h1> Welcome back, {{user.name}} </h1>
There are several ways to prevent user from seeing those:
# Zwivel Ad Platform
## Requirements
- PHP >= 5.5.9
- check your php version with **php -v** from command line
- PHP Extensions
- OpenSSL PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
APP_ENV=stage
APP_DEBUG=true
APP_KEY=TuOO60ykdxiBM7E8TTOa1cTxpihHqxvs
DB_HOST=localhost
DB_DATABASE=stage_zwivel_advertising
DB_USERNAME=root
DB_PASSWORD=root
CACHE_DRIVER=file
@ndamnjanovic
ndamnjanovic / eloquent_eager_loading
Last active December 26, 2015 18:49
Laravel 4 - Eager loading
Assume we have a following situation:
- We have a task that has associated checklists (one or many).
- Every checklist has associated items (again, one or many).
In Laravel 4, we can use Eager Loading to fetch all associated data.
Let's take a look.
First, we have have a TaskChecklistItem model as following:
@ndamnjanovic
ndamnjanovic / accessor_laravel_4
Created October 28, 2013 14:34
Extending Model using Laravel 4
Sometimes we need to extend out model, with more than data that is fetched from database, for example.
But on the other hand, we don't want to do that manually, and we want our framework to do that instead of us.
Here's an example, how to do that using Laravel 4.
Assume we have model Task, that has some fillable columns. Beside those, predefined columns, we want to attach additional data, let's say, parent task (and all its data).
First, we will define relationship between 'task' and 'task parent'. It is one-to-many relationship. We'll do it based on column named 'parent_id'.
public function parentTask(){
@ndamnjanovic
ndamnjanovic / updating_related_model_laravel_4
Last active December 26, 2015 23:49
Updating related models Laravel 4
@ndamnjanovic
ndamnjanovic / writing_test_tips
Created October 31, 2013 10:13
Tips when writing tests in Laravel 4
TIP 1: Exception when performing many requests
-----------------------------------------------------------------------------------------------
If you have more than one $this->call() or $this->client->request(), inside one test method,
you may experience problems like:
{"error":{"type":"ErrorException","message":"Undefined variable: header","file":"/*,"line":1}}
or
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
You can solve this problem, if you do $this->client->restart(), before every next request that you're making.
@ndamnjanovic
ndamnjanovic / angular-ng-hide-ng-if
Created January 21, 2014 09:19
angular - conditionally displaying of html blocks
In AngularJS, you have several ways to display/hide some HTML block.
I'll mention most common one, and point out main differencies between them.
1. ng-hide/ng-show: By using these two directives, you can hide or show html block, by simple passing expression. Example:
<div ng-hide='checked' > Hide me, if checked is true </div>
2. another way of doing same thing, is to use ng-class. You can conditionally apply some class to HTML block, and by doing that, hide or show it.
@ndamnjanovic
ndamnjanovic / cancel_route
Last active January 4, 2016 03:29
angular authentication and routing
In case you want to do authentication and redirection, depending on whether user is logged in or not,
you can do it by listening $routeChangeStart event.
This way, you don't need to use additional plugins,
or to add 'resolve' parameters to your routes (which can be difficult to maintain).
In following example, if non-logged user tries to reach authenticated route, user will be redirected to login page.
If logged user tries to reach login/register page, user will be redirected to home page.
$rootScope.$on('$routeChangeStart', function(event, next, current){
if(AuthFactory.isAuthenticated()){
'use strict';
_app
.provider("$exceptionHandler", {
$get: function( ErrorLogService ) {
return( ErrorLogService );
}
}
)
.factory('ErrorLogService', function($log, $window, stacktraceService, routes) {