Skip to content

Instantly share code, notes, and snippets.

@yanli0303
yanli0303 / crash-swift-compiler.swift
Last active May 31, 2017 14:58
Crash Swift compiler by defining a local variable with same name as class property
import Foundation
class Foo {
var bar: Int? = 1
}
enum BarEnum: Int {
@yanli0303
yanli0303 / HTML-string-to-NSAttributedString.swift
Last active June 1, 2017 15:26
Swift: Convert HTML string to NSAttributedString
// method 1
extension NSAttributedString {
static func from(html: String) throws -> NSAttributedString {
guard let data = html.data(using: String.Encoding.unicode, allowLossyConversion: true) {
throws ArgumentError.invalidArgument("Invalid `html` string, failed to convert it to `Data`.")
}
return try NSAttributedString(
data: data,
@yanli0303
yanli0303 / NSWindowController-close-does-not-stopModal-or-endSheet.swift
Created June 20, 2017 15:14
NSWindowController.close() does not stopModal or endSheet
import Cocoa
class FooWC: NSWindowController {
}
extension FooWC: NSWindowDelegate {
func windowWillClose(_ notification: Notification) {
guard let win = notification.object as? NSWindow else {
import sys
import os
import re
import json
def _parse_strings_file_path():
if len(sys.argv) < 2:
return
@yanli0303
yanli0303 / static-analysis-test-report.jelly
Created January 12, 2018 22:17
Jenkins HTML email template based on static-analysis.jelly
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:g="glide">
<html>
<head>
<title>${project.name}</title>
<style>
body table, td, th, p, h1, h2 {
margin: 0;
font: normal normal 100% Georgia, Serif;
background-color: #ffffff;
@yanli0303
yanli0303 / static-analysis-test-report2.jelly
Created January 12, 2018 22:25
Jenkins HTML email template for testing result
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<html>
<head>
<title>${project.name}</title>
<style>
body table, td, th, p, h1, h2 {
margin:0;
font:normal normal
100% Georgia, Serif;
@yanli0303
yanli0303 / swift-extension-default-implementation.swift
Last active July 25, 2018 15:51
Swift 4 extension default implementation vs. inheritance
import Cocoa
// see https://team.goodeggs.com/overriding-swift-protocol-extension-default-implementations-d005a4428bda
protocol ToString {
func toString() -> String
}
extension ToString {
@yanli0303
yanli0303 / HttpStatusEnum.strings
Last active July 27, 2018 19:35
HTTP Status Swift Enumeration based on https://httpstatuses.com/
/// HTTP Status
"http_status_100" = "Continue";
"http_status_101" = "Switching Protocols";
"http_status_102" = "Processing";
"http_status_200" = "OK";
"http_status_201" = "Created";
"http_status_202" = "Accepted";
"http_status_203" = "Non-authoritative Information";
"http_status_204" = "No Content";
"http_status_205" = "Reset Content";
@yanli0303
yanli0303 / xcode-9-edit-in-scope.md
Created August 24, 2018 20:30
Xcode 9.4.1 edit in scope (rename a local variable)
  1. Set cursor to the variable name.
  2. Press and hold "SHIFT" key until all occurrences of the variable are highlighted.
  3. CMD + CTRL + E and start edit in scope.
@yanli0303
yanli0303 / xcode-9-edit-in-scope.md
Created August 24, 2018 20:30
Xcode 9.4.1 edit in scope (rename a local variable)
  1. Set cursor to the variable name.
  2. Press and hold "SHIFT" key until all occurrences of the variable are highlighted.
  3. CMD + CTRL + E and start edit in scope.