Skip to content

Instantly share code, notes, and snippets.

View YK-Unit's full-sized avatar
🐬
swimming in computing-ocean

YorkFish YK-Unit

🐬
swimming in computing-ocean
View GitHub Profile
@Leehro
Leehro / semaphore.m
Created October 30, 2013 19:18
I love this. Use a dispatch_semaphore_t to limit how many blocks you dispatch to a queue.
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
// Then in some loop ...
if(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0) {
dispatch_async(queue, ^{
// Some code that needs to run but doesn't need to fill up the queue.
//
dispatch_semaphore_signal(semaphore);
});
@fcanas
fcanas / Distance.swift
Created May 21, 2015 15:11
Creating a Numeric Type : Distance
public struct Distance :NumericType {
public var value :Double
public init(_ value: Double) {
self.value = value
}
}
extension Distance :IntegerLiteralConvertible {
public init(integerLiteral: IntegerLiteralType) {
self.init(Double(integerLiteral))
@efremidze
efremidze / Example.swift
Last active October 30, 2017 08:21 — forked from gavrix/Example.swift
protocol LoginProvider {
func login()
}
class EmailLoginProvider: LoginProvider {
var email: String
var password: String
init(email: String, password: String) {
self.email = email
self.password = password
@iamamused
iamamused / LoadImage.h
Created March 2, 2012 03:23
Create iOS image resources from a PDF on the fly.
//
// LoadImage.h
// AssetsFromPDF
//
// Created by Jeffrey Sambells on 2012-03-02.
//
#import <Foundation/Foundation.h>
@interface LoadImage : NSObject
@Pranit-Harekar
Pranit-Harekar / WKWebViews+keyboardRequiresUserInteraction.swift
Last active February 1, 2019 01:27
Add keyboardRequiresUserInteraction to WKWebViews iOS 11.3
import Foundation
import WebKit
typealias ClosureType = @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void
extension WKWebView{
var keyboardDisplayRequiresUserAction: Bool? {
get {
return self.keyboardDisplayRequiresUserAction
}
@jordiboehme
jordiboehme / gist:3168819
Created July 24, 2012 08:25
iOS Pixel-to-Points conversion
+(CGFloat)pixelToPoints:(CGFloat)px {
CGFloat pointsPerInch = 72.0; // see: http://en.wikipedia.org/wiki/Point%5Fsize#Current%5FDTP%5Fpoint%5Fsystem
CGFloat scale = 1; // We dont't use [[UIScreen mainScreen] scale] as we don't want the native pixel, we want pixels for UIFont - it does the retina scaling for us
float pixelPerInch; // aka dpi
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
pixelPerInch = 132 * scale;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
pixelPerInch = 163 * scale;
} else {
pixelPerInch = 160 * scale;
@atsepkov
atsepkov / universal-framework.sh
Last active February 18, 2021 06:26 — forked from cromandini/universal-framework.sh
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures). This version works with Cocoapods, merging simulator and device architectures for intermediate libraries as well. To use this script, go to Product > Scheme > Edit S…
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@chrismay
chrismay / pre-commit
Created March 14, 2011 16:10
git pre-commit hook to syntax-check files
git diff --cached --name-status | while read st file; do
# skip deleted files
if [ "$st" == 'D' ]; then continue; fi
# do a check only on the puppet files
if [[ "$file" =~ ".pp" ]]·
then
echo "syntax checking \"$file\""·
if ! puppet --confdir=/tmp --vardir=/tmp --parseonly --ignoreimport "$file"
then
echo "puppet syntax check failed for file: $file"
@yesmeck
yesmeck / git-flow.md
Created December 9, 2012 14:53
Git 开发流程

Git 协作流程

master 分支

master 永远处于稳定状态,这个分支代码可以随时用来部署。不允许在该分支直接提交代码。

develop 分支

开发分支,包含了项目最新的功能和代码,所有开发都在 develop 上进行。一般情况下小的修改直接在这个分支上提交代码。

@daltonclaybrook
daltonclaybrook / cocoapods-bundle-id
Last active January 21, 2022 22:36
A post install script for CocoaPods that changes the bundle identifier of all pods to the one specified.
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == 'BREnterprise'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution: The Carter Group LLC'
config.build_settings['PROVISIONING_PROFILE'] = '${BR_ENTERPRISE_PROVISIONING_PROFILE}'
end
end
end