Skip to content

Instantly share code, notes, and snippets.

View pingzh's full-sized avatar

Ping Zhang pingzh

View GitHub Profile
A simple solution is to move view up with constant of keyboard height.
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}
## 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 / Badge.swift
Last active May 22, 2016 20:06 — forked from yonat/Badge.swift
Rounded UILabel and UIButton, Badged UIBarButtonItem Rounded UILabel and UIButton, Badged UIBarButtonItem Rounded UILabel and UIButton, Badged UIBarButtonItem
//
// Badge.swift
// Extensions for Rounded UILabel and UIButton, Badged UIBarButtonItem.
//
// Created by Yonat Sharon on 06.04.2015.
// Copyright (c) 2015 Yonat Sharon. All rights reserved.
//
import UIKit

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:

@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 / 0_reuse_code.js
Last active May 27, 2016 02:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: deal.value)
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 1, range: NSMakeRange(0, attributeString.length))
value.attributedText = attributeString
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)
@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
@pingzh
pingzh / rbenv-howto.md
Last active May 27, 2016 02:33 — forked from MicahElliott/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev