Skip to content

Instantly share code, notes, and snippets.

View jeffypooo's full-sized avatar
🔥

Jefferson Jones jeffypooo

🔥
View GitHub Profile
@jeffypooo
jeffypooo / seriously.swift
Last active January 29, 2024 17:34
How to determine PresentationDetent type in SwiftUI (pre-iOS 16.4).
extension PresentationDetent {
/// Converts a `PresentationDetent` to an `ExpandableSheetDetent`
/// NOTE: Detents created using `.custom(_)` will fail to convert.
var expandableSheetDetent: ExpandableSheetDetent {
if self == .medium { return .medium }
if self == .large { return .large }
if let height = heightValue { return .height(height) }
if let fraction = fractionValue { return .fraction(fraction) }
let unknownType = type(of: self)
@jeffypooo
jeffypooo / gb-ticket.sh
Created April 6, 2023 18:47
Script to automate checking out a new git branch associated with a JIRA ticket, by parsing the ticket URL
#!/bin/bash
###############################################################################
# Script to create a new git branch for a JIRA ticket, using the ticket URL. #
# #
# Usage: gb-ticket.sh <ticket_url> <desc> #
###############################################################################
# Require parameters and parse them
if [ $# -ne 2 ]; then
@jeffypooo
jeffypooo / kill_pid_on_port.sh
Created February 15, 2021 22:49
Kill a process using a port
function kill_process_using_port() {
echo "attempting to kill process on port $1"
PID=$(lsof -t -i ":${1}")
if [ -z "${PID}" ]; then
echo "no process found using port ${1}"
return 1
fi
echo "killing pid ${PID}"
kill -9 "${PID}"
return 0
@jeffypooo
jeffypooo / cpustat.sh
Last active December 13, 2020 21:43
Raspberry Pi - Ubuntu - Get the CPU temperature and core frequency
#!/bin/bash
temp=$(</sys/class/thermal/thermal_zone0/temp)
freq_hz=$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq)
temp_f=`echo "$temp/1000" | bc -l`
freq_ghz_f=`echo "$freq_hz/1000000" | bc -l`
printf "CPU Temp: %.2f°C\n" $temp_f
@jeffypooo
jeffypooo / xcp-ng-rpm-nodesource-nodjs12.sh
Last active July 22, 2020 02:57
RPM Nodesource script but with versioning (assumes "CentOS-ish version 7")
#!/bin/bash
# Discussion, issues and change requests at:
# https://github.com/nodesource/distributions
#
# Script to install the NodeSource Node.js 12.x repo onto an
# Enterprise Linux or Fedora Core based system.
#
# Run as root or insert `sudo -E` before `bash`:
#
@jeffypooo
jeffypooo / View+Guides.swift
Created December 29, 2019 18:08
SwiftUI View Extensions
extension View {
func horizontalGuide(_ which: HorizontalAlignment, compute: @escaping (ViewDimensions) -> CGFloat) -> some View {
return alignmentGuide(which, computeValue: compute)
}
func verticalGuide(_ which: VerticalAlignment, compute: @escaping (ViewDimensions) -> CGFloat) -> some View {
return alignmentGuide(which, computeValue: compute)
}
@jeffypooo
jeffypooo / UseCases.kt
Created November 20, 2019 19:05
Usecase base classes
import io.reactivex.Observable
import io.reactivex.Single
/**
* Something that can be executed.
* @param ArgsType The argument data type.
* @param ReturnType The return data type for the execution
*/
interface AbstractExecutable<ArgsType : Any, ReturnType : Any> {
@jeffypooo
jeffypooo / Preferences.kt
Created November 13, 2019 21:30
Testable and decoupled preferences interface for Android apps
/**
* Data store for application preferences.
*/
interface AppPreferences {
/**
* Get the preference value for the given key.
* @param T The value type.
*/
operator fun <T : Any> get(key: String): T?
@jeffypooo
jeffypooo / Require.kt
Created October 13, 2019 22:19
Misc utilities similar to Kotlin stdlib require funcs
package com.beartooth.relaytestapp.util
import java.lang.ref.WeakReference
/**
* Require.kt
* author: jefferson jones
* org: Beartooth, Inc
* github: github.com/masterjefferson
* email: [email protected]
@jeffypooo
jeffypooo / Phone.kt
Last active June 29, 2019 20:37 — forked from espinchi/DeviceUtil.java
Check if the running device is an emulator
import android.os.Build;
/**
* Utility methods related to physical devies and emulators.
*/
object Phone {
val isEmulator: Boolean get() {
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")