Lunes, Disyembre 21, 2020

Angular 11 Custom Vertical Pagination on Scroll Tutorial

Working with Angular<ng> is fun but when displaying hundreds of feed items ala facebook the older mobile devices  can't handle it. Good thing there is a virtual scroller from the material CDK but it does not fit my needs. The experimental version is still buggy and jumpy at times.

Now I'll show you how to do virtual scrolling without using any third party library in Angular. It's a very simple solution and only involves a bit of coding.

Keep in mind the page items you want to display. For this exercise we need to display 20 feeds per page.

This line will determine if we loaded enough feeds so we can limit the number of feeds per next load and increment the <beginFeeds> variable accordingly.
if(this.pageLoad > this.beginFeeds + 40){
    this.beginFeeds += 20;
}
If the <pageLoad> is more than 40 items than the <beginFeeds>, it should increment 20 items for the <beginFeeds> variable.

We set the scroll event listener so when our button element's top is above the viewport it will call the feed loader.

ngOnInit(){
    window.addEventListener('scroll', eScroll, false);
}

This line will set the feeds hidden variable to true so we can check it on an *ngIf compare and hide our div

for(i=0; i < this.feeds.length; i++){
        
    this.feeds[i].hidden = true;

    if(i < this.beginFeeds){
        this.feeds[i].hidden = false;
    }
}


This line increments the <pageLoad> variable for the next data fetch.

this.pageLoad += 20;

If we keep loading data it will only show non-hidden items and free some precious resources.

What if the user scrolls to the beginning? Don't worry my friend. We got it handled.

loadLess = () => {
    
    if(this.beginFeeds - 20 < 0 ) return;

    let start = this.beginFeeds - 20;

    let end = this.beginFeeds + 40; 

    for(var i=0; i < this.feeds.length; i++){
        this.feeds[i].hidden = true; //hide all feeds
    }

    for(i=start; i < end; i++){
        
        this.feeds[i].hidden = false; //unhide feeds in range

    }

}

This line will check if our <beginFeeds> variable is greater than zero and get out if it is.

if(this.beginFeeds - 20 < 0 ) return;

Set our beginfeeds to decrement 20 items.

 let start = this.beginFeeds - 20;

Set the range to <beginFeeds> plus 40 items.

let end = this.beginFeeds + 40; 

Loop through the feeds and set feed items inside the range its hidden variable to false so it will show on the page. Then we'll employ Angular's last item check after its done the *ngFor loop and call our special function to seamlessly scroll back to the feed we are in.

    
for(var i=0; i < this.feeds.length; i++){
     this.feeds[i].hidden = true; //hide all feeds
}

for(i=start; i < end; i++){
        
    this.feeds[i].hidden = false; //unhide feeds in range

}


That's it! that will get you a fairly decent vertical scroll pagination on scroll. 

Here's the StackBlitz

Buy me a cup of coffee :)

Biyernes, Disyembre 11, 2020

Building a native Android and iOS app with Flutter

It's been years since I touched app development again for the reason of me focusing mainly on web development of the entirety of  my career. I am a little bit rusty but things seems promising. My current job is at a company that maintains its own Application on web, iOS and Android and I see the gory details every single day. 


Flutter has been popping up on my newsfeed  and it seems an interesting platform since it can do web, iOS and Android app in one go natively. Yes natively. The web part is at beta stage as of writing though but it's not a big deal. 

So I've been thinking of a way to learn flutter and this is by building my own app which is a simple app that I think will be helpful for ordinary folks in their everyday lives.

What you need:

  1. A decent computer that has enough ram for debugging.
  2. Flutter installer for your OS
  3. Android Studio for the SDK
  4. An IDE of your choice.
  5. Android/iOs Emulator or an actual device
First install Flutter then followed by Android Studio then your IDE. If all goes well you can now follow flutter's getting started tutorial which is explained in great detail.

I will try to write most of my journey on flutter development. Happy Coding!

Sabado, Agosto 19, 2017

Solving Bluetooth Device Problem on Ubuntu 17.04

I have an Asus SonicMaster laptop that runs the new Ubuntu 17.04 Zesty Zapus and everything is running great except that bluetooth. I want to enjoy wireless music you know. The bluetooth icon shows in the panel bar but does nothing.

Running "lshw" on the terminal got me started. I looked up the lines and found an unclaimed hardware device which is my bluetooth RALINK RT3290. Started searching from the forums and one pointed to install rtbth-dkms driver from launchpad.

