要把 model 中的代码拿出来, common pattern 是这样的:
module MyModule
def self.included(base)
base.extend ClassMethods
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 |
//测试 express && async 的异常处理 | |
import express from 'express'; | |
let router = express.Router(); | |
function badass() { | |
return new Promise(async(resolve, reject)=> { | |
console.log('before throw error'); |
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 ") |
#!/bin/bash | |
PROG_NAME=$0 | |
ACTION=$1 | |
usage() { | |
echo "Usage: $PROG_NAME {list|ping|optimal|conn|close|status}" | |
exit 1 | |
} |
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 |
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:
Create a new Gist with a command.js
and command.json
file, or simply fork this one.
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.
Add some metadata to the command.json
file: