Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Yunzheng 42thcoder

🎯
Focusing
View GitHub Profile
@42thcoder
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(" "))
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 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 ")
View concern.md

scope 该写在哪里

old days

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

module MyModule
  def self.included(base)
 base.extend ClassMethods
View vpn.sh
#!/bin/bash
PROG_NAME=$0
ACTION=$1
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 = Array.new(size)
@sp = 0
end
View README.md

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.