Skip to content

Instantly share code, notes, and snippets.

@badsyntax
badsyntax / android_emulator_cli_ci.md
Last active May 3, 2024 04:01
start an android emulator with screen dimensions (specifically for use in CI)
# Install AVD files
yes | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86'
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-29;default;x86' --force

$ANDROID_HOME/emulator/emulator -list-avds
@badsyntax
badsyntax / react-native-apple-m1.md
Last active March 11, 2024 18:25
Some tips to working with react-native 0.64 on an Apple M1 Silicon chip

My env:

  • cocoapods 1.10.1
  • xcode 12.4
  • macos big sur 11.2.3
  • react-native 0.64

iOS

The iOS simulator build won't "just work". If you get errors like ld: library not found for... or swift compiler errors, then you need to disable arm64 for the simulator build.

https://github.com/react-native-community/releases/issues/214#issuecomment-791487871
@badsyntax
badsyntax / workaround.md
Last active June 16, 2021 06:32
Apple M1 workarounds

For npm packages that don't provide arm binaries:

npm i --target_arch=x64

For gradle packages that don't provide arm binaries:

// for apple m1, please add protoc_platform=osx-x86_64 in $HOME/.gradle/gradle.properties
@badsyntax
badsyntax / .vimrc
Created February 12, 2021 20:28
.vimrc
set nowrap
" Make vim more useful
set nocompatible
" Enhance command-line completion
set wildmenu
" Allow cursor keys in insert mode
set esckeys
" Optimize for fast terminal connections
set ttyfast
@badsyntax
badsyntax / React Native Clear Cache
Created February 5, 2021 18:11 — forked from jarretmoses/React Native Clear Cache
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
1. Create a new directory;
mkdir Apple\ Enterprise
cd Apple\ Enterprise
2. Generate a certificate signing request
openssl req -nodes -newkey rsa:2048 -keyout ios_enterprise.key -out CertificateSigningRequest.certSigningRequest
3. With the information like so (ensure you give it a password):
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:London

Some pain points:

  • HMR is not always practical for server side development. For example HMR interferes with the initialisation of prom-client (and probably other libs), and there's no way to configure the HMR behaviour in Next.js (at time of writing).
    • "Interferes" meaning exceptions are thrown due to a "singleton" class being instantiated twice
  • If you're using TypeScript, you'll need a completely seperate build process for server code:
    • Generated server files are not part of the next build (ie don't exist within .next) - this is a pain when deploying or adding to a docker image
  • If you're consuming common code across the custom server and Next.js build, you're going to have 2 different compiled versions
@badsyntax
badsyntax / Dockerfile
Last active December 23, 2020 18:27
Next.js Dockerfile
FROM node:14.15.3-alpine AS builder
WORKDIR /app
ENV NPM_CONFIG_LOGLEVEL warn
ENV NPM_CONFIG_FUND false
ENV NPM_CONFIG_AUDIT false
ENV CI true
COPY package.json package-lock.json ./
@badsyntax
badsyntax / node-ipc.js
Last active November 28, 2020 21:47
Super simple Node.js IPC with Unix domain sockets
const net = require('net');
const socketPath = '/tmp/my.unix.sock';
const server = net
.createServer()
.on('connection', (stream) => {
console.log('Server: client connected');
stream.setEncoding('utf-8');