Skip to content

Instantly share code, notes, and snippets.

View rvibit's full-sized avatar

Ravi Singh rvibit

View GitHub Profile
@rvibit
rvibit / FlastlistScroll.tsx
Created August 4, 2024 11:20
React Native Flatlist/Flashlist Reverse Page counter based on scroll position
const PER_PAGE = 30;
const [current_page,setPage] = useState(0);
const ITEM_HEIGHT = 55; //each item height including vertical padding/margin
const calculatePage = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
const cPage = Math.floor(e.nativeEvent.contentOffset.y / (ITEM_HEIGHT * (current_page + 1 * PER_PAGE)));
console.log(cPage);
return cPage;
};
[
// add namespace
{ "keys": ["f6"], "command": "import_namespace" },
// add constructor property
{ "keys": ["f7"], "command": "insert_php_constructor_property" },
// add namespace to class (expand to fully qualified class name)
{ "keys": ["f9"], "command": "expand_fqcn" },
// add FQCN to use statements
{ "keys": ["f10"], "command": "find_use" },
// ace jump to a word
@rvibit
rvibit / logger.ts
Created April 4, 2024 08:58
logger middleware for redux/toolkit
//copied from twillio-demo-app
import { type Middleware } from '@reduxjs/toolkit';
import { type Dispatch, type State } from '../app';
export type LogOptions = Readonly<{
logStackTrace?: boolean;
}>;
export const logMiddlewareDefaultOptions: LogOptions = Object.freeze({
@rvibit
rvibit / .env
Created February 4, 2023 13:51
.env file for laravel-shopify React SPA
VITE_SHOPIFY_API_KEY=xxxxxx
SHOPIFY_API_KEY=xxxxxxx
SHOPIFY_API_SECRET=xxxxxx
SHOPIFY_FRONTEND_ENGINE=REACT
SHOPIFY_BILLING_ENABLED=true
@rvibit
rvibit / Billable.php
Created February 4, 2023 13:47
vendor\kyon147\laravel-shopify\src\Http\Middleware\Billable.php for React SPA using laravel-shopify package
<?php
namespace Osiset\ShopifyApp\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Osiset\ShopifyApp\Contracts\Queries\Shop as ShopQuery;
use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
@rvibit
rvibit / web.php
Last active February 4, 2023 13:38
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
@rvibit
rvibit / welcome.blade.php
Last active February 4, 2023 13:27
laravel-shopify React SPA welcome view
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shopify Laravel Example</title>
@viteReactRefresh
@vite('resources/js/app.js')
</head>
<body>
@rvibit
rvibit / app.js
Last active February 4, 2023 13:33
shopify-laravel-app/resources/js/app.js file for laravel-shopify React SPA
import './bootstrap';
import "../css/app.css";
import '../frontend/index.jsx' //import react frontend entry file
@rvibit
rvibit / vite.config.js
Created February 4, 2023 13:03
vite.config.js for laravel-shopify react SPA
import { defineConfig, loadEnv } from "vite";
import laravel from "laravel-vite-plugin";
import react from "@vitejs/plugin-react";
import fs from "node:fs";
export default defineConfig(function ({ mode }) {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; //process.env is not accessible directly in this file so we have to do this
return {
plugins: [
laravel(["resources/css/app.css", "resources/js/app.js"]),
react(),
@rvibit
rvibit / package.json
Created February 4, 2023 12:40
package.json file for laravel-shopif React SPA
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"@shopify/app-bridge": "^3.1.0",
"@shopify/app-bridge-react": "^3.1.0",
"@shopify/app-bridge-utils": "^3.1.0",