Skip to content

Instantly share code, notes, and snippets.

View brunogama's full-sized avatar
🏠
Working from home

Bruno Gama brunogama

🏠
Working from home
  • Banco Inter
  • Brazil
  • 00:17 (UTC -03:00)
  • X @brunogama
View GitHub Profile
@brunogama
brunogama / .gitconfig
Created January 14, 2021 17:38 — forked from gonchar/.gitconfig
git aliases
[alias]
# full status
rstatus = !sh -c 'git status -sb --ignore-submodules=dirty && git submodule foreach --recursive git status -sb --ignore-submodules=dirty' -
rstatus-no-subs = !sh -c 'git status -sb --ignore-submodules=all && git submodule foreach --recursive git status -sb --ignore-submodules=all' -
s = !sh -c 'git rstatus-no-subs' -
# fetches all modules
rfetch = !sh -c 'git fetch && git submodule foreach --recursive git fetch' -
# updates project and all submodules
r-fetch-pull-merge = !sh -c 'git rfetch && git submodule foreach --recursive git merge && git merge && git s' -
r-fetch-pull-rebase = !sh -c 'git rfetch && git submodule foreach --recursive git rebase && git rebase && git s' -
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@brunogama
brunogama / post-checkout
Created September 24, 2020 15:05 — forked from lyrixx/post-checkout
Git post checkout
#!/bin/bash
# Put this file at: .git/hooks/post-checkout
# and make it executable
# You can install it system wide too, see http://stackoverflow.com/a/2293578/685587
PREV_COMMIT=$1
POST_COMMIT=$2
NOCOLOR='\e[0m'
@brunogama
brunogama / BetterDecodingError.swift
Created August 22, 2020 16:07 — forked from nunogoncalves/BetterDecodingError.swift
Better Decoding Error Messages
import Foundation
enum BetterDecodingError: CustomStringConvertible {
case dataCorrupted(_ message: String)
case keyNotFound(_ message: String)
case typeMismatch(_ message: String)
case valueNotFound(_ message: String)
case any(_ error: Error)
@brunogama
brunogama / convertPDFToPNG3x.sh
Created August 21, 2020 16:25 — forked from kampfgnu/convertPDFToPNG3x.sh
convert vector pdf to iOS image assets
#!/bin/bash -e
# convert vector pdf to iOS image assets
# copy this script to the folder where the pdf files live and run "./convertPDFToPNG3x.sh" in terminal.
# this will generate [filename]@3x.png, [filename]@2x.png and [filename].png images in the same folder
# Ensure we're running in location of script.
cd "`dirname $0`"
@brunogama
brunogama / svg-convert.sh
Created August 21, 2020 14:19 — forked from igorkulman/svg-convert.sh
SVG to PNG convert and resize
#!/bin/bash
# I made this script to convert SVG icons for an iOS app into PNG.
# The script will create icons in 3 sizes for different screen DPIs.
find "$(cd ..; pwd)" . -type f -name "*.svg" | while read f
do
FILENAME="${f%.*}"
echo '---'
inkscape -W "$FILENAME.svg"
@brunogama
brunogama / cases.swift
Created August 7, 2020 19:21 — forked from heestand-xyz/cases.swift
Swift Cases
import Foundation
fileprivate let badChars = CharacterSet.alphanumerics.inverted
public extension String {
var camelToTitleCased: String {
if self.count <= 1 {
return self.uppercased()
}
@brunogama
brunogama / README.md
Created July 3, 2020 17:30 — forked from jboehler/README.md
Xcode Behavior Script: Run SwiftLint & SwiftFormat only on modified files (using git to find modified files)

Xcode Behavior Script: Run SwiftLint & SwiftFormat

In Xcode settings you can define your own Behavior Scripts. This script will apply swiftlint and swiftformat to all modified files. The modified files are detected with the help of git.

Xcode Behavoior Script can be assigned with a shortcut so this script can be used to format swift code in xcode with a shortcut. 😎

Dependence:

@brunogama
brunogama / .swiftlint.auto.yml
Created June 28, 2020 12:22
Gist for .swiftlint.auto.yml
---
# Rules in this file will be automatically fixed. The script in Xcode must be
# changed to:
#
# if which swiftlint >/dev/null; then
# swiftlint autocorrect --config ".swiftlint.auto.yml" && swiftlint
# else
# echo "warning: SwiftLint not installed"
# echo "Download from https://github.com/realm/SwiftLint"
# fi
@brunogama
brunogama / RPScreenWriter.swift
Created March 31, 2020 17:10 — forked from mspvirajpatel/RPScreenWriter.swift
ScreenWriter With ReplayKit
import Foundation
import AVFoundation
import ReplayKit
class RPScreenWriter {
// Write video
var videoOutputURL: URL
var videoWriter: AVAssetWriter?
var videoInput: AVAssetWriterInput?
// Write audio