Skip to content

Instantly share code, notes, and snippets.

View MihailPreis's full-sized avatar
:octocat:
Say no more

Mihail Preis MihailPreis

:octocat:
Say no more
View GitHub Profile
@MihailPreis
MihailPreis / Storage.swift
Created November 6, 2023 08:17
UserDefault+AppStorage extensions
import Foundation
public struct AppStorageKeys {
public var userOnboarding: AppStorageKey<Bool> { .init("user_onboarding", defaultValue: false) }
public var updateFrequencyTimeInterval: AppStorageKey<Double> { .init("update_frequency_time_interval", defaultValue: 1.0) }
}
public struct AppStorageKey<Value> {
let name: String
let defaultValue: Value
@MihailPreis
MihailPreis / iTerm.md
Created November 4, 2022 07:30
Convenient terminal setup for mac

iTerm + OMZ + Plugins

  1. Install Brew:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install iTerm2 with Brew:

    brew install --cask iterm2
@MihailPreis
MihailPreis / device_switch.sh
Created November 4, 2022 07:04
Script for unpair/pair selected bluetooth devices
#!/bin/bash
#
# This script unpair selected device if is paired and vice versa
# for example, to quickly switch mouse and keyboard between macs
# Install `blueutil` with Brew before use this script!
# For get device ID run `blueutil --paired` and get "address" (as is)
# P.S. This script will be more convenient with Automator...
# for Homebrew on M1
export PATH="$PATH:/opt/homebrew/bin"
@MihailPreis
MihailPreis / Dockerfile
Created September 21, 2021 15:13
Build rust app for Ubuntu 16.04
FROM ubuntu:16.04
WORKDIR /app
RUN apt update
RUN apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
curl
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
@MihailPreis
MihailPreis / Array+diff.swift
Created August 27, 2021 12:29
Swift extension of Array for getting difference from two arrays.
extension Array where Element: Hashable {
/// Result entity for `diff(with:)`
typealias DiffResult = (old: [Element], changed: [Element], new: [Element])
/**
Return difference between two arrays.
- Parameter newArray: New array.
- Returns: DiffResult entity with:
@MihailPreis
MihailPreis / example.html
Created June 28, 2021 19:24
Ghost random Telegram post
<div id="tg-post"></div>
<script>
let GROUP_NAME = ""
let MIN_POST_ID = 3
let MAX_POST_ID = 100
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
let post_id = randomIntFromInterval(MIN_POST_ID, MAX_POST_ID);
@MihailPreis
MihailPreis / Keycodes.swift
Created April 22, 2021 12:49 — forked from swillits/Keycodes.swift
Swift Keyboard Keycodes
struct Keycode {
// Layout-independent Keys
// eg.These key codes are always the same key on all layouts.
static let returnKey : UInt16 = 0x24
static let enter : UInt16 = 0x4C
static let tab : UInt16 = 0x30
static let space : UInt16 = 0x31
static let delete : UInt16 = 0x33
static let escape : UInt16 = 0x35
@MihailPreis
MihailPreis / archive_post_action.sh
Created March 19, 2021 08:56
Script for build framework device/simulator sdk for Xcode (create script in post-action for Archive)
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-Universal
# Make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
BUILD_PRODUCTS="${SYMROOT}/../../../../Products"
@MihailPreis
MihailPreis / open_xcode_alias.sh
Created December 21, 2020 09:22
Add this in your *rc file
open_in_xcode() {
xfile=$1
if [[ -d "$xfile" && ${xfile: -12} == ".xcworkspace" ]]; then
open -a Xcode.app "$xfile"
elif [[ -d "$xfile" && ${xfile: -12} == ".xcodeproj" ]]; then
open -a Xcode.app "$xfile"
else
echo "Find project file in current dir."
project_files=(
$(find . -type d -depth 1 -name "*.xcworkspace")
@MihailPreis
MihailPreis / tg_alert.sh
Last active October 14, 2022 21:48
Telegram alert sh
#!/bin/bash
# Example: echo "Hello" | tg_alert.sh
# For find out the chat ID, use https://api.telegram.org/bot<token>/getUpdates
#
message=$1
apiToken="<TG_BOT_API_KEY>"
chatId="<TG_CHAT_ID>"
if [[ ! -z "$message" ]]; then