use Rack::Lint # gives more descriptive error messages when responses aren't valid
class LogIt
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
body.map { |chunk| p "LogIt: #{chunk}" }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Where | |
| class <<self | |
| attr_accessor :editor | |
| def is_proc(proc) | |
| source_location(proc) | |
| end | |
| def is_method(klass, method_name) | |
| source_location(klass.method(method_name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I use the first | |
| —– BEGIN LICENSE —– | |
| Michael Barnes | |
| Single User License | |
| EA7E-821385 | |
| 8A353C41 872A0D5C DF9B2950 AFF6F667 | |
| C458EA6D 8EA3C286 98D1D650 131A97AB | |
| AA919AEC EF20E143 B361B1E7 4C8B7F04 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //To fetch a branch, you simply need to: | |
| git fetch origin | |
| //This will fetch all of the remote branches for you. With the remote branches | |
| //in hand, you now need to check out the branch you are interested in, giving | |
| //you a local working copy: | |
| git checkout -b test origin/test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Latency Comparison Numbers | |
| -------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf
File locations:
nginx.confto/usr/local/etc/nginx/default.confanddefault-ssl.confto/usr/local/etc/nginx/sites-availablehomebrew.mxcl.nginx.plistto/Library/LaunchDaemons/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.company; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.Mac; | |
| import javax.crypto.spec.IvParameterSpec; | |
| import javax.crypto.spec.SecretKeySpec; | |
| import java.security.MessageDigest; | |
| import java.security.SecureRandom; | |
| public class Main { |
对于一个API请求,开发平台一般需要知道下面几件事情:
- 哪个应用发起这个请求(Which application is making the request)
- 这个请求是为哪个用户发起的(Which user the request is posting on behalf of)
- 用户是否对这个请求进行授权(Whether the user has granted the application authorization to post on the user's behalf)
- 请求是否在传输过程中被篡改(Whether the request has been tampered by a third party while in transit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # All credit: http://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-with-redis | |
| redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.*; | |
| import java.time.format.DateTimeFormatter; | |
| import java.time.format.FormatStyle; | |
| import java.time.temporal.ChronoUnit; | |
| import java.time.temporal.TemporalAdjusters; | |
| import java.util.*; | |
| import static java.time.temporal.TemporalAdjusters.*; | |
| public class Java8DateTimeExamples { |