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
Ionic, Stack Overflow

ionic plugin add phonegap-plugin-push results in a 404 Not Found Error

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 be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.

I actually asked this question myself:

I was following the official (and rather great) docs over at Ionic for how to get started with push notifications.

However, once the instructions said to install the phonegap-plugin-push plugin, I received the following error:

nikola@Nikolas-Mini ~/Desktop/ionicTesting/ionicPush
> ionic plugin add phonegap-plugin-push
Error: 404 Not Found: phonegap-plugin-push
at RegClient.<anonymous> (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:304:14)
at Request._callback (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:246:65)
at Request.self.callback (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/request/request.js:236:22)
at Request.emit (events.js:110:17)
at Request.<anonymous> (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/request/request.js:1142:14)
at Request.emit (events.js:129:20)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/request/request.js:1096:12)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)

Anyone has an idea of why? I tried with cordova instead ionic but I get the same error.

Also, I managed to find the answer myself:

After quite some searching I stumbled upon an official blog post, Cordova is moving their plugins to npm.

So, finally, I installed it easily now with npm:

npm install phonegap-plugin-push

https://twitter.com/HitmanHR/status/671596248764428289

Books

The art of being unmistakable – Srinivas Rao

My notes from (currently) free book The Art of Being Unmistakable: A Collection of Essays About Making a Dent in The Universe by Srinivas Rao, which I rated  4/5 on my Shelfari account.

What if you decided to be the one who creates for the joy of creating, nothing more?!

To experience something new, we have to let go of what’s old. We have to remain calm in the face of setbacks.

My greatest sin was to waste my life believing that I wasn’t capable of something more.

How long are you willing to act like a pro without any of the external rewards that come with it?

If you try to miomic, copy er emulate anybody else, at best you will be a pale imitation.

The only way to really stand out online is to be honest.

None of these things define you as a person: Your education The size of your bank account Your job title Your failures Your successes And sadly, we let so many of these things rule our lives. Obsession with crossing off the checkboxes of society’s life plan leads to little other than therapy, midlife crises, and depression.

Worrying about what other people think is a jail of our own creation, and the irony of it is those people are in the same jail with us.

The “No bullshit” version of who you are can work with a compass. Your ego needs a map because it does not quite understand the wise words of Paul Jarvis, “Nobody is successful because they took somebody else’s roadmap and copied it.

To become truly unmistakable I have to be willing to ditch the map, travel without a guidebook, and see where it leads me.

https://twitter.com/HitmanHR/status/671227308649353216

Ionic, Stack Overflow

Firebase $authWithOAuthRedirect doesn’t call $onAuth without page refresh

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 be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.

I actually asked this question myself:

I have a simple Firebase Facebook OAuth login set like below by following the official tutorial for the Ionic Firebase Facebook login.

The problem is that once I click on the login with Facebook button, I get redirected to Facebook, I log in, and I get redirected back to my app. However, the problem is that I stay in the login page. Strange thing is that if I physically refresh my browser (testing with ionic serve) by pressing F5 the onAuth triggers and I get redirected to the Items page. If I don’t refresh the browser, onAuthdoesn’t get called.

Did someone have this issue? How did you solve it?

Please note that yes, I did my research (and am slightly starting to lose it), but can’t get it to work. I searched SO, tried with $timeout from google groups, tried to call $scope.$apply(), but all to no avail – so please help me figure out where I’m doing it wrong?

.controller('AppCtrl', function($scope, Items, Auth, $state, $ionicHistory) {
    $scope.login = function(provider) {
        Auth.$authWithOAuthRedirect(provider).then(function(authData) {

        }).catch(function(error) {
            if (error.code === "TRANSPORT_UNAVAILABLE") {
                Auth.$authWithOAuthPopup(provider).then(function(authData) {
                    
                });
            } else {
                console.log(error);
            }
        });
    };

    $scope.logout = function() {
        Auth.$unauth();
        $scope.authData = null;

        $window.location.reload(true);
    };

    Auth.$onAuth(function(authData) {
        if (authData === null) {
            console.log("Not logged in yet");
            $state.go('app.login');
        } else {
            console.log("Logged in as", authData.uid);
            
            $ionicHistory.nextViewOptions({
                disableBack: true
              });
            $state.go('app.items');
        }
        $scope.authData = authData; // This will display the user's name in our view
    });
})
<ion-view view-title="Members area">
    <ion-content padding="true">
        <div ng-if="!authData">
            <button class="button button-positive button-block" ng-click="login('facebook')">Log In with Facebook</button>  
        </div>       
        
        <div ng-if="authData.facebook">
            <div class="card">
                <div class="item item-text-wrap">Hello {{authData.facebook.displayName}}!</div>                
            </div>

            <button class="button button-assertive button-block" ng-click="logout()">Log out</button>
        </div>        

    </ion-content>
