Skip to content

Instantly share code, notes, and snippets.

View mikehouse's full-sized avatar

Mikhail Demidov mikehouse

  • Thailand
View GitHub Profile
@manniru
manniru / NukeSSLCerts.java
Last active January 6, 2024 07:32
Disable SSL Certificate on Android Volley for Testing only
public static class NukeSSLCerts {
protected static final String TAG = "NukeSSLCerts";
public static void nuke() {
try {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
X509Certificate[] myTrustedAnchors = new X509Certificate[0];
return myTrustedAnchors;
@mayoff
mayoff / !README.md
Last active August 14, 2023 15:09
Debugging Objective-C blocks in lldb

The attached lldb command pblock command lets you peek inside an Objective-C block. It tries to tell you where to find the source code for the block, and the values captured by the block when it was created.

Consider this example program:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

@implementation Foo

@Akhu
Akhu / InvertMask+Layer.swift
Created May 12, 2017 12:53
Simple way to invert a mask on a layer with swift / quartzcore / ios
func mask(withRect rect: CGRect, inverse: Bool = false) {
let path = UIBezierPath(rect: rect)
let maskLayer = CAShapeLayer()
if inverse {
path.appendPath(UIBezierPath(rect: self.bounds))
maskLayer.fillRule = kCAFillRuleEvenOdd
}
maskLayer.path = path.CGPath
@dduan
dduan / runCommand.swift
Last active May 5, 2024 12:55
How to fork()+execv() in Swift
import Foundation
func withCStrings(_ strings: [String], scoped: ([UnsafeMutablePointer<CChar>?]) throws -> Void) rethrows {
let cStrings = strings.map { strdup($0) }
try scoped(cStrings + [nil])
cStrings.forEach { free($0) }
}
enum RunCommandError: Error {
case WaitPIDError
@sjoerdvisscher
sjoerdvisscher / expression-problem.swift
Last active August 21, 2019 16:57
Finally tagless in Swift 3
protocol Expr {
static func lit(_ x: Int) -> Self
static func add(_ lhs: Self, _ rhs: Self) -> Self
}
extension Int : Expr {
static func lit(_ x : Int) -> Int {
return x;
}
static func add(_ lhs: Int, _ rhs: Int) -> Int {
@zacwest
zacwest / ios-font-sizes.swift
Last active July 17, 2024 21:39
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@jtbandes
jtbandes / decode-dyn-uti.swift
Last active May 21, 2024 02:42
Dynamic UTI decoding
/// Decodes a dynamically-generated Uniform Type Identifier for inspection purposes. (**NOT FOR PRODUCTION USE!**)
/// Many, many thanks to http://alastairs-place.net/blog/2012/06/06/utis-are-better-than-you-think-and-heres-why/
///
/// <https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html#//apple_ref/doc/uid/TP40001319-CH202-BCGCDHIJ>
func decodeDynUTI(_ uti: String) -> String?
{
let vec = Array("abcdefghkmnpqrstuvwxyz0123456789")
let encoded = Array(uti).suffix(from: 5)
var result: [UInt8] = []
@CodaFi
CodaFi / alltheflags.md
Last active June 2, 2024 17:09
Every Option and Flag /swift (1.2) Accepts Ever

#Every Single Option Under The Sun

  • optimization level options
  • automatic crashing options
  • debug info options
  • swift internal options
  • swift debug/development internal options
  • linker-specific options
  • mode options
@JaviLorbada
JaviLorbada / FRP iOS Learning resources.md
Last active June 17, 2024 06:08
The best FRP iOS resources.

Videos

@aprell
aprell / va_nargs.c
Last active March 9, 2024 08:44
Counting arguments in variadic macros
// RUN: cc -Wall -Wextra %s && ./a.out
#include <assert.h>
#if defined(__GNUC__) || defined(__clang__)
// Supports 0-10 arguments
#define VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
#define VA_NARGS(...) VA_NARGS_IMPL(_, ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#else