Skip to content

Instantly share code, notes, and snippets.


Yunzheng 42thcoder

View GitHub Profile
42thcoder / bench_rails_memory_usage.rb
Created Jun 20, 2016 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
View bench_rails_memory_usage.rb
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
42thcoder / test.js
Created Mar 20, 2016
handle exception the right way with async/await && promise && express
View test.js
//测试 express && async 的异常处理
import express from 'express';
let router = express.Router();
function badass() {
return new Promise(async(resolve, reject)=> {
console.log('before throw error');
View gist:5fdec9d278ea4adfd7df
class Api < Grape::API
class << self
def log_exception(exception)
trace = exception.backtrace
message = "\n#{exception.class} (#{exception.message}):\n"
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
message << " " << trace.join("\n ")

scope 该写在哪里

old days

要把 model 中的代码拿出来, common pattern 是这样的:

module MyModule
  def self.included(base)
 base.extend ClassMethods
usage() {
echo "Usage: $PROG_NAME {list|ping|optimal|conn|close|status}"
exit 1
View community_thread.rb
after_update :decr_group_thread_count, :hide_posts, if: "self.hidden_changed?"
View Reverse Polish Notation Calculator
# 许多特殊情况都没考虑
# 除数为0 用户输入字母 括号
class Stack
def initialize(size)
@stack =
@sp = 0

This is an example command for Backtick. A Backtick command consists of some executable JavaScript and a bit of metadata in JSON.

Here are the required steps to create a command:

  1. Create a new Gist with a command.js and command.json file, or simply fork this one.

  2. Write your JavaScript in command.js. This will be injected into and executed on the page the user is currently on when they run it.

  3. Add some metadata to the command.json file:

  • name: The name of the command.