Author: Catzie

  • Laravel 5 RESTful API with Basic Auth: PHPUnit Testing

    I’ve been using PHPUnit to test my RESTful API. PHPUnit is ready to use in Laravel.

    In my Laravel-based RESTful API, I have an endpoint /api/users which returns JSON data when you send a GET request. The API will only return such data if the client sends the corrent username and password (Basic Authentication). The JSON data looks like this:

    I’m gonna show you how to create a PHPUnit test for this kind of JSON API data in Laravel 5.

    To create a test case, use this command:

    This will create a new test case named ApiUsersTest.php in your directory /tests

    Paste the following code in it.

    Edit the test case as needed.

  • Android M runtime permissions utility class


    Hello world, I prepared a PermissionsUtil.java class and it’s on GitHub.

    Check it out: AndroidPermissionsUtil

    Why use it? It will help by letting you write less code as you add conditions to your Android app that supports Android 6.0 (Marshmallow). The utility class defines helper methods that were used in the following example.

    Sample usage of Android M PermissionUtils

    On the activity where you need to check for runtime permissions, add these:

    And add the callback function to the same activity:

    Feel free to use in on any project. And please let me know if you have suggestions on how to improve that Android M runtime permissions utility class.

  • Rama Beach Resort – photos & review (Botolan, Zambales)

    Rama Beach Resort – photos & review (Botolan, Zambales)


    This was an old draft that took long to get published. 😆

    The Travel

    My bottom hurt from the long bus ride.

    At Monumento, we took a bus bound for Iba, Zambales. The travel was over 5 hours, if I remember correctly. We had stopped over places several times, for not a short period of time. 🙁

    Also if I remember correctly (Hehe, my bad for not posting this sooner), the fare was about 300 pesos per person.

    20160226_121421_Pano

    The Restaurant


    On our first evening we were told we can go to the restaurant for dinner until 9:30PM, so being tired from the 4-hour bus ride from Manila, we took a nap until 8PM only to find that the restaurant had already closed! We talked to a staff at the reception area, and they said that the restaurant closed because they THOUGHT we were already asleep. I think it’s not good to close the restaurant earlier than the stated closing time because of the “assumption” that all guests were already asleep. The good thing was that they still accommodated us — they fetched the chef from home back into the resort’s restaurant just to cook for us, so thanks!

    We LOVED the Buko Pandan Shake. It was so creamy and has a distinct coconut taste. We tried mango and ube shake too and they were good too, but buko pandan is still their best, in our opinion. Their shakes are all smooth and unlike regular shakes, don’t have small crushed bits of ice that kind of get in the way when I sip from the glass. The Italian pizza was also nice.

    The Beach


    We came to Rama Beach Resort on a weekday – Thursday. We had the beach almost to ourselves and it was really clean. I didn’t like many “plants” floating because they kind of got in the way, but I put up with it. It’s part of nature anyway.

    There were too many waves to just relax in the beach water. But we got used to it and had fun, going against the waves. 😆 The waves kept pushing us back to the shore, and it was as if nature didn’t want us to go farther into the sea. 🙁

    The sand surface beneath the water was uneven, probably caused by the waves. But it didn’t feel unsafe.

    The shore only became rocky on our 3rd or 4th day. Only a bit painful to step on.

    Lucky us we did not see or brush against any jelly fish. There were also only a few crabs on the beach. They can be a pain (literally) sometimes when scurrying around in great number. 😆

    The Room

    The Deluxe room we had was for four people. If you are only two people, you have a big room for four. But if you come as a group of four, you use the same room but have to pay for the two extra people you’re with. So I guess this Deluxe room is more sulit if you’re only two persons.

    It’s clean and spacious. It has a nice view of the backyard where one could see part of the beach. And cute dogs walking around. :3

    There were two cute little monkeys too. It was fun watching them.

    Hmm.. if I remember correctly, there were a few mosquitoes flying around the room. But I don’t remember being bitten a lot.

    And oh, I like leaving the window in the bathroom for ventilation since there was no exhaust fan. Bathrooms need ventilation. It was situated in a high place, but I noticed someone passing by that window! 🙁 Good thing I was not naked during a bath back then. But that was a privacy issue in the room. 🙁 See one of the pics below for how the bathroom window looks. It’s covered with green mini curtain.

    The Pool

    The pool felt more cozy than the regular rectangular swimming pool with blue/white sides and bottom. This one had

    20160226_162123

    Do I recommend Rama Beach Resort?

    Yep! If you’re like me who likes peace and quiet, you might enjoy it more on a weekday. I guess this applies to any beach resort. Hehe.

    Rama Beach Resort rates/prices are also good.

    And oh, what a lovely view:

    20160227_124253_HDR

    On Saturday and Sunday, more people began to arrive. We no longer had the pool (it was a bit small but it’s clean and a cozy one) to ourselves but that’s okay. We were worried that we might not get a good night’s sleep because of noisy guests at night, but thank goodness, they weren’t noisy at night. 🙂 There’s a note in the room doors in small text saying that loud music is not allowed after 10PM and that noises should be minimized at night. Thank you, Rama Beach Resort management!

    And please do choose Deluxe room over Economy if you can. I think economy rooms don’t have aircon and are placed in a less quiet area. Check with Rama beach resort to confirm. 🙂

  • Rockpoint Hotspring Resort Hotel – rates & review

    Rockpoint Hotspring Resort Hotel – rates & review

    This was an old draft that took long to get published. 😆

    Our stay at Rockpoint Hotel wasn’t bad. It wasn’t one of the best hotels we stayed at, but it had most of what we needed.

    This resort is in Laguna.

    Holiday Rates (2015) at Rockpoint Hotspring Resort Hotel

    These were the rates when we went there last year during holidays:
    Rates December 2015 (Rockpoint Hotspring Resort Hotel review)

    Here’s what the entrance looks like:

    Nice view here:

    nice view at rockpoint hotspring hotel

    And the reception area was oh-so-cozy.

    20151226_133527_HDR

    Deluxe Room at Rockpoint Hotspring Resort Hotel

    We booked a Deluxe Room for 1 night, and depending on availability, you can choose between twin beds or a queen bed.

    hot tub (Rockpoint Hotspring Resort Hotel review)

    The bathroom had a big hot tub that could fit two or three people. It can take about an hour to fill it with water though. The shower is in the tub area also, so when you just want to shower, you need to step into the bath tub which is inconvenient to me especially when I’m very tired and the floor is slippery. There were to sachets of shampoo with conditioner, two small bars of soap, and two toothbrush and toothpaste set. The tube of toothpaste was tiny and difficult to open. XD

    bed (Rockpoint Hotspring Resort Hotel review)

    The pillows of their beds were soft and fluffy. We found extra pillows in the cabinet under the TV but they didnt have pillowcase.

    Other photos of what’s included in the room:

    The light bulbs in the bedroom and bathroom were yellow, except for the one at the table which had a white light. I personally prefer white lights because I don’t feel so well in rooms that are not bright enough. That table with white light had a huge mirror too, perfect for women who do hair makeup.

    Rockpoint Hotel doesn’t have hair dryer and that is another inconvenience. Not a major inconvenience because there was electric fan in the room.

    They charge corkage fee for cooked foods bought anywhere aside from their Lava Restaurant. They charged 10% for the pizza we ordered. Pizza Hut’s charge was 499 and we paid the hotel 50 pesos. It’s not that big, I guess.

    Pools at Rockpoint Hotspring Resort Hotel

    pool by the entrance (Rockpoint Hotspring Resort Hotel review)

    pool (Rockpoint Hotspring Resort Hotel review)

    Based on what I read on Rockpoint Hotel’s site, I expected 2 pools. First pool is in front of the Deluxe rooms with warm water temperature, whose schedule is 9AM-9PM, and a second pool in front of Lava Restaurant which was said to have HOT water like you’re in a hot spring, but nope! Its pool water had the same warmth as that of the first pool.

    pool in front of lava restaurant (Rockpoint Hotspring Resort Hotel review)

    That pool in front of Lava Restaurant opens at 7AM according to a poster, which doesn’t state up to what time we could use it.

    When we checked in around 2pm, there was no one but us using the pool in front of the Deluxe rooms. Everyone else was in the other pool, until about 3pm. And at night around 10pm, we enjoyed swimming in the second pool near Lava Restaurant because not a single guest was swimming there until we came there. We can say that “nasolo at nasulit namin yung pools”, but I think we were just lucky!

    Peace and quiet at Rockpoint Hotspring Resort Hotel

    avoid noise at night (Rockpoint Hotspring Resort Hotel review)

    I like how Rockpoint Hotel actually cares about preventing noises from disturbing guests in their rooms. They have this sign that says we shouldn’t make noises so that guests can rest well in their rooms. The first pool, located in front of the Deluxe rooms, closes at 9pm, probably because Rockpoint hotel doesn’t want noise from the pool from disturbing guests at bed time. The second pool, which is in front of the restaurant anf has a nearby kiddie pool, seems to be usable even until midnight since there’s no guest room near it.

    And yes, we had a quiet rest at night. But not for the rest of the day because there were many kids outside our room making noise, laughing and shouting.

    Kalipayan Nature Spa at Rockpoint Hotspring Resort Hotel

    Kalipayan Nature Spa for massage (Rockpoint Hotspring Resort Hotel review)
    We wanted body massage for relaxation but the spa was closed. Maybe it’s by appointment only?

    Food in Lava Restaurant at Rockpoint Hotspring Resort Hotel

    So here’s a gallery of some of the foods that we ordered that the Lava Restaurant:

    We had free breakfast included. It wasn’t satisfying. Among the available items foe free breakfast, I chose malunggay 4 small pan de sal with cheese and eggs. It’s good enough but also something that anyone can quickly prepare at home. The coffee they serve is not even brewed coffee — only instant 3-in-1 coffee. My companion chose longganisa with rice and egg. It was okay. Since we felt unsatisfied, we ordered chicken tenders with fries. The fries served was a very scant amount compared to the picture in the menu, and the thin strips of chicken didn’t look so appetizing. The taste of the chicken breading was not bad though, but reminds me of an instant store-bought chicken breading we buy from grocery stores. The fries tasted like usual packed fries we buy from the grocery too. The dip for chicken and fries was very sour. Maybe there was too much vinegar? Meh, I guess I’ll never eat at Lava Restaurant again unless it’s free food included in our room booking.

    Conclusion of Rockpoint Hotspring Resort Hotel

    So, to conclude this Rockpoint Hotel review… We stayed there on December 26 and 27, and the other guests seemed to be families with many kids. It got so noisy at times, but I was glad they were quiet at night. The pool near Lava Restaurant was not hot enough as described, and I hope Rockpoint can adjust the temperature to make it consistent with what’s written in their website. The Deluxe room was clean and cozy, but it would become a perfect if they provide hair dryer, and a shower separate from the hot tub.

  • Android app codes for Google Maps with clustering

    I prepared Android app codes with Google Maps and clustering feature. Feel free to use these as basis for your new projects.

    They are on GitHub:

    Android map clustering with default markers

    [1] Default Map Markers:
    catzie/SimpleAndroidMapClustering

     

     

    I simply took the necessary classes and res files from Android Maps Utility demo, and then placed them into bare Android Studio projects for simplicity. For me, it’s easier to start a new “maps with clustering” project on simple apps like these, rather than downloading the entire Android Maps Utility Demo, picking out the necessary files, and fixing errors before getting started each time. 😆

     

  • Android Maps: Get current location coordinates with Google API Client Builder

    To get your current location via Google Map in an Android app, this was how we do it:

    Stop. Don’t use that! The method GoogleMap.getMyLocation() is deprecated. Instead, we need to use FusedLocationApi and the callback onLocationChanged().

    Here’s an example code that works for me ( consider copying the contents of onResume() into onStart() ):

    Code source: How to get current location of device on google maps api v2, getMyLocation() method is deprecated

  • Bash: rename all files in directory, replacing all hyphens (-) with underscores (_)

    I don’t want to waste time doing things manually when I can run a script that will help me save time and effort.

    When using Linux or Mac command line (bash?), if you want to rename all files in your present directory and replace all hyphens - with underscores _, run this command:

    And if you want to do the reverse, i.e., replace all underscores _ with hyphens -, run this command instead:

    To remove substring from file names, (e.g., remove @3x string), run this:

    I had to do this after importing image files with hyphens in their names into my Android project. I can’t use images with hyphens in their names.

  • This place will never be the same again

    When I first came to that place, that “existence” was there. It was at first an annoyance to me and made my blood boil quite a few times, even after moving to this new place. Occasionally this existence would speak of wise words such as “Be the better person.”

    Now, that existence is gone.

    But for a short while before it had left us, I felt that this once “only annoying” is one of the few who I could actually connect with. In this chaotic place, we need to laugh our negativity away to survive, and this existence and I found humour in the same simple things.

    We will surely miss how that loud contagious laughter would boom in the room.

    This place will never be the same again without you. All the best to you in the new place you chose.

  • Android Studio: add Google Map from empty activity (dev note)

    //Update: I prepared a simple Android app that features a Google Map with markers that form clusters together when zoomed out. Check it out: Simple Android Map Clustering on GitHub.

    This “dev note” of mine will give you a rough idea on how to add a Google Map to your Android up from an empty activity, not from a pre-made Google Maps activity.

    I won’t be able to write everything in detail here because I’m in a hurry, and so I’m calling this article a “dev note” instead of tutorial. 🙂 This dev note can be considered a “guide” too.

    This dev note was based on Android Studio v.2.1 running on MAC OS X

    From your Android Studio’s SDK Manager, install Google Play Services.

    Add this as child of <application> tag in AndroidManifest.xml:

    Later we’ll replace YOUR_API_KEY with a key from Google API Console.

    Also add these to your AndroidManifest.xml as direct child of manifest tag:

    We need to get an API KEY for the value attribute of this meta data. Let’s get one from the Google API Console — create a new project there and then search for Google Maps Android API. Enable it.

    After enabling it, you’ll find a way to get an API key that we need from Google API Console. Go to Credentials -> Create Credentials -> API Key -> Android Key. Before we are given the API key, we need to provide Google API Console a SHA1 certificate fingerprint from our computer and our app’s package name.

    To generate SHA1 certificate fingerprint on a Mac, type this on the terminal:

    On Windows, try this command:

    When prompted for a keystore password, enter the word debug as your password.

    Copy the SHA1 certificate fingerprint and then paste it into Google API Console. Enter your package name as well (e.g. com.yourdomain.projname). You’ll be given an API Key in return.

    Note: My Android Studio says ‘In the Google Developer Console (https://console.developers.google.com), ensure that the “Google Maps Android API v2” is enabled.’ but I can’t find the option for V2.

    Remember the meta-data tag we added in the AndroidManifest.xml? Replace the value with the API key that you just copied from Google API Console.

    Resource: https://developers.google.com/maps/documentation/android-api/signup

    Open app/build.gradle file and add the following as dependency:

    Sync your project with Gradle files.

    This was one of the tutorials I followed: GOOGLE MAPS ANDROID API V2 TUTORIAL USING ANDROID STUDIO and I based my XML plus Java codes on the author’s.

    My files in the end…

    Here were the codes of my Android app when I finally made the Google Map show up in the activity:

    app/build.gradle

    build.gradle

    app/src/main/res/layout/activity_main.xml

    app/src/main/java/net/catzie/maptest/MainActivity.java

    app/src/main/AndroidManifest.xml

    …even though the Google Map now shows up on my Android activity, I get these errors that I’m not able to fix yet:

  • Laravel update from v.5.0.35 to v.5.2.32 hiccups and solutions

    I tried to update Laravel 5 today and here were the steps I had to take.

    First checked my Laravel version before the update:

    Edited composer.json in my laravel’s root folder like such:

    Run this on command line:

    You might need to delete root folder’s composer.lock file before the update can actually begin.

    I got an error which I later fixed. Scroll to the bottom of the following message.

    So, Illuminate\Routing\ControllerServiceProvider’ could not be found.

    What I did was remove the following line from config/app.php:

    New error upon running php artisan –version:

    I created a folder named “cache” under bootstrap folder to solve that one.

    Tried to check my Laravel version again, but this was the new error:

    Solution was this:

    Then, finally!

    Oops, I can’t view my Laravel site on the web browser. It gives the following error:

    I opened App/Http/Controllers/Controller.php and replaced all instances of DispatchesCommands with DispatchesJobs.

    Next web browser error:

    So I replaced the content of my config/auth.php file with the following:

    Another error… Oh will this end soon?

    …which was caused by this code in my blade file:

    I simply passed a string “/” to the url() method to fix it. Then, ta-da! I could browse my Laravel site again via web browser.