So i obeyed and added blaze repo (https://launchpad.net/~blaze/+archive/ubuntu/rtbth-dkms)


//this two lines will add the blaze rtbth-dkms repository 
//on the system and update it along the way
sudo add-apt-repository ppa:blaze/rtbth-dkms
sudo apt-get update


Next step is to install it:


//install bluetooth driver
sudo apt-get install rtbth-dkms


Next step is to reboot your laptop and start the bluetooth once you got in. The instructions are listed here.

# Init
sudo modprobe rtbth
sudo rfkill unblock bluetooth
hcitool dev # check

# Switch off
sudo rfkill block bluetooth

# Switch on
sudo rfkill unblock bluetooth

# Shutdown
sudo pkill -2 rtbt
sudo rmmod rtbth


Once done your bluetooth device will be recognized and claimed by the driver.
Then I paired up my little bluetooth speaker and happily enjoying wireless music! Thanks to blaze for the bluetooth repo.








Biyernes, Agosto 18, 2017

Motherboard Repair - Acer Borg Iibtdl-borg 13057-1m W/ Intel(R) Celeron(R) CPU 1007U




So my aunt got this little ACER Mini-ITX pc that was not booting up. I looked at the capacitors and found some bulging 16V 220f electrolytic and I imidiately thought this will be an easy fix since all I have to do is replace those and it will be back to business. I had experience with this before with my AMD K6-2 mobo back in the day.

10 days later and I'm still stuck at figuring out what the heck is going on. Since I already replaced the suspected bad capacitors it still refuses to boot.

To the oven it is! I baked that sucker on a regular kitchen oven at 180 *C for 10 minutes. Cooled it down and hooked the ATX power plug and the powcer button connector. IT BOOTED UP!! So much for the excitement though because after shutting it down to insert the HDD and memory it was back to being dead.



Oven equals heat so I thought it boots when something is hot. My wife's trusty hair dryer came into play. Heated up the board entirely and when it was hot to the touch i plugged the mini board back with the ATX and power button connectors. You're right it came to life. Those beeps where beeps of joy. I diagnosed the problem and the next thing to do is to isolate the search for the failing component.

This time I wasn't sure yet what component needs to be hot so i took my soldering iron waited it to heat up just around 100 *C and started heating up the solid capacitors near the CPU by briefly touching it with the soldering tip. Those solid caps looks perfect from the outside and I don't have the proper equipment to test it inline the board.

Every time i heated a capacitor I then push the switch. Bingo! I found waldo. A solid, good looking filter capacitor was the criminal. You wouldn't even think it was bad. Next time i'm investing on proper tools but for now i got to use unorthodox methods for this job.



I had a 6.3v 1000uf low esr cap that i salvaged from a dead video card lying around so a quick work with the soldering iron is all needed. I decided that i'll skip removing the bad capacitor and instead rig the replacement cap with a wire that will run to the side because i'm afraid i'll damage those little components near the CPU. Ugly but works.



Huwebes, Hunyo 29, 2017

Variation Issue - WooCommerce Update 3.1.0

After the new 3.1.0 update, my custom variation stopped working due to a code update that checks my custom value against the pre-defined attribute values. With a little searching through the code using the error message it produced, i found that they have added the checking in "class-wc-form-handler.php" at around line 828.

 // Allow if valid or show error.
if ( $valid_value === $value ) {
    $variations[ $taxonomy ] = $value;
// If valid values are empty, this is an 'any' variation so get all possible values.
} elseif ( '' === $valid_value && in_array( $value, $attribute->get_slugs() ) ) {
    $variations[ $taxonomy ] = $value;
} else {
        throw new Exception( sprintf( __( 'Invalid value posted for %s', 'woocommerce' ), wc_attribute_label( $attribute['name'] ) ) );
}

I commented that section and added "$variations[ $taxonomy ] = $value;" before that code block and my site is back to normal.

Biyernes, Hulyo 17, 2015

DIY resistor from broken soldering iron

Nichrome (NiCr, nickel-chrome, chrome-nickel, etc.) generally refers to any alloy of nickel, chromium, and often iron and/or other elements or substances. Nichrome alloys are typically used in resistance wire. They are also used in some dental restorations (fillings) and in other applications.


Tools:
  • soldering Iron
  • Digital Multimeter
Materials:
  • nichrome wire from broken soldering iron
  • 2 x i inch stainless paper clips (cut it)
  • Plaster of Paris
  • small tube for mold
First is to measure the ohm value you want then cut the nichrome wire and solder it to the ends of the two stainless so it will be like:


Insert it to the tube centering it with a hard paper with a hole to let through the stainless wire. it will look like this:

The last step is to pour your Plaster of Paris into the mold covering the wires completely and leave it to dry.

Biyernes, Hulyo 3, 2015

Quick and easy Direct Drive Lead Acid Battery Desulfator - Battery Saver

Warning: This device can cause shock or fire hazard. Monitor usage always. The author cannot accept responsibility for any loss or damage arising from the use of this device.

Lead Acid Car and motorbike batteries tend to build sulfate crystals on the lead plates that results into lowering its capacity. This happens when you don't use your car/bike for months sitting in the garage. This is common for all Lead Acid batteries including your UPS backup batteries and there's a way to recover them if there's no shorted cells yet.



This device is consisted of a capacitor bank, diodes and a 12 volt relay and that's it! The relay will act as a very fast on/off switch that will push the charge from the capacitor bank into the battery in a pulsing manner. The pulse is estimated between 90Hz and 150Hz - not much but I managed to save two of my motorbike batteries that won't hold charge  for a day. The power source is my trusted 19V 90W 3A laptop charger.



Parts:

6  x 100v 1000uF  Electrolytic
1  x 12v 10A relay
5  x 1N4008 Diodes
2 x 25V 100uF Electrolytic


Follow the diagram exactly as it is. The desulfator also acts as the main charger so a separate charger is not necessary. Use it once a month to pulse-charge your battery for maximum life-span.

Save the Earth!