Skip to content

Instantly share code, notes, and snippets.

Avatar

Dexter Legaspi dalegaspi

View GitHub Profile
@dalegaspi
dalegaspi / flask_redis.py
Created Jun 16, 2021
Flask Redis PUT/GET Endpoints
View flask_redis.py
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
@app.route('/api/guestbook/message', methods=['POST', 'PUT'])
def api_put_message():
form_data = request.form
id = str(uuid.uuid4())
data = {
'ts': round(time.time() * 1000),
'id': id,
'email': form_data['email'],
@dalegaspi
dalegaspi / vue_vs_react.md
Last active Jun 14, 2021
Vue vs React 2021
View vue_vs_react.md

For me, the better choice Vue.js regardless of size of the project. And this can be explained succintly with three simple words: Two Way Binding.

When I began using JavaScript frameworks for dynamic UI, I started with the original AngularJS. It is the original framework that elegantly implemented two-way binding in an MVVM framework, where a model is bound to an element/elements. The original implementation didn't scale as well (i.e., there is severe page performance as you add more and more two-way bindings), but this was actually mitigated (to an extent) by the introduction of one-way binding construct in v1.5.

If this feature is so great, why do some developers hate it and even calling it anti-pattern? A few reasons I could think of, actually.

  • While VueJS (and the newer Angular 2.x) has addressed the performance issues plagued by two-way bindings in Angular 1.x, there is a tende
@dalegaspi
dalegaspi / es6_arrow_functions.md
Last active Jun 8, 2021
Arrow Functions and the Road to Declarative Programming
View es6_arrow_functions.md

Arrow Functions and the Road to Declarative Programming

Consider this data:

let tbl_hs_students = {
  headers: [
    "First Name",
    "Year",
    "House",
@dalegaspi
dalegaspi / install_py_3_centos7.md
Created Jun 1, 2021
How to Install Python 3 on Centos 7
View install_py_3_centos7.md

How to Install Python 3 on Centos 7

  1. yum -y update
  2. yum install -y python3

you now have python3.

@dalegaspi
dalegaspi / ConvertHttpMethodFilter.java
Created Apr 22, 2021
Custom Spring Cloud Gateway to change HTTP Method In Flight
View ConvertHttpMethodFilter.java
package yeet;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@dalegaspi
dalegaspi / DynamicPostTransformFilter.java
Last active Sep 3, 2021
Spring Cloud Gateway Response Modification
View DynamicPostTransformFilter.java
package yeet;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.Strings;
import org.reactivestreams.Publisher;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter;
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
import org.springframework.cloud.gateway.filter.factory.rewrite.MessageBodyDecoder;
@dalegaspi
dalegaspi / windows_10_boot_loop.md
Created Jun 15, 2020
Windows 10 Preparing Automatic Repair Infinite Loop Issue
View windows_10_boot_loop.md

This issue has happened to me recently and this happened after i rearranged the cables on my custom PC to make it look cleaner.

Windows will just get stuck into the spinning dots and after 2 hard reboots it will go into the "Prepare Automatic Repair" then goes blank not able to boots successfully and will not even go into Safe/Repair mode.

Trying to boot Windows via USB is also successful. Windows Installer will start really slow but eventually gets stuck in starting the actual install. Selecting the PC Repair option leaves you in this state.

After a couple of hours troubleshooting, it turns out that the cable to one of the secondary SATA drives (NVMe is used as primary drive) isn't plugged in completely (most likely got dislodged while I was rearranging the cable as it's only held on by friction). Once i plug it in again, Windows has booted up successfully.

**TLDR: Windows 10 won't boot when one of the secondary SATA drives isn't plugged in correctly...make sure all SATA drives are plugged in pro

@dalegaspi
dalegaspi / winboot.md
Created Apr 5, 2020
Creating Bootable Win10 Disk
View winboot.md

This is the most updated instructible for creating a bootable Windows 10 USB drive:

https://alexlubbock.com/bootable-windows-usb-on-mac

Not only does it creatively uses rsync it also has provided a workaround when install.wim exceeds 4GB (the maximum file size for a FAT32 FS which the thumb drive is formatted with)

@dalegaspi
dalegaspi / log.py
Created Aug 1, 2019
Python Logging with YAML configuration
View log.py
import logging
import logging.config
import yaml
from pathlib import Path
# https://stackoverflow.com/a/52266636/918858
here = Path(__file__).parent
LOG_CFG = here/'logging.yaml'
@dalegaspi
dalegaspi / graphql_sangria_scala.md
Created Jun 7, 2019
Thoughts on GraphQL and Sangria
View graphql_sangria_scala.md

Thoughts on GraphQL and Sangria

I have recently implemented GraphQL as an enhancement to an existing REST microservice application (written in Akka HTTP Framework) and here are a few random thoughts:

  • Sangria certainly makes things easy to adapt GraphQL to most Scala projects. The way the resolvers are implemented are elegant and simple; e.g. there's no explicit way of different handling whether your resolve method is a Future[T] or just a value; it's treated the same in code.
  • Sangria can use existing case classes for the GraphQL objects, and provides macros to avoid boilerplate. However, there are a bunch of caveats and limitations; we are using scalaxb to generate our case classes from XSDs, and sadly these are not workable with the Sangria macros. Fortunately, with the awesome libray Chimney this makes it less painf