Charts Tip #1

Text Rotation

A simple tip if you want to rotate text in x or y axis in google charts. In this example I am rotating horizontal axis text to 65 degrees. The reason why I am doing this is to create more space for labels and also easier to read.

hAxis: {
 textStyle: {
 fontSize: 11
 },
 direction:-1, 
 slantedText:true, 
 slantedTextAngle:65,
 },

google_charts_pic

Link to fiddle for the working example.

If you want to read more on google charts than click here.

Convert chart to Image

Google chart also can be converted into images. If you want to print your google charts or link to other pages can just convert into image.

 google.visualization.events.addListener(chart, 'ready', function () {
 var imgUri = chart.getImageURI();
 // do something with the image URI, like:
 document.getElementById('chartImg').src = imgUri;
 });

Further information can be obtain from google site.

Happy days!!!!

 

Laravel Tips #4

Last Login event registration

Today I worked on my application to record last login date and time for the users. After reading this documentation this is how I implemented in my project.

protected $listen = [
    'Illuminate\Auth\Events\Login' => [
        'App\Listeners\LogLastLogin',
    ],
];

Then ran the artisan command

php artisan event:generate

This artisan command generate events and listeners.
Then update the handle method under Listeners\LogLastLogin.php

public function handle(Login $event)
{
    $event->user->last_login = date('Y-m-d H:i:s');
    $event->user->save();
}

Tested and its working fine. Happy days!!!

Windows Lumia 950 XL

Finally hubby bought his new phone couple of weeks ago. After months of research he finally settled with Windows Lumia 950 XL.  It took a while to be available in New Zealand maybe because the market is very small or some other strategy but I must say some genuine windows fans also live another side of the world.

Not many resellers are available here so we chose the nearest one with reasonable price. We were not surprised why it was cheaper than others as we presumed that the product will be imported from China. It took 7 working days for the phone to arrive in the country.

^C873D0179F72BB71D0E56E79006AE751656AEFE174227FB7DA^pimgpsh_fullsize_distr

 

Configuration was bit of a challenge because everything was setup in Chinese language – phone plus the user guide. Only solution was to google and see if someone has any guidance or you have to figure out own your own.

How to change Lumia 950 XL from Chinese to English?

Swipe from top down, The one to the very right is All Settings (or bottom right when you have expanded, it’s the gear icon)  ==> All settings with gear icon

  1. Tap the gear icon
  2. Tap the Settings menu with the clock and letter A in it, which is 6th one from top
  3. Tap the second from top. You’ll see Chinese in Chinese, tap the line with the + sign to add more languages.
  4. Now you should see a list with the language you want. You cannot remove the Chinese yet, but you will be able to after reboot.
  5. Under the line with the + sign is “restart phone” which may still be in Chinese. Tap that and your phone should restart with the correct language.

As windows operating system you should not be surprised  that the product will be without any bugs.

Some of the issues with the phone so far:

  1. During updates gives false storage indication that it is low on storage
  2. Phone heating problem
  3. Need to hook to charger most of the time
  4. Iris scan setup is just a nightmare have to reset and restart so many times to get it working.
  5. Cortana is not working in New Zealand

After all this, I think hubby is pretty satisfied with his new phone. Still waiting for screen protector and case.

^78A803299FE8ABBECC9D6ABAD8372DCF0A4005FE8BE0E4B013^pimgpsh_fullsize_distr

 

Laravel Tips #3

Using Hashid with Laravel 5

Hashid can be used to to obfuscate id for the url of the web pages. Sometimes we want to prevent the id display for security reasons. Tonight I was working on it so thought to share my experience.

Hashid is a php open-source library which generates ids like  Youtube ids where the numeric id is being converted to alphabets. Example 123 converted to bnt. 

I have used this Laravel 5 wrapper for my project which can be installed via composer.

composer require vinkla/hashids

I have used it to hide the users id so that no one else can use it to edit others account. In user model I have added getRouteKey() method.

User.php

public function getRouteKey() {
    return Hashids::encode($this->getKey());
}

getRouteKey[Name] are implementation of the interface, which lets you create routes like before route(‘users.show’, $user->id) or easier route(‘users.show’, $user). Eloquent objects can be passed as route parameters and Laravel will to the job.

In the controller the id will be passed as obfuscated id therefore we need to decode it before passing the data to database or apply the business logic. Route binding is the easiest way of achieving this.

Routes.php

Route::bind('users', function($user)
{
   return Hashids::decode($user);
});

The userid is being decoded before it is being passed to the controller.

index.blade.php

Laravel does the job to fetch the userid from this.

<a href="{{ route('show_user', [$user]) }}">

Another method:

In the model

protected $appends = ['hashid'];
public function getHashidAttribute()
{
    return Hashids::encode($this->attributes['id']);
}

 

 

Laravel Tips #2

Closed-based routes vs Controller
Closure function – allows to skip the controllers and perform business logic and generate views. Helps to prototype applications quickly or ideal for testing purpose.
As the application grows closed-based routes will become very complex and confusing.
Route::get('cats/{cat}/edit', function(Furbook\Cat $cat) {
    return view('cats.edit')->with('cat', $cat);
});
Controller – loads a dedicated class and easy to maintain.
Routes using controller
Route::resource('users', 'UsersController', [
    'names' => [
        'create' => 'create_user',
        'index'  => 'users_preview',
        'store' => 'save_users',
        'destroy' => 'user_delete',
        'edit' => 'edit_user',
    ]
]);
Controller
public function index()
{

  $users_array = $this->company->companyUsers(Auth::user()->company->first()->id);
   return view("Users::index", compact('users_array'));
}
It better to use the MVC principle and separate the business logic and let route just do the routing job only.

CSS Tips #1

Disable link with CSS.

If you want to disable the link from clicking than this simple CSS will do the trick rather than writing a javascript.

<a href="link.html" class="not-active">Link</a>

.not-active {
   pointer-events: none;
   cursor: default;
}

Urgent vs. Important

This morning I was reading this great article. Thought to share some of my views on this topic.

“What is important is seldom urgent and what is urgent is seldom important.” — Dwight D. Eisenhower

Applying this concept into real business world, when the tasks becomes urgent the company uses all its resources to complete that task as soon as possible. Which results in overuse of resources, time and overall money. In the end the tasks completes at high cost than predicted.

From my own experience at workplace a project was completed and than client noticed some problems. Client started logging those bugs but it was taken very lightly and then client got very upset because he was losing his sales. It came to a point where the client has to take legal action because what was promised is not being delivered. Than all the resources were being used to fix the problem.

If all important tasks are properly planned and delegated than it is less likely for urgency. When the tasks become urgent which results into unhappy client and than poor relationship.

In case if it happens than proactive approach should be taken where you should be prepared and ready for it rather than taking reactive approach.

A business is more likely to fail if they focus on increasing revenue and less in customer satisfaction.

If important tasks are addressed on time than urgency is less likely to happen. Thus failure or delaying in attending important tasks will escalate to urgency.

It is worth investing time in planning and resolving the issues when they are important. A systematic approach should be in place where a task should be properly planned, delegated and supervised.