Skip to content

Instantly share code, notes, and snippets.

View calvingit's full-sized avatar
🎯
Focusing

Wen calvingit

🎯
Focusing
View GitHub Profile
@calvingit
calvingit / ThreadSafe.swift
Created November 4, 2023 11:36
iOS 自定义锁
@propertyWrapper
public final class ThreadSafe<T> {
// MARK: Lifecycle
public init(wrappedValue: T) {
self.value = wrappedValue
}
// MARK: Public
//
// UIViewController+Popover.swift
// HomeMate
//
// Created by zhangwen on 2023/6/29.
// Copyright © 2023 Legrand Intelligent Electrical (Huizhou) Co., Ltd. All rights reserved.
//
import UIKit
@calvingit
calvingit / EventPublisher.swift
Created November 4, 2023 11:34
广播事件分发器
import Foundation
// 事件
@objcMembers
class EPEvent: NSObject {
/// 事件 id,唯一
private(set) var id: String = ""
/// 对象参数
private(set) var object: Any?
@calvingit
calvingit / DependencyContainer.swift
Created November 4, 2023 11:34
依赖管理工具
//
// DependencyContainer.swift
// DependencyContainer
//
// Created by zhangwen on 2023/11/1.
//
import Foundation
@objc
class DependencyContainer: NSObject {
@calvingit
calvingit / .vimrc
Created August 7, 2021 03:05 — forked from simonista/.vimrc
A basic .vimrc file that will serve as a good template on which to build.
" Don't try to be vi compatible
set nocompatible
" Helps force plugins to load correctly when it is turned back on below
filetype off
" TODO: Load plugins here (pathogen or vundle)
" Turn on syntax highlighting
syntax on
@calvingit
calvingit / RxPermission.swift
Created December 15, 2017 03:24
RxSwift bindings for Permission API that helps you with Permissions in iOS.
//
// RxPermission.swift
//
// Copyright (c) 2016 Sunshinejr <[email protected]>
//
// 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
// copies of the Software, and to permit persons to whom the Software is
// iOS 11 之后的方法,来自: https: // www.appcoda.com/rounded-corners-uiview/
// layerMaxXMaxYCorner – lower right corner
// layerMaxXMinYCorner – top right corner
// layerMinXMaxYCorner – lower left corner
// layerMinXMinYCorner – top left corner
func roundCorners(cornerRadius: Double) {
self.layer.cornerRadius = CGFloat(cornerRadius)
self.clipsToBounds = true
@calvingit
calvingit / Remove-Framework-Unwanted-Archs.sh
Created November 22, 2016 07:35
第三方的framework一般都兼容模拟器和真机arch,但是上架时不能包含模拟器的arch,这个脚本的作用就是打包时移除无效的archs
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
if [ "${CONFIGURATION}" == "Release" ]; then
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
@calvingit
calvingit / google-translate.py
Created October 25, 2016 04:01
调用Google Translate API 翻译
# /usr/bin/env python
# -*- coding: utf-8 -*-
# 同级目录下面包含 Localizable.strings 或者 InfoPlist.strings,把strings文件的注释都去掉
# cnFile 参数修改需要翻译Localizable还是InfoPlist
# 到Google翻译API页面申请Key(https://cloud.google.com/translate/v2/quickstart),送300美刀,免费2个月
# 安装google-api-python-client (https://developers.google.com/api-client-library/python/apis/translate/v2)
# pip install --upgrade google-api-python-client
# 会自动生成对应的.lproj目录
# 注意: 葡萄牙语、繁体中文的语言缩写分别是pt和zh-TW,这个和Xcode的目录有点区别,其他语言都一样
@calvingit
calvingit / translation.py
Created October 19, 2016 08:10
iOS 调用百度翻译 API 将中文 strings 翻译成其他国家语言
# /usr/bin/env python
# -*- coding: utf-8 -*-
# 同级目录下面包含 Localizable.strings 或者 InfoPlist.strings,把strings文件的注释都去掉
# cnFile 参数修改需要翻译Localizable还是InfoPlist
# 到百度翻译API页面申请免费的appid和secretKey(http://api.fanyi.baidu.com/api/trans/product/index)
# 百度翻译每月翻译字符数低于200万,享免费服务
# 会自动生成对应的.lproj目录
import httplib