This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PipeElement | |
attr_accessor :source | |
def initialize | |
@delegator = Fiber.new do | |
process | |
end | |
end | |
def | other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def dec(fn): | |
def inner_fn(*args): | |
result = fn(*args) | |
print "the result is: " + result | |
return result | |
return inner_fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(ipctest). | |
-export([oneway/0, consumer/0, pingpong/0]). | |
oneway() -> | |
N = 10000000, | |
Pid = spawn(ipctest, consumer, []), | |
Start = erlang:now(), | |
dotimes(N - 1, fun () -> Pid ! message end), | |
Pid ! {done, self()}, | |
receive ok -> ok end, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Misc { | |
public static int[] StrToInt(String str) { | |
if(str == null) return new int[0]; | |
int[] array = new int[str.codePointCount(0,str.length())]; | |
for(int i=0; i < array.length; i++){ | |
array[i] = str.codePointAt(i); | |
} | |
return array; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order | |
attr_accessor :type, :sub_orders | |
def initialize type | |
self.type = type | |
self.sub_orders = [] | |
end | |
# 统计订单及其包含子订单的数量,按照订单类型归类 | |
def count_items | |
result = sub_orders.reduce({}) do |result, order| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(multi_try). | |
-export([dothese/1]). | |
dothese(FuncArray) -> | |
Me = self(), | |
lists:foreach(fun(F) -> spawn(fun() -> F(Me) end) end, FuncArray), | |
spawn(fun() -> timer:sleep(200), Me ! timeout end), | |
Result = get_result("",length(FuncArray)), | |
io:format("result: ~p~n", [Result]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'action_mailer' | |
class Mailer < ActionMailer::Base | |
def contact | |
mail( | |
:to => "test@example.com", | |
:from => "test@example.com", | |
:subject => "Test") do |format| | |
format.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RubyVM::InstructionSequence.compile_option = { | |
tailcall_optimization: true, | |
trace_instruction: false | |
} | |
eval <<end | |
def fact(n, result = 1) | |
if n == 1 | |
result | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo | |
111 | |
rescue | |
222 | |
ensure | |
333 | |
end | |
puts foo # got 111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyTool | |
module Tree | |
class << self | |
def loop root, &block | |
return false unless File.exist? root | |
block_given? ? exec(root, &block) : collect(root) | |
end | |
def exec root, &block |
NewerOlder