Skip to content

Instantly share code, notes, and snippets.

View chhornponleu's full-sized avatar

Ponleu chhornponleu

View GitHub Profile
@chhornponleu
chhornponleu / index.tsx
Created November 11, 2024 13:59 — forked from RaphBlanchet/index.tsx
React-Native SectionList item layout calculations
/* -----------------------
* One thing that is not really sepcified in React-Native's documentation
* of SectionList is what should be provided in getItemLayout function.
* In fact, this function is called for **every** items in your list,
* including the sections' header and footer EVEN IF YOU DON'T PROVIDE
* ANY COMPONENTS FOR THESE ITEMS. This is really important, otherwise you
* would have an offset in your items layout and what's displayed!
* This doesn't apply to "ItemSeparatorComponent", however.
* ----------------------- */
@chhornponleu
chhornponleu / widget.md
Created January 5, 2024 03:57 — forked from nandorojo/widget.md
How to create an iOS Widget with React Native (Expo / EAS)

First, copy the config plugin from this repo: https://github.com/gaishimo/eas-widget-example

You can reference my PRs there too (which, at the time of writing, aren't merged).

After adding the config plugin (see app.json) with your dev team ID, as well as a bundle ID, you can edit the widget folder to edit your code. Then npx expo run:ios (or npx expo run:android).

Workflow

After npx expo run:ios, open the ios folder, and open the file that ends in .xcworkspace in XCode. Make sure you have the latest macOS and XCode versions. If you don't, everything will break.

Oh my zsh.

Oh My Zsh

Install ZSH.

sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh

Install Oh my ZSH.

@chhornponleu
chhornponleu / envFileToJS.js
Created October 23, 2023 10:31 — forked from a-tokyo/envFileToJS.js
Converts a .env file to a .env.js file
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const os = require('os');
/**
* Writes bash env variables to a .env.js file
*/
// const _bashEnvToEnvFileJs = () => {
// /** Destination Env file path */

Creating an Expo app in 2023

12th July, 2023. I'm going to try creating an iOS app called Paranovel, using Expo. My environment for mobile app dev (Xcode, Ruby, etc.) should be in reasonably good shape already as I frequently develop with React Native and NativeScript.

Creating the app

Go to https://docs.expo.dev, and see the Quick Start: npx create-expo-app paranovel

This runs with no problem, then I get this macOS system popup:

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import java.lang.reflect.Method;
// MIUI. Redefining Android.
@chhornponleu
chhornponleu / useEffectEvent.ts
Created February 7, 2023 06:42
useEffectEvent
/**
* original https://github.com/scottrippey/react-use-event-hook
*/
import { useLayoutEffect, useRef } from 'react';
type AnyFunction = (...args: any[]) => any;
function useEvent_shouldNotBeInvokedBeforeMount() {
console.warn(
'INVALID_USEEVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.'
@chhornponleu
chhornponleu / deeplinking parser
Last active September 19, 2023 08:20
extract params from route path
function matchRoute(url, routes) {
let route = null;
let exactMatchRoute = null;
for (let i = 0; i < routes.length; i++) {
const routePath = routes[i].path;
const routeName = routes[i].name;
const handler = routes[i].handler;
const routeParams = {};
const urlParts = url.split('/');
@chhornponleu
chhornponleu / prisma.service.ts
Created November 21, 2022 03:45
nestjs: prisma service with read instance
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
import { PrismaClient, Session, User } from "@prisma/client";
import * as _ from "lodash";
import * as minimatch from "minimatch";
import { AppConfigService } from "../app-config/app-config.service";
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
@chhornponleu
chhornponleu / fix_rbenv.md
Created August 9, 2022 06:39 — forked from esteedqueen/fix_rbenv.md
How to fix rbenv: version `x.x.x` is not installed

So, you just cloned an existing project's repo and you run bundle install but you got the error: rbenv: version x.x.x is not installed....

What the issue means? The project uses a specific ruby version that you do not have on your system.

Here's how to fix it:

  • Install the Ruby build for the specified version using:
rbenv install x.x.x