Skip to content

Instantly share code, notes, and snippets.

@zhjuncai
zhjuncai / OSX UTC Time Zone
Created Nov 14, 2019 — forked from nick-desteffen/OSX UTC Time Zone
Set Time zone in OSX to UTC
View OSX UTC Time Zone
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
@zhjuncai
zhjuncai / Jenkinsfile
Created Nov 8, 2019 — forked from merikan/Jenkinsfile
Some Jenkinsfile examples
View Jenkinsfile
Some Jenkinsfile examples
@zhjuncai
zhjuncai / schema.sql
Created Apr 29, 2018 — forked from fernandomantoan/schema.sql
Schema for PostgreSQL to use with JdbcTokenStore (Spring Security OAuth2)
View schema.sql
create table oauth_client_details (
client_id VARCHAR(256) PRIMARY KEY,
resource_ids VARCHAR(256),
client_secret VARCHAR(256),
scope VARCHAR(256),
authorized_grant_types VARCHAR(256),
web_server_redirect_uri VARCHAR(256),
authorities VARCHAR(256),
access_token_validity INTEGER,
refresh_token_validity INTEGER,
@zhjuncai
zhjuncai / HTTPStatusCode.swift
Created Feb 6, 2017 — forked from ollieatkinson/HTTPStatusCode.swift
HTTP status codes as a Swift enum.
View HTTPStatusCode.swift
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
View rex.swift
import Foundation
// Extend String to support regex searching by conforming
// to CustomStringConvertible
extension String: CustomStringConvertible {
public var description: String {return self}
}
// Regex support for keys
public extension Dictionary where Key: CustomStringConvertible {
View example1.swift
import UIKit
import XCPlayground
class ViewController: UIViewController {
func action() { print("Bing!") }
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .whiteColor()
@zhjuncai
zhjuncai / css-supports.js
Created Jan 14, 2016 — forked from codler/css-supports.js
CSS.supports() Polyfill
View css-supports.js
/*! CSS.supports() Polyfill
* https://gist.github.com/codler/03a0995195aa2859465f
* Copyright (c) 2014 Han Lin Yap http://yap.nu; MIT license */
if (!('CSS' in window)) {
window.CSS = {};
}
if (!('supports' in window.CSS)) {
window.CSS._cacheSupports = {};
window.CSS.supports = function(propertyName, value) {
@zhjuncai
zhjuncai / StringSize.swift
Last active Sep 20, 2015 — forked from plumhead/StringSize.swift
String extension to find the layout size of a String with specified attributes.
View StringSize.swift
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
View networkswitcher.sh
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
View Function.bind.polyfill.js
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 () {},
You can’t perform that action at this time.