Skip to content

Instantly share code, notes, and snippets.

View djds23's full-sized avatar

Dean Silfen djds23

View GitHub Profile
@djds23
djds23 / gist:eeab5ba359b94a71dbb20f857fd04cfb
Created September 30, 2017 18:00 — forked from mobmad/gist:433ba54e9cb97d6d7771
Create self-signed certificate for wiremock and configure a java client under test for HTTPS

1. Generate self-signed certificate

keytool -genkey -alias wiremock -keyalg RSA -keysize 1024 \
    -validity 365 -keypass password -keystore identity.jks -storepass password

Important: keypass must equal storepass, or else you'll receive java.io.IOException: !JsseListener: java.security.UnrecoverableKeyException: Cannot recover key

2. Start wiremock with the new keystore and HTTPS enabled

@djds23
djds23 / des.swift
Created February 6, 2018 15:58
Swift - String to JSON example
jsonInStringFormat.data(using: String.Encoding.utf) // -> String -> Data, for use with JSONSerialization
@djds23
djds23 / LocalisedStrings.swift
Created February 28, 2018 00:30 — forked from douglashill/LocalisedStrings.swift
Generating an enum to ensure only defined localised string keys are used. For development on Apple platforms.
// Douglas Hill, February 2018
import Foundation
/// Returns a localised string with the key as an enum case so the compiler checks it exists.
/// The enum should be automatically generated using UpdateLocalisedStringKeys.swift.
public func localisedString(_ key: LocalisedStringKey) -> String {
return Bundle.main.localizedString(forKey: key.rawValue, value: nil, table: nil)
}
@djds23
djds23 / mov2gif
Created March 1, 2018 18:53
convert mov 2 gif
#/bin/bash
if [[ $2 -eq 0 ]]; then
ffmpeg -ss 00:00:00.000 -i $1 -pix_fmt rgb24 -r 10 output.gif
else
ffmpeg -ss 00:00:00.000 -i $1 -pix_fmt rgb24 -r 10 $2
fi
find . -name \*.swift | tr '\n' '\0' | xargs -0 SwiftGenStrings -o .
/*
`map` is a method on sequence that will iterate over a sequence
and apply a closure to each element of that sequence. It will then
return the new sequence with the closure applied.
Using `map` simplifies code that needs to transform lists of data
for example, it could be used here to simplify your code.
*/
@djds23
djds23 / compressMap-example.swift
Last active May 1, 2018 23:24
example how to use flatMap/compressMap with optionals
struct Dog {
let name: String
}
let possibleDogNames: [String?] = [
"barry",
"scooby",
"scrappy",
nil,
nil,
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
protocol GreetService {
func greeting() -> String
}
class Greeter: GreetService{
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
protocol GreetService {
func greeting() -> String
}
class Greeter: GreetService{
@djds23
djds23 / FollowUserViewModel.pt1.swift
Last active November 15, 2018 15:23
Let Me Check My Scheduler
final class FollowUserViewModel {
// Observer for our view to bind to when our user
  // wants to follow another user.
  let followUserObserver: AnyObserver<User> {
  return followSubject.asObserver()
  }
private let disposeBag = DisposeBag()
  // This subject will listen for users to follow.
  private let followSubject = PublishSubject<User>()
  init(user: User, networkHandler: FollowNetworkHandler) {