Skip to content

Instantly share code, notes, and snippets.

View pingzh's full-sized avatar

Ping Zhang pingzh

View GitHub Profile
@pingzh
pingzh / callback.rb
Last active May 24, 2016 01:49 — forked from EmmanuelOga/callback.rb
callback test.
require 'benchmark'
class Proc
def slow_callback(callable, *args)
self === Class.new do
method_name = callable.to_sym
define_method(method_name) { |&block| block.nil? ? true : block.call(*args) }
define_method("#{method_name}?") { true }
def method_missing(method_name, *args, &block) false; end
end.new
@pingzh
pingzh / gist:2694bd711ad24a0d51d0
Last active June 3, 2016 04:58 — forked from derrickshowers/gist:80fb450490ff03e6e274
Delegation Design Pattern Using Swift
import UIKit
protocol YelpRequestDelegate {
func getYelpData() -> AnyObject
func processYelpData(data: NSData) -> NSData
}
class YelpAPI {
var delegate: YelpRequestDelegate?
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: deal.value)
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 1, range: NSMakeRange(0, attributeString.length))
value.attributedText = attributeString

Public service announcement: never delete postmaster.pid. Really. Great way to get data corruption.

You already had PostgreSQL installed, and you deleted the data dir without stopping the running server. So you now have some orphan PostgreSQL server processes that are managing data files that've been deleted, so they're no longer accessible in the file system and will be fully deleted when the last open file handle to them is closed. You can't use pg_ctl to shut the server down like normal because you've deleted the cluster datadir, so you must simply kill the processes. Kill the postmaster (do not use kill -9, just an ordinary kill will do) and the rest will shut down too.

You will then be able to start a new server in the datadir against the freshly initdb'd data.

It is highly likely that you will experience conflicts down the track unless you uninstall the other older version of PostgreSQL.

In a nutshell:

private let _refreshControl: UIRefreshControl!
//in addSubviews
tableView.addSubview(refreshControl)
func refreshView() {
refreshControl.beginRefreshing()
tableView.reloadData()
//initData()
class MyAccountViewController: UIViewController {
private var _leftBarButtion: UIBarButtonItem!
private var _rightBarButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
addSubviews()
addLayout()
}
func addSubviews() {
var followingNumer: UIButton {
if _followingNumer == nil {
_followingNumer = UIButton()
_followingNumer.titleLabel?.lineBreakMode = .ByWordWrapping
_followingNumer.titleLabel?.textAlignment = .Left
_followingNumer.titleLabel?.font = TprofileButtonFont
_followingNumer.setTitleColor(TprofileButtonFontColor, forState: .Normal)
_followingNumer.setTitle("222\nFollowiing", forState: .Normal)
}
return _followingNumer
func onPanGesture(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(view)
let velocity = sender.velocityInView(view)
if sender.state == UIGestureRecognizerState.Began {
}
else if sender.state == UIGestureRecognizerState.Changed {
contentView.snp_updateConstraints(closure: { (make) -> Void in
make.left.equalTo(view).offset(translation.x)
## hexdiget to digest
hexdigest = Digest::MD5.hexdigest("ping")
digest = hexdigest.scan(/../).map(&:hex).pack("C*")
## digest to hexdigest
digest = Digest::MD5.digest('http://www.example.com')
hexdigest = digest.unpack('H*').first
@pingzh
pingzh / RBResizer.swift
Last active May 27, 2016 02:33 — forked from HamptonMakes/RBResizer.swift
Swift Image Resizer
//
// RBResizer.swift
// Locker
//
// Created by Hampton Catlin on 6/20/14.
// Copyright (c) 2014 rarebit. All rights reserved.
//
import UIKit