</ion-view>

edit: I sort of solved it by using $timeout:

$timeout(function(){
    Auth.$onAuth(function(authData) {
        if (authData === null) {
            console.log("Not logged in yet");
            $state.go('app.login');
        } else {
            console.log("Logged in as", authData.uid);

            $ionicHistory.nextViewOptions({
                disableBack: true
              });
            $state.go('app.items');
        }
        $scope.authData = authData; // This will display the user's name in our view
    });
}, 3000);

However, this just feels wrong (mildly put), and there has to be a better way, so please suggest one. Also, I noticed that the whopping 3second delay is barely enough (few of the resources I found suggested 500ms would be enough, but in my case, that’s not the case).

Answer, from user mhartington, was:

Posted on the github issues, but will reply here as well.

This only happens in the browser using $authWithOAuthRedirect. The example was intended for cordova apps, so this really shouldn’t be an issue.

But if you really need it, you could just skip the redirect and use a popup.

Auth.$authWithOAuthPopup(authMethod).then(function(authData) {
      console.dir(authData);
    });

https://twitter.com/HitmanHR/status/671222279121076224

Books

Free ebook: The Universe doesn’t give a flying fuck about you – Johnny Truant

My notes from (currently) free book The Universe Doesn’t Give a Flying Fuck About You (Epic series Book 1) by Johnny Truant, which I rated  4/5 on my Shelfari account. Actually, the whole series (4 books) is free currently, so you may wanna rush your download 😉

If you knew how small you are and how short a time you have to do what you can, you wouldn’t waste time watching five fucking hours of TV a day.

Stop being a pussy and go do something amazing!

It doesn’t matter what you’ve done. What matters is what you do.

It means that even though the universe doesn’t care enough to give you what you want, it doesn’t care enough to stop you from having it, either. So embrace that anarchy, and take those things for yourself.

Just do it. Claim it. Stop waiting for permission.

Fucking hell. Stop whining and just be it already. Be fucking awesome.

Your life is a one-way train, and any second you waste is a second lost forever.

There’s a drinking game in Heaven, where angels do a shot every time humans invest ‘for the long term.

I heard that God watches jewelry commercials and LOL’s when they say that diamonds are forever.

https://twitter.com/HitmanHR/status/671216342465437696

Ionic, Stack Overflow

Use navigator.geolocation or $cordovaGeolocation in Ionic

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 be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.

I actually asked this question myself:

Since I basically can get the same info with both approaches, I’m wondering which is the preferred one and what are the advantages using one over the other?

Answer, from user Mudasser Ajaz, was:

$cordovaGeolocation is angular wrapper over plain javascript plugin, developed by ionic. Now question is why ngCordova was introduced,in simple words to deal it as plugin service as module and inject plugin wrapper as dependency to only particular controller or service.
On Pratical level, cordova developers were having issues with plugins on angular project. One simple issue was that $scope does not get updated sometimes in simple plugins callback.
Quoting from ionic blog post :

The services support promises to make it easier to deal with their asynchronous nature and ensure scope data is properly updated

https://twitter.com/HitmanHR/status/671057737669832705

Books

The 5 Elements of Effective Thinking – E. Burger and M. Starbird

My notes from the bestseller book The 5 Elements of Effective Thinking by the authors Edward B. Burger and Michael Starbird, which I rated  5/5 and marked as favorite on my Shelfari account:

Earth – understand deeply

Fire – make mistakes

Air – raise questions

Water – follow the flow of ideas

Change – universal constant that allows you to get the most out of living and learning

Education is what survives when what has been learned has been forgotten. ~ B. F. Skinner

In everything you do, refine your skills and knowledge about fundamental knowledge and simple cases. Once is never enough. As you revisit fundamentals you’ll find new insights.

The depth with which you master the basics influences how well you understand everything you learn after that.

As you learn more, the fundamentals become at once simpler but also subtler, deeper, more nuanced, and more meaningful.

One of the challenges of life is to be open-minded about new ideas and new possibilities.

Sadly, many people spend their entire lives focusing on the wrong questions. They may pursue money, when they really want happiness. They may pursue the respect of people whose favor is really not worthy of being sought. So before you succumb to the temptation to immediately spring to work on the answer, always stop and first ask, “What’s the real question here?” Often the question that seems obvious may not be the question that leads to effective action.

Fail nine times! The next time you face a daunting challenge, think to yourself, “In order for me to resolve this issue, I will have to fail nine times, but on the tenth attempt, I will be successful.” This attitude frees you and allows you to think creatively without fear of failure, because you understand that learning from failure is a forward step toward success. Take a risk and when you fail, no longer think, “Oh, no, what a frustrating waste of time and effort,” but instead extract a new insight from that misstep and correctly think, “Great: one down, nine to go—I’m making forward progress!” And indeed you are. After your first failure, think, “Terrific, I’m 10% done!” Mistakes, loss, and failure are all flashing lights clearly pointing the way to deeper understanding and creative solutions.

