Nikola Brežnjak blog - Tackling software development with a dose of humor
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Home
Daily Thoughts
Ionic
Stack Overflow
Books
About me
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Nikola Brežnjak blog - Tackling software development with a dose of humor
Books

The Game – Anders de la Motte

My favourite quotes from the book The Game by Anders de la Motte:

If you don’t change, then what’s the point of anything happening to you?

Fear is a powerful weapon, my brother, very powerful. If you play this well, you can keep people under control, make them to focus on stupid things and divert their attention from the really important things like human rights and personal freedoms. This functions in both ways.

The greatest trick the devil ever pulled was convincing the world he didn’t exist.

If you’re aware of your illness, it doesn’t mean your healthy.

Stack Overflow

How to create a table based on few columns of another table, but also add some additional columns

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

So, my question was as follows:

I know I can do something like this:

CREATETABLE new_table AS(SELECT field1, field2, field3
    FROM my_table
)

I’m wondering how do I add more columns to this create table SQL, that are not from my_table, but instead ones that I would write my self and which would be unique to this new_table only.

I know I could just make the table with the above SQL and then additionaly (after the command is completed) add the necessary columns, but am wondering if this all could be done in one command, maybe something like this (tried it like that, but didn’t work):

CREATETABLE new_table AS((SELECT field1, field2, field3
    FROM my_table),
    additional_field1 INTEGER NOTNULLDEFAULT1,
    additional_field2 VARCHAR(20)NOTNULLDEFAULT1)

The answer, by user Omesh, was this:

You can also explicitly specify the data type for a generated column:

See Create Table Select Manual

CREATETABLE new_table
(
 additional_field1 INTEGER NOTNULLDEFAULT1,
 additional_field2 VARCHAR(20)NOTNULLDEFAULT1)AS(SELECT id, val,1AS additional_field1,1AS additional_field2
 FROM my_table
);

Example: SQLFiddle

Books

Rich dad, poor dad – Robert T. Kiyosaki

My favourite quotes from the book Rich dad, poor dad by Robert T. Kiyosaki:

The love of money is the root of all evil versus the lack of money is the root of all evil.

Sadly, money is not taught in school.

One said “I can’t afford it”, the other “how can I afford it?“. One is a statement, the other question which forces you to think! If you say I can’t afford it – your brain stops, if however you say/ask “how can I afford it” you force your brain to think.

Proper physical exercise increases your chances for health and proper mental exercises increase your chances of wealth.

Taxes punish those who produce!, versus the statement that the rich should give the poor and pay more taxes.

Study hard so you could find a good company to work for versus study hard to find a company you could buy.

The reason why I’m not rich is why I have you kids versus the reason why I must be rich is because I have you kids.

Learn to manage risk.

Money is power.

There is a difference between being poor and being broke – being broke is temporary, being poor is forever.

Study to be rich, understand how money works and learn to have it work for me.

Money comes and goes, but if you have the education on how the money works you’ll gain power over it and you can begin building wealth.

The poor and the middle class work for money, rich people have money work for them.

Hurt is good – it inspires you to make money.

Most people only talk and dream about getting rich, You tried to do something!

Some just let life push them around, others get angry and push back. But they push back against their boss or their job, or their husband and wife, they do not know that it’s life who’s pushing. If you do not fight back you will spend your life blaming your job, boss, little pay for your problems. You live your life hoping for that big break that will solve all your money problems. If you have no guts you’ll just give up every time life pushes you – you will live your life safe – you die a boring old man. So, fight and go for it motherfucker.

Rat race – get up, go to work, pay bills – get and increased salary, spend more.

Once a person stop searching for information and self moment ignorance sets in.

It’s not how much money you make it’s how much money you keep.

Buy assets, not liabilities. Asset is something that puts money in your pocket and liability something that takes it out.

Financial literacy, investing, understanding markets, the law.

People who avoid failure, also avoid success.

Schools often the reward people who study more and more about less and less. You should know little about a lot.

Workers work hard enough not to get fired, and owners they just enough so that workers won’t quit. That’s a wrong moto.

Life is much like going to the gym. The most painful part is deciding to go.

Give and you shall receive.

I have never really met anyone that likes losing money. And in all my years I have never met a rich person who has never lost money. But, I have met a lot of poor people who have never lost a dime. Investing that is.

Everyone wants to go to heaven but no one wants to die.

Do what you feel in your heart to be right. For you’ll be criticized anyway.

It is not what you know, it is how fast you can learn something new.

For winners – loosing inspires them. For losers – loosing defeats them.

What I find funny is that so many poor or middle class people insist on flipping restaurant help 15 to 20% even for bad service, but complain paying a broker 3 to 7%.

Too often today we focus on borrowing money to get the things we want instead of focusing on creating money.

Insanity – doing the same thing over and over again and expecting a different result. Stop and see what is it that you’re doing that is not working and do something new.

Find someone who has done what do you want to do. Take them to lunch.

Take classes, read and attend seminars.

Make offers, someone may accept.

Profits are made in that buying, nothing in selling – prices go up in the neighborhood and people start buying – wrong!

Don’t play it safe – play it smart.

Risk comes from not knowing what you’re doing.

Stack Overflow

Need a replacement for jQuery datatables plugin as it’s too slow

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

So, my question was as follows:

I’ve been using jQuery datatables plugin for about two years now and it worked great so far. The problem occured now when I need to load about 45000 records at once (you click the button and wait for the page with the data to load) – the loading time is just too big to wait.

Here are the tests I made using Chrome web browser (the data is from it’s Network tab using ):

datatables plugin turned on:
5476 records:
24 requests ❘ 256.26KB transferred ❘ 19.80s
(onload: 19.80s, DOMContentLoaded: 18.58s)

45071 records:
34 requests ❘ 1.85MB transferred ❘ 11.1min
(onload: 11.1min, DOMContentLoaded: 11.0min)

datatables plugin turned off (the jQuery datatables initialization is comented out):
5476 records:
21 requests ❘ 255.84KB transferred ❘ 6.57s
(onload: 13.26s, DOMContentLoaded: 13.28s)

45071 records:
31 requests ❘ 1.84MB transferred ❘ 2.0min
(onload: 2.0min, DOMContentLoaded: 2.0min)

The increase in load time that datatables make is over 80% for the 45k rows, and almost 40% for the 5k rows.

So I was wondering if you guys know of any similar plugin that handles alot of rows (45000+) faster, or am I just missing the point by trying to load all 45000+ records in “one go”?

Any suggestions are appreciated!

The answer, by user Allan Jardine, was this:

From the DataTables FAQs ( http://datatables.net/faqs#speed ):

  • Client-side processing – DOM sourced data: ~5’000 rows. Speed options: bSortClasses
  • Client-side processing – Ajax sourced data: ~50’000 rows. Speed options: bDeferRender
  • Server-side processing: millions of rows.

If you aren’t using deferred rendering at the moment, with your 45’000 rows, I would most certainly suggest that. Failing that, for DataTables options, you might need to look at server-side processing.

Miscellaneou$

ALS Ice bucket challenge

[vcfb id=10203881466450662]

Fala Philip Taylor na nominaciji. Ja nominiram Miljenko Bistrovic, Luka Mesarić i Denis Jelenčić.
Ko nezna za kaj se ide, nek pročita: http://www.vecernji.hr/hrvatska/i-u-hrvatskoj-pocelo-skupljanje-novca-za-oboljele-od-als-a-957366 (tu imate i broj žiro računa). Inače, slažem se i s Seth Godin koji ima ovo za reći po tom pitanju: http://sethgodin.typepad.com/seths_blog/2014/08/slacktivism.html; ali ako drugo niš, podigla se barem svijest o tome… There, my $.2, well actually 100, but who cares as long as it’s for a good cause, right? – I won’t miss it and it just might help someone…

Stack Overflow

Wait for images to load and then execute all other code

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

So, my question was as follows:

What I want to do is: wait until all images are preloaded and only then execute all other javascript code. As far as I’m concerned it can (but not a must) have a “loading…” message.

The fact is that I have a pretty big image in the body background and 2 other images which are also bigger, and so I would like to preload them so that then they would show instantly and would not have that ugly “loading” image effect.

This is what I’m using now but it’s not good:

$(document).ready(function()
{    
     preloadImages();
     ...some other code...

    function preloadImages(){
         imagePreloader([
            'images/1.png',
            'images/2.jpg',
            'images/3.png',                
         ]);
     } 

     function imagePreloader(arrayOfImages) {
         $(arrayOfImages).each(function(){
             (new Image()).src = this;
         });
     }   
}

I don’t know, maybe I should call this preloader somewhere out of the .ready()? or something like that? Btw, yes, I also read this post and I don’t know why but .ready() works faster for me.

The answer, by user Kevin Ennis, was this:

Instead of trying to preload, you could just execute your script on…

window.onload =function(){..}

That doesn’t fire until all images have been loaded.

My own solution was this:

Ok, so finally I got this thing to work. My problem? I was setting the waiting div wrong. This is my code now: I have the loading div which I show above everything and then when all images load (using $(window).load(function(){…}); as suggested I, hide that div.

<divid="loading"><divid="waiting"><imgclass="loadingGif"src="images/loading.gif"></div></div>

#loading
{
   background-size: 100%;
   background-color:#000;
   width: 100%;
   height: 100%;
   margin: 0px;
   padding: 0px;
   z-index:999;
}  

#waiting
{
   margin-left: auto;
   margin-right: auto;    
   position:absolute;
   top: 39%;
   left: 27.81%;
   width: 45%;
   height: 150px;    
   background-color: #FFF;
   border: 12px solid #FF771C;
   text-align: center;
}

And my jQuery code is this:

$(window).load(function(){    
    $('#loading').addClass('hidden');...}

Additionally, user Alex had a great answer too:

I  have a plugin named waitForImages that lets you attach a callback when descendent images have loaded.

In your case, if you wanted to wait for all assets to download, $(window).load() may be fine. But you could do it a bit cooler with my plugin 🙂

var loading = $('#loading');

$('body').waitForImages(function(){    
    loading.addClass('hidden');},function(loaded, total){
    loading.html(loaded +' of '+ total);});
Books

Think and grow rich – Napoleon Hill

My favourite quotes from the book Think and grow rich by Napoleon Hill:

All earned riches have a beginning and an idea.

We refuse to believe that which we do not understand.

We are the masters of our faith, the captains of our souls, because we have the power to control our thoughts.

Our brains become magnetized with the dominating thoughts that we hold in our minds, and these magnets attract to us the forces, the people, the circumstances of life which harmonize with the nature of our dominating thoughts.

Desire – the first step towards riches.

He did not say “I will try, he knew he would make it”.

Fix an exact amount you want in your head. Determine how much will you give back. Establish a definite date. Create a definite plan for carrying out your desire and begin at once. Write this all down. Read this statement twice a day. See yourself in possession of the money.

The object is to want money and to become so determined to have it that you convince yourself that you will have it.

No one ever is defeated until defeat is accepted as reality.

No one is ready for a thing until he believes that he can acquire it.

Our only limitations are those that we set up in our own minds.

Desire backed by faith knows no limit.

If you think poorly about yourself, your subconscious mind will take this and translate into physical equivalent.

Fate is a premise for everything.

Any idea, plan or purpose may be placed into mind by repetition of thought. That’s why you have to read/write your definite chief aim.

You come to believe what you constantly repeat to yourself.

If you think you’re beaten, you are. If you think you dare not, you don’t. If you like to win, but you think you can’t it’s almost certain you won’t. If you think you will lose, you lost. It’s all in the state of mind. You have to be sure of yourself before you ever win a prize. The man who wins is the man who thinks he can.

Any man is educated who knows where to get knowledge when he needs it, and to organize that knowledge into plans of action.

Anything acquired without effort and without cost is generally unappreciated, often discredited.

The person who stops studying merely because he finished school is forever hopelessly doomed to mediocrity.

There is no fixed price in an excellent idea.

The idea is the main thing. Specialized knowledge can be found just around the corner.

The only limitation is that which one sets up in one’s own mind.

No man is ever wiped, until he quits – in his own mind.

A quitter never wins, and the winner never quits.

The greatest among you shall be servant of all.

The world does not pay a man for that which they know, but for what they do, or induce others to do.

Every company has room for a man who has a definite plan of action which is to the advantage of that company.

Money without brains is always dangerous.

Riches do not come without effort.

With persistence will come success.

1. Definite purpose backed by a burning desire for its fulfillment.

2. A different plan expressed in continuous action.

3. Mind closed tightly against all negative and discouraging influences, including negative suggestions of relatives, friends and acquaintances.

4. A friendly alliance with one or more persons who will encourage one to follow through with the plan and purpose.

The sex energy must be transmuted from desire for physical contact into some other desire or action.

Faith and fear make poor bedfellows.

Pray for a thing and believe you will receive it.

Stack Overflow

Is there a PHP function to evaluate string like “2-1” as arithmetic 2-1=1

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

So, my question was if there is a PHP function which would take the string like “2-1” and produce the arithmetic result of it (1)? Or will I have to do this manually with explode() to get the values left and right of the arithmetic operator?

The answer, by user Jon, was quite elaborating:

I know this question is old, but I came across it last night while searching for something that wasn’t quite related, and every single answer here is bad. Not just bad, very bad. The examples I give here will be from a class that I created back in 2005 and spent the past few hours updating for PHP5 because of this question. Other systems do exist, and were around before this question was posted, so it baffles me why every answer here tells you to use eval, when the caution from PHP is:

The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

Before I jump in to the example, the places to get the class I will be using is on either PHPClasses orGitHub. Both the eos.class.php and stack.class.php are required, but can be combined in to the same file.

The reason for using a class like this is that it includes and infix to postfix(RPN) parser, and then an RPN Solver. With these, you never have to use the eval function and open your system up to vulnerabilities. Once you have the classes, the following code is all that is needed to solve a simple (to more complex) equation such as your 2-1 example.

require_once "eos.class.php";
$equation ="2-1";
$eq =new eqEOS();
$result = $eq->solveIF($equation);

That’s it! You can use a parser like this for most equations, however complicated and nested without ever having to resort to the ‘evil eval‘.

Because I really don’t want this only only to have my class in it, here are some other options. I am just familiar with my own since I’ve been using it for 8 years. ^^

Wolfram|Alpha API
Sage
A fairly bad parser
phpdicecalc

Not quite sure what happened to others that I had found previously – came across another one on GitHub before as well, unfortunately I didn’t bookmark it, but it was related to large float operations that included a parser as well.

Anyways, I wanted to make sure an answer to solving equations in PHP on here wasn’t pointing all future searchers to eval as this was at the top of a google search.

Books

The greatest salesman in the world – Og Mandino

My favourite quotes from the book The greatest salesman in the world by Og Mandino:

It is indeed a simple task, provided one is willing to pay the price in time and concentration until each principal becomes a part of one’s personality.

Do not aspire for wealth and labor not only to be rich. Strive instead for happiness to be loved and to love and more importantly to acquire peace of mind and serenity.

I consider poverty to be lack of ability, or lack of ambition.

Rewards are great if one succeeds. But the rewards are great only because so few succeed.

Never feel shame for trying and failing, for he who has never failed is he who has never tried.

Failure will never overtake me if my determination to succeed is strong enough.

Although I consider myself a good salesman I cannot sell death on departing from my door.

You’re an old man nods wisely and speaks stupidly.

For what is success than the state of mind.

Failure is man’s inability to reach his goals in life, whatever they may be.

I could bestow upon you great wealth but this would do you great disservice, far better is if you become the world’s greatest salesman on your own.

The only difference between those who have failed and those who have succeeded lies in the difference of their habits. Good habits are the key to all success. Bad habits are the unlocked doors to failure.

Only a habit can subdue another habit.

As I repeat the words daily it will soon become the part of my active mind, but more importantly it will also slip into my other mind. That mysterious source that never sleeps, which creates my dreams, and often makes me act ways I do not comprehend.

I will not hear those who weep and complain for their disease is contagious. Let them join the sheep. The slaughterhouse of failure is not my destiny. I will persist until I succeed.

The prizes of life are at the end of each journey, not at the beginning. And it is not given to me to know how many steps are necessary in order to reach my goal. Failure I may still encounter at 1000th step, yet success hides behind the next bend in the road. Never will I know how close it hides unless I turn the corner. Always will I take another step. If that is of no avail, I will take another and yet another. I will persist until I succeed.

There is no room in the marketplace for my family. Nor is there a place for market at my home.

If I persist long enough I will win.

Never has there been a map however carefully executed to detail and scale which carried its owner over even 1 inch ground, never has there been a parchment of law that prevented one crime. Never has there been a scroll that produced a penny. Action is the food and drink that will nourish my success. I will act now.

I will pray, but my cries for help will only be cries for guidance. Never will I pray for material things of the world. Only for guidance will I pray.

Oh creator of all things help me, for this day I go out to the world naked and alone, and without your hand to guide me. I will wonder far from the path which leads to success and happiness, I ask not for gold or even opportunities equal to my ability. Instead guide me that I may acquire ability equal to my opportunity. You have taught the lion and the eagle how to hunt and prosper with the teeth and claw. Teach me how to hunt with words and prosper with love so that I may be a lion among men and the eagle at the marketplace. Help me to remain humble through obstacles and failures. Confront me with fears that will temper my spirit, yet indulge me with courage to laugh at my misgivings. Spare me some sufficient days to reach my goals, yet help me to live this day, as that would be my last. Guide me in my words that they may be a fruit, yet silence me from gossip that none be malign. Discipline me in the habit of trying and trying again, yet show me the way to use the law of the averages. Favor me with alertness to favor the opportunity, yet enable me with patients which will concentrate my strength. Bade me in good habits that the bad ones may drown, grant me compassion for weaknesses in others. Let me know that all things shall pass, yet help me to count the blessings of today. Expose me to hate, yet not be a stranger, yet fill my cup with love to turn strangers into friends. But all these things be of thy will. I’m small and lonely grape clutched divine yet that has made me different from all of us. Fairly, there must be a special place for me, guide me, help me, show me the way. Let me become all that you planned for me when my seed was planted and selected by you to sprout in the vineyard of the world. Helpe this humble salesman, guide me God!

Quick tips

How to compare today’s date with the one you have in the MySQL timestamp field

Say you have a field called date in your MySQL table and its type is timestamp (example: ‘2014-08-23 08:37:57’), and you want to get all the records for today (so, all the records who’s dates are ‘2014-08-23’ neverminding the time). Here’s how yo do that:

SELECT * FROM `the_table` WHERE date(date) = curdate();

So, we’re using date() and curdate() functions here to help us achieve that.

Page 46 of 51« First...102030«45464748»50...Last »

Recent posts

  • When espanso Breaks on Long Replacement Strings (and How to Fix It)
  • 2024 Top Author on dev.to
  • Hara hachi bun me
  • Discipline is also a talent
  • Play for the fun of it

Categories

  • Android (3)
  • Books (114)
    • Programming (22)
  • CodeProject (36)
  • Daily Thoughts (78)
  • Go (3)
  • iOS (5)
  • JavaScript (128)
    • Angular (4)
    • Angular 2 (3)
    • Ionic (61)
    • Ionic2 (2)
    • Ionic3 (8)
    • MEAN (3)
    • NodeJS (27)
    • Phaser (1)
    • React (1)
    • Three.js (1)
    • Vue.js (3)
  • Leadership (1)
  • Meetups (8)
  • Miscellaneou$ (78)
    • Breaking News (8)
    • CodeSchool (2)
    • Hacker Games (3)
    • Pluralsight (7)
    • Projects (2)
    • Sublime Text (2)
  • PHP (6)
  • Quick tips (41)
  • Servers (8)
    • Heroku (1)
    • Linux (3)
  • Stack Overflow (81)
  • Unity3D (9)
  • Windows (8)
    • C# (2)
    • WPF (3)
  • Wordpress (2)

"There's no short-term solution for a long-term result." ~ Greg Plitt

"Everything around you that you call life was made up by people that were no smarter than you." ~ S. Jobs

"Hard work beats talent when talent doesn't work hard." ~ Tim Notke

© since 2016 - Nikola Brežnjak