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
# 题目: | |
# 给出一个二维数组,从左到右递增,从上到下递增 | |
# 要求给出一个 target,返回是否包含在数组里面? | |
# Example: | |
# target = 5, return true. | |
# target = 20, return false. | |
# [ | |
# [1, 4, 7, 11, 15], |
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
mod poker { | |
use std::cmp::Ordering; | |
use std::collections::HashMap; | |
#[derive(Eq, Debug, Clone, Copy, Hash)] | |
enum CardValue { | |
DEFAULT = 0, V2, V3, V4, V5, V6, V7, V8, V9, VT, VJ, VQ, VK, VA, | |
} | |
impl CardValue { |
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
inputs = %w[ | |
CollectionSelectInput | |
DateTimeInput | |
FileInput | |
GroupedCollectionSelectInput | |
NumericInput | |
PasswordInput | |
RangeInput | |
StringInput | |
TextInput |
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 Foo | |
def large_return | |
return mini_return.map { |i| gen_str(i) } | |
end | |
def large_return_with_freeze | |
return mini_return.map { |i| gen_str(i).freeze } | |
end | |
def mini_return |
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 ruby | |
require 'colorize' | |
require 'commander/import' | |
program :name, 'fight' | |
program :version, '1.0.0' | |
program :description, 'Flight with CDN' | |
def log_target(ip, banner) | |
puts "Target IP: #{ip}".colorize(:red) |
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
# 支持 MacOS, ext4 文件系统的 Linux | |
# 参考:http://moiseevigor.github.io/software/2015/01/30/get-file-creation-time-on-linux-with-ext4/ | |
# | |
def creation_time(file_path) | |
case RUBY_PLATFORM | |
when /bsd/, /darwin/ | |
return %x{mdls -raw -name kMDItemFSCreationDate #{file_path}} | |
when /linux/ | |
inode = %x{ls -di "#{file_path}" | cut -d ' ' -f 1}.strip | |
fs = %x{df "#{file_path}" | tail -1 | awk '{print $1}'}.strip |
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
# 支付宝分享到微信的红包识别 | |
# 依赖:tesseract, gems(mini_magick, rtesseract) | |
# 使用: ruby alipay_red_packet.rb xxx.jpg | |
# xxx.jpg 就是支付宝红包图片 | |
require 'mini_magick' | |
require 'rtesseract' | |
img = MiniMagick::Image.new(ARGV[0]) | |
img.crop("#{1080-220}x#{1600-1360}+220+1360") |
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 'socket' | |
child_socket, parent_socket = Socket.pair(:UNIX, :DGRAM, 0) | |
maxlen = 1000 | |
fork do | |
parent_socket.close | |
4.times do | |
instruction = child_socket.recv(maxlen) | |
child_socket.send("#{instruction} accomplished!", 0) | |
end | |
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
reader, writer = IO.pipe | |
fork do | |
reader.close | |
10.times do | |
# heavy lifting | |
writer.puts "Another one bites the dust" | |
end | |
end | |
writer.close |
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
puts Process.pid | |
trap(:INT) { print "Na na na, you can't get me" } | |
sleep # so that we have time to send it a signal |
NewerOlder