Skip to content

Instantly share code, notes, and snippets.

View javascripter's full-sized avatar

javascripter

View GitHub Profile
@javascripter
javascripter / Ratings.tsx
Created November 27, 2024 20:16
A hand-optimized React Ratings Component that doesn't render multiple SVGs. Supports fractional values.
import * as React from 'react'
export function Ratings({
value,
width = 18,
height = 16,
gap = 2,
maxStars = 5,
color = '#f39c12',
}: {
@javascripter
javascripter / next.config.ts
Created November 26, 2024 12:10
Next.js + Turbopack + PostCSS example
// next.config.mjs
import type { NextConfig } from 'next'
function getBabelLoader() {
return {
loader: 'babel-loader',
options: {
presets: [
[
'next/dist/compiled/babel/preset-typescript',
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
const fs = require('fs');
@javascripter
javascripter / useIsMachineTranslationEnabled.ts
Last active November 25, 2024 19:29
Detection of Google Translate Usage in React
import * as React from 'react'
export function useIsMachineTranslationEnabled() {
const [isMachineTranslationEnabled, setIsMachineTranslationEnabled] =
React.useState(false)
React.useEffect(() => {
if (isMachineTranslationEnabled) {
return
}
import { parseArgs } from 'node:util'
import watchman, { Client } from 'fb-watchman'
import ansis from 'ansis'
import path from 'node:path'
import fs from 'node:fs'
import { globSync } from 'fast-glob'
import { transformSync } from '@babel/core'
import styleXBabelPlugin from '@stylexjs/babel-plugin'
diff --git a/node_modules/react-native-star-io10/src/Error.ts b/node_modules/react-native-star-io10/src/Error.ts
new file mode 100644
index 0000000..c9bc58a
--- /dev/null
+++ b/node_modules/react-native-star-io10/src/Error.ts
@@ -0,0 +1,4 @@
+// https://github.com/star-micronics/react-native-star-io10/issues/15
+export interface Error extends globalThis.Error {
+ code: string
+}
@javascripter
javascripter / migrate-redux-saga.ts
Last active February 25, 2021 21:57
redux-saga to typed-redux-saga
/*
Description:
This script converts `yield call()` to `yield* call()` syntax and 'redux-saga/effects' to 'typed-redux-saga'
Make sure to commit your files first before you run the below script!
Usage:
npx jscodeshift --parser tsx -t ./migrate-redux-saga.ts ./sagas/**\/*.ts
Before:
#include <stdio.h>
#include <string.h>
int main(void) {
int n;
int employees[4000] = {0};
while (1) {
scanf("%d", &n);
if (!n) break;
@javascripter
javascripter / gist:d376c9a4f22a947c5ff8
Created May 16, 2014 12:45
a step by step execution with generators
function* gcd(a, b) {
[a, b]
if (a < b) {
var t = a;
a = b;
b = t;
}
do {
r = a % b;