Skip to content

Instantly share code, notes, and snippets.

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

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
// I re-typed what I saw in reference 3 below,
// went to Liked videos page on YouTube[1] while logged in,
// pasted that into browser dev tools console (Google Chrome Version 97.0.4692.99 (Official Build) (x86_64)),
// pressed enter, and it seemed to do its thing, for the most part
// (when I refreshed the page, there was still 1 video remaining).
// [1] as of 2022-01-23 that’s at https://www.youtube.com/playlist?list=LL
// context: https://twitter.com/QiaochuYuan/status/1485164256970510340
// references:
@dimohamdy
dimohamdy / check-unused-codes.sh
Created July 23, 2023 13:13
List unused code using periphery
echo "🔍 Start dead code analysis"
result="$(periphery scan --config .periphery.yml)"
current_dir=$(pwd)
result_stripped_of_absolute_path_prefix=$(echo "$result" | sed "s|$current_dir/||g")
filtered_out_result=$(echo "$result_stripped_of_absolute_path_prefix" | awk '/:[0-9]+:[0-9]+:/{ print }')
sorted_result=$(echo "$filtered_out_result" | sort)
@dimohamdy
dimohamdy / Unused code 🗑️
Last active July 23, 2023 13:15
Script for Xcode build stage to list the unused code
#!/bin/bash
if ! command -v periphery &> /dev/null; then
echo "❌ Periphery is not installed. Please install periphery before running this script."
else
cd .. # change the current directory
check_unused_codes_script="${SRCROOT}/../check-unused-codes.sh"
sorted_result=$("$check_unused_codes_script")
@dimohamdy
dimohamdy / LintChangedFiles.sh
Created July 23, 2023 11:59
Lint changed files 🤖
# Run SwiftLint
#https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
START_DATE=$(date +"%s")
SWIFTLINT="${PODS_ROOT}/SwiftLint/swiftlint"
# Run SwiftLint for given filename
run_swiftlint() {
local filename="${SRCROOT}/../${1}"
if [[ "${filename##*.}" == "swift" ]]; then
@dimohamdy
dimohamdy / Appdelegate.swift
Last active May 17, 2022 01:31
Check internet Reachability iOS 12+
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Reachability.shared.startNetworkReachabilityObserver()
return true
}
@dimohamdy
dimohamdy / UITextViewPlaceholder.swift
Created March 29, 2021 14:53 — forked from tijme/UITextViewPlaceholder.swift
The correct way to implement a placeholder in a UITextView (Swift)
//
// UITextViewPlaceholder.swift
// TextViewPlaceholder
//
// Copyright (c) 2017 Tijme Gommers <tijme@finnwea.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dimohamdy
dimohamdy / swiftlint.sh
Created January 8, 2021 01:07
Swiftlint changes only
# Run SwiftLint
#https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
# Run SwiftLint for given filename
run_swiftlint() {
local filename="${1}"
if [[ "${filename##*.}" == "swift" ]]; then
@dimohamdy
dimohamdy / MigrateDefaults.swift
Created August 7, 2020 00:35 — forked from dougdiego/MigrateDefaults.swift
Migrate NSUserDefaults to App Groups - Swift
func migrateUserDefaultsToAppGroups() {
// User Defaults - Old
let userDefaults = NSUserDefaults.standardUserDefaults()
// App Groups Default - New
let groupDefaults = NSUserDefaults(suiteName: "group.myGroup")
// Key to track if we migrated
let didMigrateToAppGroups = "DidMigrateToAppGroups"
extension Date {
var timeAgo: String {
get {
let relativeDateFormatter = RelativeDateTimeFormatter()
//change these to get different formats
relativeDateFormatter.dateTimeStyle = .named
relativeDateFormatter.unitsStyle = .full
//you can know your loacal identifier here https://gist.github.com/jacobbubu/1836273
relativeDateFormatter.locale = Locale(identifier: "ar_EG")
let relativeDate = relativeDateFormatter.localizedString(for: self, relativeTo: Date())
import Foundation
extension Optional where Wrapped: Collection {
public var isNilOrEmpty: Bool {
switch self {
case .none:
return true
case .some(let collection):
return collection.isEmpty
}