Skip to content

Instantly share code, notes, and snippets.

View pingzh's full-sized avatar

Ping Zhang pingzh

View GitHub Profile
@pingzh
pingzh / gist:6f7e86861abd611a5d8b42e031bc93f9
Created January 7, 2022 07:12 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@pingzh
pingzh / headless.md
Created November 20, 2017 01:49 — forked from addyosmani/headless.md
So, you want to run Chrome headless.

Update May 2017

Eric Bidelman has documented some of the common workflows possible with headless Chrome over in https://developers.google.com/web/updates/2017/04/headless-chrome.

Update

If you're looking at this in 2016 and beyond, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

Windows and Mac users might find using Justin Ribeiro's Docker setup useful here while full support for these platforms is being worked out.

@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.

@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
@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 / 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 / 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 / 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
@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?