Skip to content

Instantly share code, notes, and snippets.

View pingzh's full-sized avatar

Ping Zhang pingzh

View GitHub Profile
@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?
@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 / 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
require "csv"
## Link: http://technicalpickles.com/posts/parsing-csv-with-ruby/
CSV.read("email_verified_at_backfill_data.csv", headers:true, header_converters: :symbol).collect do |row|
Hash[row.collect { |activation_code, date| [activation_code, date] }]
end
=begin
@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
@pingzh
pingzh / jsbin.dibug.css
Last active June 3, 2016 05:00 — forked from xypaul/jsbin.dibug.css
Fill container TinyMCE
html,body {
height: 100%;
background: blue;
}
.fill-div {
height: 100%;
width: 100%
}
@pingzh
pingzh / ng-really.js
Last active June 3, 2016 05:01 — forked from asafge/ng-really.js
ng-really? An AngularJS directive that creates a confirmation dialog for an action.
/**
* A generic confirmation for risky actions.
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function
*/
angular.module('app').directive('ngReallyClick', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
var message = attrs.ngReallyMessage;
@pingzh
pingzh / chrome.md
Last active June 3, 2016 05:00 — forked from 0xjjpa/chrome.md
Understanding Google Chrome Extensions

#Introduction

Developing Chrome Extensions is REALLY fun if you are a Front End engineer. If you, however, struggle with visualizing the architecture of an application, then developing a Chrome Extension is going to bite your butt multiple times due the amount of excessive components the extension works with. Here are some pointers in how to start, what problems I encounter and how to avoid them.

Note: I'm not covering chrome package apps, which although similar, work in a different way. I also won't cover the page options api neither the new brand event pages. What I explain covers most basic chrome applications and should be enough to get you started.

Table of Contents

  1. Understand the Chrome Architecture
  2. Understand the Tabs-Extension Relationship
  3. Picking the right interface for the job
shell -$SHELL
hardstatus alwayslastline '%{= kg}[ %{G}%H %{g}][%= %{= kB}%?%-Lw%?%{+b r}(%{G}%n*%f %t%?(%u)%?%{r})%{-b B}%?%+Lw%?%?%= %{g}%]'
@pingzh
pingzh / js-crypto-libraries.md
Last active July 17, 2017 23:56 — forked from jo/js-crypto-libraries.md
List of JavaScript Crypto libraries.

JavaScript Crypto Libraries

I start with a list and plan to create a comparison table.

WebCryptoAPI

http://www.w3.org/TR/WebCryptoAPI/

This specification describes a JavaScript API for performing basic cryptographic operations in web applications, such as hashing, signature generation and verification, and encryption and decryption. Additionally, it describes an API for applications to generate and/or manage the keying material necessary to perform these operations. Uses for this API range from user or service authentication, document or code signing, and the confidentiality and integrity of communications.