Success is the ability to go from one failure to another with no loss of enthusiasm. ~ Winston Churchill

https://twitter.com/HitmanHR/status/670239687009771520

Stack Overflow

How to get nested object property with pluck in Lodash

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 be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

This Lodash question was actually asked by myself:

I have an array of objects like this:

var characters = [
    { 'name': 'barney',  'age': 36, 'salary':{'amount': 10} },
    { 'name': 'fred',    'age': 40, 'salary':{'amount': 20} },
    { 'name': 'pebbles', 'age': 1,  'salary':{'amount': 30} }
];

I want to get the salary amounts into an array. I managed to do it by chaining two pluck functions, like this:

var salaries = _(characters)
  .pluck('salary')
  .pluck('amount')
  .value();

console.log(salaries); //[10, 20, 30]

Is there a way to do this by using only one pluck? Is there a better way with some other function in lodash?

The answer, from user thefourtheye, was:

You can just give the path to be used as a string, like this

console.log(_(characters).pluck('salary.amount').value())
// [ 10, 20, 30 ]

Or use it directly

console.log(_.pluck(characters, 'salary.amount'));
// [ 10, 20, 30 ]

https://twitter.com/HitmanHR/status/670237244695977984

Books

Surely You’re Joking, Mr. Feynman! – Richard P. Feynman

My notes from the bestseller book Surely You’re Joking, Mr. Feynman! (Adventures of a Curious Character) by the author Richard P. Feynman himself (winner of the Nobel Prize in physics), which I rated  4/5 on my Shelfari account:

All the time you’re saying to yourself, ‘I could do that, but I won’t,’ — which is just another way of saying that you can’t.

I couldn’t claim that I was smarter than sixty-five other guys–but the average of sixty-five other guys, certainly!

I learned from her that every woman is worried
about her looks, no matter how beautiful she is.

There were lot of fools at the conference – pompous fools – and pompous fools drive me up the wall. Ordinary fools are alright; you can talk to them and try to help them out. But pompous fools – guys who are fools and covering it all over and impressing people as to how wonderful they are with all this hocus pocus – THAT, I CANNOT STAND! An ordinary fool isn’t a faker; an honest fool is alright. But a dishonest fool is terrible!

I always do that, get into something and see how far I can go.

When I tried to show him how an electromagnet works by making a little coil of wire and hanging a nail on a piece of string, I put the voltage on, the nail swung into the coil, and Jerry said, “Ooh! It’s just like fucking!

I wouldn’t stop until I figured the damn thing out–it would take me fifteen or twenty minutes. But during the day, other guys would come to me with the same problem, and I’d do it for them in a flash. So for one guy, to do it took me twenty minutes, while there were five guys who thought I was a super-genius.

The whole problem of discovering what was the matter, and figuring out what you have to do to fix it–that was interesting to me, like a puzzle.

https://twitter.com/HitmanHR/status/670015841719721984

Ionic, Stack Overflow

How to design a two column button in Ionic framework

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 be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.

I actually asked this question myself:

What I would like to achieve is this:

enter image description here

Surely, I went through the button documentation, but it seems nothing similar is there. So, I would appreciate some pointing in the right direction (codepen with a basic example would be most awesome).

So, ideally, this would be one button tag where I would be able to pass two variables (one which would appear on the left and one on the right). This does smell like a job for a Angular directive, though I haven’t fiddled with it too much just yet so a friendly nudge in the right direction would be appreciated.

Answer from Malek Hijazi was pointing out to use the ButtonBar component, but I already knew about it and it wasn’t what I needed. Finally, I managed to answer this question myself after some fiddling with it:

What I ended up doing in the end was this: I created a div with a class button and then inside it I created additional two div‘s with custom classes.

How this looks like on CodePen:

And, the code below:

.leftButtonSide {
    width: 50%;
    float: left;
    color: #000;
}

.rightButtonSide {
    width: 50%;
    float: left;
    background: #F2F2F2;
    color: #000;
    border-radius: 2px;
}
<div ng-repeat="d in data" class="button button-positive-outline">
    <div class="leftButtonSide">2</div>
    <div class="rightButtonSide">2,00</div>
</div>

True, for the exact same look you would have to play a bit with CSS. I ended up with this in the end:

Hope this helps someone too!

https://twitter.com/HitmanHR/status/669836667893768192

PHP, Quick tips

M is not for minutes in PHP date function

Ah, it was one of those days when you’re too smart for your own good and you don’t check the docs and falsely assume that m must definitely be minutes in the date function in PHP.

It should be

$dateNow = date("Y-m-d H:i:s");

and not H:m:i!

The offcial docs are clear, one just needs to read them 🙂

Page 28 of 51« First...1020«27282930»4050...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