Skip to content

Instantly share code, notes, and snippets.

@ide
ide / fix-mac-audio.sh
Created July 10, 2020 02:02
Fix audio by restarting coreaudiod on macOS
# macOS regularly enters a bad state where audio doesn't play at all or the sound levels are miscalibrated and the
# speakers are quiet even at high volume settings. Various sites suggest different approaches, some of which worked for me
# and some which didn't.
#
# Restarting the audio daemon is ideal since you don't need to restart your computer and fortunately it has worked in
# several scenarios for me.
# This works for me the most when my audio doesn't work on video calls or when my sound levels are miscalibrated
sudo launchctl stop com.apple.audio.coreaudiod
sudo launchctl start com.apple.audio.coreaudiod
@douglashill
douglashill / updateSafeAreaForKeyboardFromNotification.swift
Last active June 25, 2023 16:11
Avoid the keyboard by leveraging additionalSafeAreaInsets.
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets.
// You can put this in the root view controller so the whole app will avoid the keyboard.
// Only tested on iOS 13.3.
// Made for https://douglashill.co/reading-app/
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) {
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
// Please consider whether the force unwrap here is safe for your own use case.
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@tjeerdintveen
tjeerdintveen / inspect.swift
Created October 18, 2018 13:24
inspect as an extension on Sequence
extension Sequence {
public func inspect(
_ body: (Element) throws -> Void
) rethrows -> Self {
for element in self {
try body(element)
}
return self
}
}
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
final Pie pie = AnyChart.pie();
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("Apples", 6371664));
data.add(new ValueDataEntry("Pears", 789622));
data.add(new ValueDataEntry("Bananas", 7216301));
data.add(new ValueDataEntry("Grapes", 1486621));
data.add(new ValueDataEntry("Oranges", 1200000));
import Foundation
private let TASK_BASIC_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_basic_info_data_t>.size / MemoryLayout<UInt32>.size)
private let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<UInt32>.size)
enum Process {
static var cpuUsage: Double {
var arr: thread_act_array_t?
var threadCount: mach_msg_type_number_t = 0
@LuizZak
LuizZak / README.md
Last active February 22, 2019 00:50
A chainable, storable, composable configuration object featuring Swift keypaths

With.swift - A chainable, storable, composable configuration object featuring Swift keypaths

Based on some source I don't exactly remember right now but will add a link to later.

// When used on instances, allows changing fields directly using keypaths (handy way to avoid 'lazy var' property closures!)
let label
    = UILabel()
        .with(\.text, setTo: "Hello!")
        .with(\.textColor, setTo: UIColor.darkGray)
//
// Config.swift
// Analytics
//
public protocol AnalyticsConfig {
static var analyticsKey: String { get }
static var appVersion: String { get }
}
@ryansimms
ryansimms / circleci-2.0-eb-deployment.md
Last active February 22, 2024 04:55
Deploying to Elastic Beanstalk via CircleCi 2.0

Deploying to Elastic Beanstalk via CircleCi 2.0

I got to here after spending hours trying to deploy to an Elastic Beanstalk instance via CircleCi 2.0 so I thought I'd write up what worked for me to hopefully help others. Shout out to RobertoSchneiders who's steps for getting it to work with CircleCi 1.0 were my starting point.

For the record, I'm not the most server-savvy of developers so there may be a better way of doing this.

Setup a user on AWS IAM to use for deployments

@przbadu
przbadu / react-on-docker.md
Last active May 12, 2024 15:34
Setup Docker for React development

STEP 2: setup docker to run react app (dev and production) configuration: https://gist.github.com/przbadu/929fc2b0d5d4cd78a5efe76d37f891b6

Setup Docker for React development

Because we are using Docker, we are not going to install node, npm, create-react-app in our development machine, not even for generating create-react-app scaffold.

For this purpose I am using 2-step docker configuration:

  • In first step, we will create a simple docker container, that does only one thing, install create-react-app