Encore's Blog

Web 开发者 | 专注于WEB应用程序的软件开发人员
Javascript - 使用Async Functions实现一个简单的计时器
编码 2018-12-01 邵壮

ASYNC FUNCTIONasync function 声明用于定义一个返回 AsyncFunction 对象的异步函数。异步函数是指通过事件循环异步执行的函数,它会通过一个隐式的 Promise 返回其结果。但是如果你的代码使用了异步函数,它的语法和结构会更像是标准的同步函数。接下来,我们使用 Javascript 来实现一个简单的计时器:// Your browser must support async/await and speech synthesis var countdown, say, sleep; sleep = function(ms) {   return new Promise(function(resolve) {     return window.setTimeout(resolve, ms);   }); }; output...

标签: Javascript Coffee
Ruby - 中定位方法定义的位置
编码 2018-09-02 邵壮

Ruby: 2.5.x, 2.6.x  在Ruby中如何快速定位方法的定义位置, 接下来,我们看看一些示例代码 Method 1: Object#source_location 1 #!/usr/bin/env ruby 2 3 class Color 4 def initialize 5 end 6 7 def default_color 8 'black' 9 end 10 end 11 12 puts "RUBY VERSION: #{RUBY_VERSION}" 13 color = Color.new 14 puts color.method(:defaul...

编码 2017-07-16 邵壮

首先, 我们来看如何在一个文件中替换指定文本 sed -i 's/originaltext/newtext/g’ file.txt 在多个文件中替换指定文本,我们只需修改对应匹配文件名称即可. sed -i 's/originaltext/newtext/g’ *.txt "sed" - More explanation: * sed = Stream EDitor * -i = in-place (i.e. save back to the original file) * The command string: * s = the substitute command * original = a regular expression describing the word to replace (or just t...

标签: Linux Sed
A quick script to selectively remove Failed Jobs from Resque 1.x
编码 2017-07-16 Encore Shao

1. 你可以复制到以下的代码片段并将其粘贴到rails控制台中 def delete_if redis = Resque.redis (0...Resque::Failure.count).each do |i| string = redis.lindex(:failed, i) break if string.nil? job = Resque.decode(string) remove = yield job next unless remove redis.lrem(:failed, 1, string) redo end end 2. 选择你要删除的所有workers,例如:由于http错误而失败的所有推送通知作业 ...

标签: Rails Ruby Resque
Sublime - Settings
编码 2017-07-04 邵壮

Sublime -> Preferences -> Settings{ "auto_complete": true, "auto_upgrade_ignore": [ "Better CoffeeScript" ], "bold_folder_labels": true, "color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme", "draw_white_space": "all", "enable_tab_scrolling": false, "ensure_newline_at_eof_on_save": true, "fade_fold_buttons": false, "fold_buttons": true,...

标签: Sublime Tools
This website uses cookies to ensure you get the best experience on our website.
Got it!