Skip to content

Instantly share code, notes, and snippets.

@ChuntaoLu
ChuntaoLu / fixture_abstraction.md
Last active June 24, 2021 06:01
Mock Client Fixture Abstraction

This doc proposes an abstraction to set fixture expectations for mock clients during a test run.

Overview

The goal is to treat fixtures management as first class citizen and maintain clean fixture semantics. Fixtures that belong to a specific client should reside in a centralized place associated with that client. It should be recognized that the mock client and its affinitivie fixtures together can become one functional unit. With this realization, the action of setting input/output expectations for a mock client method becomes implementation details and can be abstracted away by defining a method with the same expectation semantic on the combined functional unit. For example, instead of writing

import store "import/path/to/store/fixture"

// ad-hoc fixtures
userHeader := map[string]string{
	"x-client-version": "1.1.2",
@ChuntaoLu
ChuntaoLu / git-gpg.md
Created April 7, 2017 08:44 — forked from bcomnes/git-gpg.md
my version of gpg on the mac
  1. brew install gnupg21, pinentry-mac (this includes gpg-agent and pinentry)

  2. Generate a key: $ gpg2 --gen-key

  3. Take the defaults. Whatevs

  4. Tell gpg-agent to use pinentry-mac:

    $ vim ~/.gnupg/gpg-agent.conf 
    
@ChuntaoLu
ChuntaoLu / http_streaming.md
Created July 7, 2016 03:13 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@ChuntaoLu
ChuntaoLu / batch_embed_pdf.py
Created May 19, 2015 21:46
Batch embed and subset pdf files in a directory
import os
import subprocess
import glob
# the shell command that embeds and subsets fonts in a pdf file
cmd = "gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile={} -f {}"
for file_path in glob.glob(os.path.join('unembedded_dir_path', '*.pdf')):
target_path = os.path.join('embedded_dir_path', os.path.basename(file_path))
@ChuntaoLu
ChuntaoLu / .pryrc
Created August 29, 2014 00:59 — forked from justin808/.pryrc
## Useful Collections
def a_array
(1..6).to_a
end
def a_hash
{hello: "world", free: "of charge"}
end
@ChuntaoLu
ChuntaoLu / tree.md
Created August 20, 2014 21:30 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'
@ChuntaoLu
ChuntaoLu / run-multiple-redis-instances.md
Last active January 9, 2020 04:59 — forked from jarvys/run-multiple-redis-instances.md
configure multiple redis servers
  • create a new redis .conf file
$ cp /etc/redis/6379.conf /etc/redis/6380.conf
  • edit /etc/redis/6380.conf, illustrated as below
...