Skip to content

Instantly share code, notes, and snippets.

View joncardasis's full-sized avatar
Hold on a sec. My pour over is on its second bloom.

Jon Cardasis joncardasis

Hold on a sec. My pour over is on its second bloom.
View GitHub Profile
@joncardasis
joncardasis / usePromise.ts
Created September 21, 2021 16:33
usePromise React hook with TypeScript. React-ify promise resolutions
import { useCallback, useState, useRef, useEffect } from 'react';
const usePromise = <T, U extends any[]>(operation: (...args: U) => Promise<T>) => {
const [data, setData] = useState<T>();
const [error, setError] = useState<Error>();
const [loading, setLoading] = useState(false);
const mounted = useRef<boolean>(true);
useEffect(
() => () => {
@joncardasis
joncardasis / SkeletonView.tsx
Last active July 20, 2022 23:38
Simple SkeletonView react-native component (react-native-reanimated v1.9.0)
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import Animated, {
block,
Clock,
cond,
Easing,
eq,
set,
@joncardasis
joncardasis / useOrientation.ts
Last active December 4, 2019 19:05
Simple React Native rotation lock with React Hooks
/**
1. Install and configure `react-native-orientation-locker`.
2. In both the iOS and Android projects, set the allowed platform orientations to everything except upside down.
*/
import { useEffect } from 'react';
import Orientation, { OrientationType } from 'react-native-orientation-locker';
export function useLockOrientationPortrait() {
Orientation.lockToPortrait();
@joncardasis
joncardasis / jailbreak_protect.c
Last active May 26, 2024 22:38
iOS - Prevent debugger attachment in a jailbroken environment. Obfuscated by assembly and symbol mangling.
//
// jailbreak_protect.c
//
// Created by Jonathan Cardasis (C) on 10/11/19.
// Copyright © 2019 Jonathan Cardasis (C). All rights reserved.
//
// Source: https://medium.com/@joncardasis/mobile-security-jailbreak-protection-84aa0fbc7b23
// Simply include this file in your project and ensure the file's Target Membership
// is set to your app.
@joncardasis
joncardasis / jb_protect_all_archs.h
Last active August 23, 2021 11:32
jb_protect for all device architectures
//
// jailbreak.h
// jailbreak-protect
//
// Created by Jonathan Cardasis (C) on 10/11/19.
// Copyright © 2019 Jonathan Cardasis (C). All rights reserved.
//
#ifndef jailbreak_h
#define jailbreak_h
@joncardasis
joncardasis / jsBundleCache.sh
Created July 23, 2019 21:11
Detect if a jsbundle is dirty and needs to be rebuilt or if just the source code needs to be rebuilt
#!/bin/bash -e
# Check if JS code in a provided root folder has been changed.
# **SHOULD BE RUN WITH XCODE ENV VARIABLES**
#
# Creates a 'jsbundle-hashtable' in xcode product build directory to determine if
# the jsBundle needs to be rebuilt based on src directory hash value.
print_usage() {
printf "Usage: "
printf " %-20s %s\n" "--lookup-hash <target_name>" "Return hash value for <target_name> in table. Otherwise nothing is returned."
@joncardasis
joncardasis / optimizeImage.sh
Created April 5, 2019 20:28
Compresses and optimizes png image sizes for a given file or directory via pngquant.
#!/bin/bash
# Compresses and optimizes png image sizes for a given file or directory.
# @author: Jonathan Cardasis
CHECK_MARK="\033[0;32m\xE2\x9C\x94\033[0m"
PNGQUANT_BINARY_URL="https://pngquant.org/pngquant.tar.bz2"
optimize() {
ORIGINAL_PATH="$1"
NEW_PATH="$ORIGINAL_PATH.new"
@joncardasis
joncardasis / build_universal_fat_framework.sh
Last active March 2, 2020 17:14
Build universal ios fat framework
#!/bin/bash
#
# Builds the a framework for both the 64bit iOS architecture and
# a 64bit simulator architecture, combining the two into a single FAT framework.
#
set -e -o pipefail
print_available_options() {
printf "Usage: ./build_universal_ios_framework.sh -workspace <workspacepath> -target <targetname> -configuration <configurationname> -destination <destinationpath>\n\n"
printf "Options:\n"
@joncardasis
joncardasis / get-ip.sh
Created February 4, 2019 19:05
Gets the machine's IP address
#!/bin/bash
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
@joncardasis
joncardasis / gource.sh
Created January 29, 2019 21:59
gource - generate gource video for git repo
# Install ffmpeg
brew install ffmpeg
# Install gource
brew install gource
# Generate video
gource \
--hide filenames \
--seconds-per-day 0.1 \