Skip to content

Instantly share code, notes, and snippets.

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

Ashu Ashu

🏠
Working from home
View GitHub Profile
@Jonalogy
Jonalogy / handling_multiple_github_accounts.md
Last active April 29, 2024 13:49
Handling Multiple Github Accounts on MacOS

Handling Multiple Github Accounts on MacOS

The only way I've succeeded so far is to employ SSH.

Assuming you are new to this like me, first I'd like to share with you that your Mac has a SSH config file in a .ssh directory. The config file is where you draw relations of your SSH keys to each GitHub (or Bitbucket) account, and all your SSH keys generated are saved into .ssh directory by default. You can navigate to it by running cd ~/.ssh within your terminal, open the config file with any editor, and it should look something like this:

Host *
 AddKeysToAgent yes

> UseKeyChain yes

@candostdagdeviren
candostdagdeviren / Dangerfile
Last active February 1, 2023 10:40
Sample Dangerfile for iOS Project
# PR is a work in progress and shouldn't be merged yet
warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]"
# Warn when there is a big PR
warn "Big PR, consider splitting into smaller" if git.lines_of_code > 500
# Ensure a clean commits history
if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ }
fail "Please rebase to get rid of the merge commits in this PR"
end
@candostdagdeviren
candostdagdeviren / .swiftlint.yml
Last active April 27, 2024 08:48
Sample SwiftLint file to apply best practices
disabled_rules: # rule identifiers to exclude from running
- variable_name
- nesting
- function_parameter_count
opt_in_rules: # some rules are only opt-in
- control_statement
- empty_count
- trailing_newline
- colon
- comma
@cotkjaer
cotkjaer / CGRect+Center.swift
Last active November 23, 2023 06:15
Swift extensions to add "center" to CGRect
extension CGRect
{
/** Creates a rectangle with the given center and dimensions
- parameter center: The center of the new rectangle
- parameter size: The dimensions of the new rectangle
*/
init(center: CGPoint, size: CGSize)
{
self.init(x: center.x - size.width / 2, y: center.y - size.height / 2, width: size.width, height: size.height)
@laurilehmijoki
laurilehmijoki / keyboardHeightObservable.swift
Last active November 15, 2022 13:00
RxSwift Observable on iOS keyboard height
import RxSwift // Version 3.2.0
import RxCocoa // Version 3.2.0
func keyboardHeight() -> Observable<CGFloat> {
return Observable
.from([
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow)
.map { notification -> CGFloat in
(notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
},
//reference types
class someClass {
var name: String
init(name: String) {
self.name = name
}
}
var aClass = someClass(name: "James")
var bClass = aClass
@artemnovichkov
artemnovichkov / UITableView+Dequeue.swift
Created December 9, 2016 08:21
UItableView dequeueing with Swift magic
import UIKit
extension UITableView {
func dequeueReusableCell<T: UITableViewCell>() -> T {
return dequeueReusableCell(withIdentifier: NSStringFromClass(T.self)) as! T
}
}
//using: let cell: ExampleTableViewCell = tableView.dequeueReusableCell()
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
import UIKit
// Swift rewrite challenge
// Starting point: https://gist.github.com/jkereako/200342b66b5416fd715a#file-scale-and-crop-image-swift
func scaleAndCropImage(
image: UIImage,
toSize size: CGSize,
fitImage: Bool = true
) -> UIImage {
@Nanomancer
Nanomancer / transmission.rb
Last active December 1, 2019 13:17
Sonic Pi code (Ruby) for piece entitled 'Transmission' based around MIDI note tuned resonators
## Transmission - Origin Unknown -Tuned Resonators in C minor
## Random Seed Version: 746742
## Coded by Nanomancer - Distributed under Creative Commons Non-Commercial Attribution license - :)
## 26.03.2016
## Watch a video produced with screen grabs of the code and Nebulae:
## https://www.youtube.com/watch?v=5fwGHAdoaXA&feature=youtu.be
#######################
max_t = 8 # Adjust the run time of the piece