Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

DEFAULT_PROXY=http://proxy:8083
PROXY_SERVER=proxy.domain.com
PROXY_PORT=8080
SERVICE_NAME=Wi-Fi
if [[ $1 == "default" ]]; then
sudo networksetup -setautoproxystate $SERVICE_NAME on
sudo networksetup -setproxyautodiscovery $SERVICE_NAME on
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},

Swift Don'ts

  • Don't add code cruft. Avoid parentheses around conditions in if-statements or with the return keyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line.
  • Don't use ALL_CAPS; use camelCase
  • Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
  • Don't use var when let is appropriate, especially for properties. The compiler better optimizes let statements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create."
  • Don't use classes when structs will do. Use class
// Helper function to convert from RGB to UIColor
// UIColorFromRGB(0x22B573)
func UIColorFromRGB(rgbValue: UInt) -> UIColor {
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
@zhjuncai
zhjuncai / JSONTest.js
Last active October 17, 2017 10:48
SAPUI5 JSONModel Test case example
test("test JSONModel destroy", function(){
var testModel = new sap.ui.model.json.JSONModel();
testModel.attachRequestCompleted(function() {
ok(false, "Request should be aborted!");
});
testModel.attachRequestFailed(function() {
ok(false, "Error handler should not be called when request is aborted via destroy!");
});
var spy = this.spy(jQuery, "ajax");
testModel.loadData("testdata.json");
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
//
// ISO3661-2alpha2.swift
// ISO3661-2-alpha2
//
// Created by Bernd Rabe on 01.04.15.
// Copyright (c) 2015 Bernd Rabe. All rights reserved.
//
import UIKit
import Foundation
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
struct Notification<A> {
let name: String
}
// Playground - noun: a place where people can play
import Foundation
import UIKit
//~~~~~~~~~~~~~~~~ Error handling with enum Result<A> ~~~~~~~
enum Result<A> {
case Error(NSError)
case Value(Box<A>)
import Foundation
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
struct Notification<A> {
let name: String
}