Author Archives: Tony

Life Lessons for Children

I’ve been thinking a lot lately about what values and ideals I want to instill into my children as they grow. I’ve been collecting my thoughts for some time and have tried to clearly articulate them below. I’ve also attached a PDF version for an easier one page print out.


Values and Character

  • Honesty and Integrity: Teach him the importance of telling the truth, keeping promises, and acting with integrity even when no one is watching.
  • Respect for Others: Encourage him to treat everyone—regardless of differences—with kindness and respect.
  • Empathy and Compassion: Help him understand others’ feelings, practice kindness, and show compassion to both people and animals.
  • Responsibility and Accountability: Instill the idea that he should take responsibility for his actions and learn from mistakes.
  • Courage and Resilience: Show him that it’s okay to fail sometimes and that perseverance and resilience are key to growth.

Social Skills and Relationships

  • Effective Communication: Teach active listening, clear expression of thoughts, and respectful disagreement.
  • Teamwork and Cooperation: Emphasize the value of working together, sharing, and understanding that collective effort often leads to better outcomes.
  • Conflict Resolution: Provide strategies for resolving disputes peacefully and learning to compromise.
  • Building Healthy Friendships: Explain the qualities of a good friend and how to maintain positive, supportive relationships.

Practical Life Skills

  • Basic Financial Literacy: Introduce concepts like saving, spending wisely, and even a simple understanding of budgeting.
  • Digital Literacy and Internet Safety: Teach him to navigate the digital world safely, including understanding privacy, respectful online behavior, and critical evaluation of information.
  • Time Management and Organization: Help him plan his day, set priorities, and keep track of responsibilities like homework and chores.
  • Self-Care and Hygiene: Ensure he understands the importance of personal hygiene, nutrition, exercise, and enough rest.

Intellectual and Emotional Growth

  • Critical Thinking and Problem Solving: Encourage curiosity, ask open-ended questions, and engage him in puzzles or activities that stimulate creative thinking.
  • Growth Mindset: Reinforce that abilities can improve through practice and that effort is more important than innate talent.
  • Emotional Regulation: Teach him how to identify and manage his emotions, from anger to disappointment, using strategies like taking deep breaths or talking through feelings.
  • Mindfulness and Gratitude: Introduce practices that help him stay present, reflect on positive experiences, and appreciate what he has.

Cultural and Environmental Awareness

  • Environmental Responsibility: Teach him about recycling, conservation, and the importance of protecting the natural world.
  • Civic Engagement: Discuss the role of community and how even small actions can contribute to the greater good.

Safety and Well-being

  • Personal Safety: Cover basic safety rules such as road safety, stranger awareness, and when to ask for help.
  • Digital and Physical Boundaries: Teach him about respecting his own space and the personal boundaries of others.
  • Health Education: Provide age-appropriate information about how his body works, the importance of physical activity, and making healthy lifestyle choices.

Creativity and Self-Expression

  • Encouraging Creativity: Support his interests in art, music, writing, or any creative outlet that lets him express himself.
  • Curiosity and Lifelong Learning: Foster an attitude of exploration—learning is a continuous journey that goes beyond the classroom.
  • Setting Goals and Celebrating Achievements: Help him set realistic goals, track progress, and celebrate successes, no matter how small.

Ethical Reasoning and Decision-Making

  • Moral Decision-Making: Discuss scenarios that help him think about right versus wrong and make ethical decisions.
  • Understanding Consequences: Teach him that every action has consequences and that thoughtful decisions lead to positive outcomes.
  • Accountability in Actions: Reinforce that both successes and failures offer opportunities to learn and improve.

React: The Documentary

The documentary on the origins of React is finally out! This technology fundamentally changed the way the world did front-end development and how we create web application. I’m super proud and honored to be representing the innovative folks at Netflix who were brave enough to adopt this transformative new technology and outrun the competition.

Simple Cache Expiration for Apollo GraphQL Queries

The Problem

There are times when you want to fetch data from your server that is occasionally changed. For example, getting the number of unread messages in an application. There are a few possible solutions for keeping the data up-to-date with the backend. 1) You can poll the server every X minutes, or 2) you can use “cache-and-network” to utilize the cache first, but also check the server for updated data.

Polling

If you choose to poll for new messages, you run the risk of your application constantly calling the server for data even though the user has not recently interacted with the page. Think, checking another tab or walking away from the computer for a while. While not detrimental, this results in a lot of wasted calls and network requests.

Cache and Network

