Skip to content

Instantly share code, notes, and snippets.

View dnedrow's full-sized avatar

David Nedrow dnedrow

View GitHub Profile
@dnedrow
dnedrow / leadingDigits.sql
Created February 23, 2022 03:14
How to get leading digits when retrieving data from PostgreSQL
with sample_numbers (nr) as (
values (1),(11),(100)
)
select to_char(nr, 'fm000')
from sample_numbers;
/*
Example output:
to_char
@dnedrow
dnedrow / xliff-example.xml
Last active February 19, 2022 15:50
Example of using xliff:g to mark parts of strings that shouldn't be translated
<!--
ref: https://github.com/icerockdev/moko-resources
Often strings contain text that should not be translated into other languages.
Common examples might be a piece of code, a placeholder for a value, a special
symbol, or a name. As you prepare your strings for translation, look for and
mark text that should remain as-is, without translation, so that the translator
doesn't change it.
@dnedrow
dnedrow / hbdualinst.sh
Created February 16, 2022 19:39
Shell script to install both ARM and Intel versions of Homebrew on M1+ Mac
#!/bin/bash
// This script can be used to install Homebrew both both MacOS
// architectures when run on an M1+ Mac.
//Install the ARM version
arch -arm64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
// Install the Intel version
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@dnedrow
dnedrow / TouchIDsudo.md
Created November 9, 2021 00:15
Enable TouchID auth for sudo in macOS

Add the following line

auth       sufficient     pam_tid.so

immediately after

auth       sufficient     pam_smartcard.so

in the /private/etc/pam.d/sudo file.

@dnedrow
dnedrow / JSEnum.js
Created October 2, 2021 01:05
JavaScript enum implementation
/**
* Creates a frozen "enumeration"
* @see https://masteringjs.io/tutorials/fundamentals/enum
* @example createEnum(['Up', 'Down', 'Left', 'Right']) returns { Up: 'Up', Down: 'Down', Left: 'Left', Right: 'Right' }
* @param values Array of items with which to create enum
* @returns {Readonly<{}>}
*/
export function createEnum(values) {
const enumObject = {};
for (const val of values) {
@dnedrow
dnedrow / pastetoemulator.sh
Last active November 9, 2021 00:20
Script demonstrating how to use adb and pbpaste to insert test in an Android emulator.
#!/bin/bash
# Copy something to your Mac clipboard. This script will paste it into
# a focused text field in the Android emulator.
# As always, you could also create an alias for the command or just
# run it manually.
adb shell input text `pbpaste`
@dnedrow
dnedrow / brewdump.sh
Last active April 13, 2022 00:21
Shell script for backing up the list of installed Homebrew (brew) packages
#!/bin/zsh -l
# This script can easily be added to your crontab for scheduled backups.
#
# EXITS
SUCCESS=0
BUNDLE_FAILED=1
BACKUP_FILE_EXISTS=2
MOVE_FAILED=3
NO_HOMEBREW=4
// yarn add react-native-extra-dimensions-android
const {Platform, Dimensions} = require('react-native');
const deviceHeight =
Platform.OS === 'ios'
? Dimensions.get('window').height
: require('react-native-extra-dimensions-android').get('REAL_WINDOW_HEIGHT');
@dnedrow
dnedrow / KMPHTTPStatus.kt
Last active August 2, 2021 15:40
Getting HTTP status codes in ApolloGraphQL Kotlin multiplatform client
/*
While working on a Kotlin Multiplatform project, I needed to examine
the HTTP response code when a call to the GraphQL server fails.
ApolloGraphQL server will always return HTTP 200, regardless of whether
the query failed or succeeded on the GraphQL server.
There are often cases where errors may occur before the GraphQL server
is accessed. An example would be redirects (300–399), client errors (400–499), etc.
*/
@dnedrow
dnedrow / isSimulator.js
Created January 4, 2021 21:29
Determine is React/Native app is running in an emulator/simulator.
import DeviceInfo from 'react-native-device-info'
isSimulator() {
// https://github.com/react-native-community/react-native-device-info#isemulator
return DeviceInfo.isEmulator();
},
// Found in https://stackoverflow.com/a/35529545