Skip to content

Instantly share code, notes, and snippets.

View 42thcoder's full-sized avatar
🎯
Focusing

Yunzheng 42thcoder

🎯
Focusing
View GitHub Profile
@42thcoder
42thcoder / bench_rails_memory_usage.rb
Created June 20, 2016 17:09 — 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`.
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(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@42thcoder
42thcoder / test.js
Created March 20, 2016 13:18
handle exception the right way with async/await && promise && express
//测试 express && async 的异常处理
import express from 'express';
let router = express.Router();
function badass() {
return new Promise(async(resolve, reject)=> {
console.log('before throw error');

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.

scope 该写在哪里

old days

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

module MyModule
  def self.included(base)
 base.extend ClassMethods
@42thcoder
42thcoder / vpn.sh
Last active August 29, 2015 14:18 — forked from hongjiang/vpn.sh
#!/bin/bash
PROG_NAME=$0
ACTION=$1
usage() {
echo "Usage: $PROG_NAME {list|ping|optimal|conn|close|status}"
exit 1
}
@42thcoder
42thcoder / community_thread.rb
Created September 13, 2014 10:19
It's kind of funny.
after_update :decr_group_thread_count, :hide_posts, if: "self.hidden_changed?"
# 许多特殊情况都没考虑
# 除数为0 用户输入字母 括号
class Stack
def initialize(size)
@stack = Array.new(size)
@sp = 0
end
@42thcoder
42thcoder / gist:5fdec9d278ea4adfd7df
Last active August 28, 2015 09:30
异常处理
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 ")