Skip to content

Instantly share code, notes, and snippets.

View freak4pc's full-sized avatar
🤓

Shai Mishali freak4pc

🤓
View GitHub Profile
@delebedev
delebedev / gist:7265957
Created November 1, 2013 14:09
Bind RAC to AFNetworking
- (RACSignal *)enqueueRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters cacheTime:(NSTimeInterval)expirationTime {
NSAssert(self.cluster, @"cluster should be set before request.");
NSAssert(self.applicationID.length != 0, @"applicationID should be set before request.");
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:parameters];
RACSignal *signal = [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
AFHTTPRequestOperation *operation;
operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *op, id JSON) {
NSDictionary *errorDictionary = JSON[@"error"];
@alskipp
alskipp / encrypt_xor1.swift
Last active November 1, 2018 11:10
Swift encrypt/decrypt string using XOR
import Foundation
extension Character {
func utf8() -> UInt8 {
let utf8 = String(self).utf8
return utf8[utf8.startIndex]
}
}
func encrypt(c:Character, key:Character) -> String {
Hello,
I'd like to request the following information, in accordance with the information rights in the GDPR, and particularly Article 15. Please address all points in this email in turn.
1. A copy of all my personal data held and/or undergoing processing, in a commonly used electronic form (Article 15(3)). Please note that this might also include any audiovisual material (e.g. voice-recordings or pictures) and is not necessarily limited to the information contained in your customer database and/or the information you make available through the ‘manage my profile’ functionality. For all data that would fall under Article 20 (portability), I would like to recieve this in a commonly-used machine readable format. For data that does not fall under Article 20, such as data inferred about me or opinions about me, I would like this in a commonly-used electronic format.
2. If any data was not collected, observed or inferred from me directly, precise information about the source of that data, including the name and c
@dduan
dduan / SpeakBubble.swift
Last active June 20, 2020 13:56
Twitter's voice tweet UI has an interesting animation on iOS. This is an attempt to recreate that animation with SwiftUI. Looks like this https://youtu.be/I6XZzIgWYAQ
import SwiftUI
struct ChaoticPhoto: View {
let image: Image
let radius: CGFloat
@Binding var activated: Bool
@State var scale: CGFloat = 1
var body: some View {
image
.resizable()
@danielt1263
danielt1263 / Store.swift
Last active November 9, 2020 18:02
A stripped down version of The Elm Architecture for Swift. Great for implementing state machines.
//
// Store.swift
//
// Created by Daniel Tartaglia on 3/11/17.
// Copyright © 2020 Daniel Tartaglia. MIT License
//
import Foundation
import RxSwift
@IanKeen
IanKeen / Usage.swift
Created July 24, 2020 18:47
SwiftUI: Show a sheet based on an optionals unwrapped value
@main
struct MyApp: App {
enum Sheet { case first, second }
@State var sheet: Sheet? = nil
var body: some Scene {
WindowGroup {
VStack {
Button("First") { sheet = .first }
@noahsark769
noahsark769 / LoginViewController.swift
Created December 29, 2020 20:03
Copying WKWebView cookies into HTTPCookieStorage
extension LoginViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if let url = webView.url, url.absoluteString.contains("/index.action") {
let store = WKWebsiteDataStore.default().httpCookieStore
store.getAllCookies { cookies in
if let sessionIdCookie = cookies.first(where: { cookie in
cookie.name == "JSESSIONID"
}) {
HTTPCookieStorage.shared.setCookies(cookies, for: webView.url, mainDocumentURL: nil)
self.callback(ConfluenceSessionCookie(jSessonId: sessionIdCookie))
@IanKeen
IanKeen / Decodable+Random.swift
Last active March 29, 2022 13:06
Custom Decoder that can be used to create Decodable instances that are populated with random values
import Foundation
extension Decodable {
public static func randomInstance() throws -> Self {
let decoder = RandomDecoder()
return try Self(from: decoder)
}
}
private class RandomDecoder: Decoder {
//
// PaginationNetworkLogic.swift
//
// Created by Daniel Tartaglia on 4/9/17.
// Copyright © 2019 Daniel Tartaglia. MIT License
//
import RxSwift
struct PaginationUISource {
@warpling
warpling / CAMediaTimingFunction.swift
Last active June 14, 2022 11:15
Better CAMediaTimingFunctions
//
// CAMediaTimingFunction.swift
import UIKit
extension CAMediaTimingFunction {
static let linear = CAMediaTimingFunction(name: .linear)
static let easeOut = CAMediaTimingFunction(name: .easeOut)