Skip to content

Instantly share code, notes, and snippets.

View zlx's full-sized avatar

Newell Zhu zlx

  • Hangzhou, China
View GitHub Profile
@zlx
zlx / matrix.rb
Last active February 9, 2018 03:20
# 题目:
# 给出一个二维数组,从左到右递增,从上到下递增
# 要求给出一个 target,返回是否包含在数组里面?
# Example:
# target = 5, return true.
# target = 20, return false.
# [
# [1, 4, 7, 11, 15],
@zlx
zlx / poker-hands-rust.rs
Created August 30, 2016 12:31
Poker Hand in Rust
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 {
@zlx
zlx / simple_form_bootstrap3.rb
Created June 30, 2016 09:26 — forked from tokenvolt/simple_form_bootstrap3.rb
Bootstrap 3 simple form initializer
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
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
#!/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)
@zlx
zlx / creation_time.rb
Last active December 15, 2015 12:16
Get file creation time
# 支持 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
@zlx
zlx / alipay_red_packet.rb
Last active August 29, 2015 14:14
支付宝朋友圈红包识别程序
# 支付宝分享到微信的红包识别
# 依赖: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")
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
reader, writer = IO.pipe
fork do
reader.close
10.times do
# heavy lifting
writer.puts "Another one bites the dust"
end
end
writer.close
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