Skip to content

Instantly share code, notes, and snippets.

View pushkarnk's full-sized avatar

Pushkar N Kulkarni pushkarnk

  • Canonical | ex-IBM
  • India
View GitHub Profile
import Foundation
import Dispatch
public class DownloadTask : NSObject {
let location = URL(string: "file:///Users/puskulka/LICENSE.txt")!
internal func download(urlString: String) {
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let urlRequest = URLRequest(url: URL(string: urlString)!)
import Foundation
import Dispatch
public class DownloadTask : NSObject {
let location = URL(string: "file://<valid path>")!
Users
internal func download(urlString: String) {
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let url = URL(string: urlString)
@pushkarnk
pushkarnk / Auth-framework.md
Last active September 29, 2017 11:05
An authentication framework for the URL Loading System in Swift Corelibs Foundation

An Authentication framework for URLSession

The URL Loading System (URLSession and friends) in swift-corelibs-foundation needs authentication support. The following is a design proposal to plug an authentication in the existing URLSession architecture. The design may or may not bear resemblance to the authentication on Foundation or Darwin. The sole goal is to make sure that behaviour on Linux completely matches that on Darwin.

Background

A URL loading system without authentication support is of meagre value in these times of "secure engineering". Though we've been fairly successful with incremental improvements in URLSession, it does need a few significant augmentations. Authentication support is one of them. In my experience on URLSession use cases on Linux, I have come across a very limited number of scenarios using Basic HTTP authentication with a fixe

@pushkarnk
pushkarnk / Auth.swift
Last active September 25, 2017 08:55
import Foundation
import Dispatch
class AuthenticationTest: NSObject {
var session: URLSession!
var task: URLSessionTask!
public func run() {
session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
task = session.dataTask(with: URL(string: "http://httpbin.org/basic-auth/user/passwd")!)
@pushkarnk
pushkarnk / SettingUp.md
Created September 16, 2017 09:37
Regularizing your Neural Network

Techiniques for reducing overfitting in Neural Network

Increase data

  1. By flipping each of the images in the training set, you can double the number of examples
  2. Take random transformations/distortions of the image to increase the number of examples These are ways to increase the amount of data, which has an effect similar to regularization.

Early Stopiing

import Foundation
import Dispatch
class ProxyURLProtocol: URLProtocol {
static var session: URLSession!
struct PropertyKeys {
static let handledByForwarderURLProtocol = "HandledByProxyURLProtocol"
}
import Foundation
import Dispatch
class ProxyURLProtocol: URLProtocol {
var session: URLSession!
struct PropertyKeys {
static let handledByForwarderURLProtocol = "HandledByProxyURLProtocol"
}
import Foundation
struct Access {
static let `open` = "source.lang.swift.accessibility.open"
static let `public` = "source.lang.swift.accessibility.public"
}
struct SubStructure : Decodable {
let name: String?
let kind: String?

Restructuring URLSession

This document discusses the current design of URLSession in swift-corelibs-foundation, identifies drawbacks and proposes a new design.

Authors: Pushkar N Kulkarni, Nethra Ravindran

1. Background

The currently available open source implementation of URLSession in swift-corelibs-foundation supports only HTTP/HTTPS. It is tightly coupled with the two protocols. This makes it difficult to plug in implementations of the other common protocols natively supported by URLSession - ftp, file, data. Also, plugging in support for custom protocols, defined through the URLProtocol/URLProtocolClient API, and configured with URLSession using theURLSessionCongfiguration.protocolClasses property, may need some undesirable patchwork with the current design of URLSession. This document first describes the pain-points/drawbacks of the current design and subsequently proposes a new framework for URLSession, which is based on URLProtocol.

....
libdispatch: about to invoke handler for dispatch source 0x7f44781bf0a0
calling the handler we installed, now performing action on the socket
libdispatch: epoll_ctl called on fd 14 with data 0x7f4468000b70 and operation EPOLL_CTL_MOD
libdispatch: epoll_wait returned with ready EVFILT_READ on fd 14 with data 0x7f4468000b70
libdispatch: about to invoke handler for dispatch source 0x7f44781bf0a0
calling the handler we installed, now performing action on the socket
libdispatch: epoll_ctl called on fd 14 with data 0x7f4468000b70 and operation EPOLL_CTL_MOD
libdispatch: epoll_wait returned with ready EVFILT_READ on fd 14 with data 0x7f4468000b70
libdispatch: about to invoke handler for dispatch source 0x7f44781bf0a0