This method ensures you always have the most up-to-date information from the server, but also results in a lot of needless calls to the server. The client is constantly saying, “Ok, I’ll use the cache, but let me still call the server to check for updated data.” This query/hook may run multiple times on a single user interaction and is still to aggressive for data that only updates every few minutes.

The Solution

What we really want is the best of both worlds. We want to utilize the cache as much as possible, but also set an expiration for when to grab fresh data from the server. We can use a simple technique of utilizing Map and dates to accomplish this goal.

We’ll simply make a unique “key” for our query and record the last time we fetched that key. When we call useQuery, we pass it our “key” and the expected expiration time. If the “key” is still valid, we return to useQuery the fetchPolicy of “cache-first.” This means, use the cache if it exists and otherwise fetch from the server. If the “key” is invalid, we call useQuery with “network-only” which calls the server to refresh the data. And at the same time, we update the last fetched time of the key.

Let’s take a look at an example of the getFetchPolicyForKey() function and its implementation.

useUnreadMessages.ts

import { getFetchPolicyForKey, ONE_MINUTE } from "./hooks/useCacheWithExpiration";

export const useUnreadMessages = (): number => {
    let unreadMessages: number = 0;

    const { data, error } = useQuery(UNREAD_MESSAGES_DOC, {
        fetchPolicy: getFetchPolicyForKey("unreadMessages", ONE_MINUTE * 5),
    });

    if (isDefined(data)) {
        unreadMessages = data.unreadMessages
    }

    return unreadMessages;
}

And here’s the implementation of the cache check and when to return each fetch policy.

getFetchPolicyForKey.ts

// Record of keys and the last fetched timestamp
// These are universal for all calls and hooks
const keys = new Map<string, number>();

export const ONE_MINUTE = 1000 * 60;

/**
 * This function accepts a unique key and an expiration date. It returns "network-only" if the cache key is expired
 * or "cache-first" if the key is still valid for the given expiration time
 *
 * @param key - the unique name you want to give this expiration key
 * @param expirationMs)
 */
export const getFetchPolicyForKey = (key: string, expirationMs: number): WatchQueryFetchPolicy => {
    const lastFetchTimestamp = keys[key];
    const diffFromNow = lastFetchTimestamp ? Date.now() - lastFetchTimestamp : Number.MAX_SAFE_INTEGER;
    let fetchPolicy: WatchQueryFetchPolicy = "cache-first";

    // Is Expired?
    if (diffFromNow > expirationMs) {
        keys[key] = Date.now();
        fetchPolicy = "network-only";
    }

    return fetchPolicy;
};

Financial Overview V2 – Track your stock portfolio and retirement accounts with Google Sheets

I’d like to share the spreadsheet I use for tracking my entire financial overview. I’ve always preferred keeping track of my accounts in a spreadsheet for 2 reasons. (1) I don’t like giving my personal financial information to a 3rd party. (2) I can use spreadsheets to analyze data and even perform custom calculations. Such as, what’s the delta on the current price vs the 52 week low.

I’ve been slowly building this over the last few years and it is finally time to share V2. Here are the main features I like about this spreadsheet:

  • Tracks investments across multiple institutions and account types (IRA, 401k, brokerage)
  • Shows portfolio distribution by holding type and account
  • Tracks heaviest investments across all accounts
  • Live charts for stocks
  • Live expense ratios for ETFs and Funds
  • Track heaviest positions across stocks and funds
  • See your diversification across accounts and investment categories

So without further ado, here is the spreadsheet for you to copy.

See types of diversification
Track heaviest positions

Custom PM Sensor for Poor Air Quality

We’ve been having bad air in the Bay Area for a few weeks now and it got me wondering how much was seeping into my house and garage. After a little tinkering, I finished a custom, portable PM2.5 and PM10.0 sensor. The initial build used a SDS011, which promptly died after a week. I moved on to the “less” accurate PMS5003 and have been quite happy with the results. Here’s the sensor in action.

Google Sheet for Tracking Your Portfolio

I’d like to share the spreadsheet I use for tracking my portfolio. I’ve always preferred keeping track of my portfolio in a spreadsheet for 2 reasons. (1) I don’t like giving my personal financial information to a 3rd party. (2) I can use spreadsheets to analyze data and even perform custom calculations. Such as, what’s the delta on the current price vs the 52 week low.

I’ve been slowly building this over the last few years and it is finally time to share. Here are the main features I like about this spreadsheet:

  • Tracks investments across multiple institutions and account types (IRA, 401k, brokerage)
  • Shows portfolio distribution by holding type and account
  • Tracks heaviest investments across all accounts
  • Live charts for stocks
  • Live expense ratios for ETFs and Funds

So without further ado, here is the spreadsheet for you to copy.