Skip to content

Instantly share code, notes, and snippets.

View NeverwinterMoon's full-sized avatar
💭
Hacking at SwiftUI

Pavel Sorokin NeverwinterMoon

💭
Hacking at SwiftUI
View GitHub Profile
import android.support.annotation.Nullable;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* https://github.com/square/retrofit/issues/1554#issuecomment-178633697
@NeverwinterMoon
NeverwinterMoon / gist:46ae017f26b8f2aa9ec0140b8112fa31
Created June 17, 2018 17:53 — forked from museofwater/gist:6373048
Android code snippet showing how to handle timeouts and server errors cleanly in a web view
public class AsyncMultiplayerSetupActivity extends Activity {
private static final String TAG = AsyncMultiplayerSetupActivity.class.getName();
public static final String UTF_8 = "UTF-8";
private WebView wvSignin;
private String url = "http://localhost:9000/signin";
private ProgressDialog progressLoadUrl;
private SigninWebViewClient webViewClient;
@NeverwinterMoon
NeverwinterMoon / json-post.swift
Created May 16, 2018 13:01 — forked from h2non/json-post.swift
JSON POST example with Alamofire
let parameters = [
"username": "foo",
"password": "123456"
]
Alamofire.request(.POST, "https://httpbin.org/post", parameters: parameters, encoding: .JSON)
// -> HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
@NeverwinterMoon
NeverwinterMoon / NibFileOwnerLoadable.swift
Created May 14, 2018 10:03 — forked from stefanofrosoni/NibFileOwnerLoadable.swift
NibFileOwnerLoadable Protocol in Swift
public protocol NibFileOwnerLoadable: class {
static var nib: UINib { get }
}
public extension NibFileOwnerLoadable where Self: UIView {
static var nib: UINib {
return UINib(nibName: String(describing: self), bundle: Bundle(for: self))
}
@NeverwinterMoon
NeverwinterMoon / string_to_data_back.swift
Created April 16, 2018 07:40 — forked from lzell/string_to_data_back.swift
Swift string to data (bytes) and back
// (string, swift, bytes, data, buffer, cstring)
print("--- using nulTerminated ---")
let x : String = "hello"
let buf = x.nulTerminatedUTF8
print(buf)
print("\n--- using [UInt8] ---")
let buf2 : [UInt8] = [UInt8](x.utf8)
print(buf2)
@NeverwinterMoon
NeverwinterMoon / Country.swift
Created March 27, 2018 11:38 — forked from kharrison/Country.swift
Swift Hash Functions
import Foundation
struct Country {
let name: String
let capital: String
var visited: Bool
}
extension Country: Equatable {
static func == (lhs: Country, rhs: Country) -> Bool {
@NeverwinterMoon
NeverwinterMoon / Realm+CascadeDeleting.swift
Created March 22, 2018 07:21 — forked from krodak/Realm+CascadeDeleting.swift
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@NeverwinterMoon
NeverwinterMoon / UIColorExtension.md
Created March 5, 2018 07:37 — forked from bhrott/UIColorExtension.md
Swift 3: Hex UIColor

Extension:

import Foundation
import UIKit

extension UIColor {
    convenience init(hexString: String) {
        let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
        var int = UInt32()
 Scanner(string: hex).scanHexInt32(&amp;int)