Skip to content

Instantly share code, notes, and snippets.

find . -type f -mtime +30 # 30 天之前修改过的文件
find . -type f -mtime -30 # 30 天内的文件
ls | xargs -l asd echo asdf # ${filename}f 文件名后多了个"f"
@xiejiangzhi
xiejiangzhi / cmd_counter_with_ruby
Created August 16, 2015 08:52
统计CLI下输入最多的工具名与输入的命令
#! /usr/bin/env ruby
# Tool top 10
# git 100
# vim 49
# xxx 21
#
# Action top 10
# git checkout master 231
# vim index.html 192
@xiejiangzhi
xiejiangzhi / sequel_to_active_record
Created October 8, 2015 05:59
migrate Sequel to ActiveRecord
#! /usr/bin/env ruby
require './boot' rescue nil
conn = ActiveRecord::Base.connection
table_name = 'schema_migrations'
cols = conn.execute("show columns from #{table_name}").map {|row| row.first }
unless cols.include?('version')
@xiejiangzhi
xiejiangzhi / autoload_settings
Created October 8, 2015 06:14
auto load settings
class Settings
class << self
Dir[Rails.root.join('config/settings/*')].each do |filepath|
filename = File.basename filepath
next unless filename =~ /^\w+\.ya?ml$/
puts "Load config '#{filename}'"
setting_name = filename.gsub(/\.ya?ml/, '')
eval(%Q{
def #{setting_name}
db_config = YAML.load_file('config/my_database.yml')
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(db_config)
spec = resolver.spec(env)
conn_pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
#! /bin/bash
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
libgpac-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \
libvorbis-dev libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
mkdir ~/ffmpeg_sources
which yasm && echo "yasm has installed" || sudo apt-get -y install yasm
which wget && echo "wget has installed" || sudo apt-get -y install wget
@xiejiangzhi
xiejiangzhi / config.ru
Created March 29, 2016 03:08
ruby rack app
app = Proc.new do |env|
['200', {'Content-Type' => 'text/html'}, ['Hello, this is a rack app.']]
end
run app
@xiejiangzhi
xiejiangzhi / web.rb
Last active March 29, 2016 03:09
ruby test web
require 'rack'
app = Proc.new do |env|
['200', {'Content-Type' => 'text/html'}, ['Hello, this is a rack app.']]
end
port = ENV['PORT'] || 8080
Rack::Handler::WEBrick.run app, Port: port
# Daemon.new.run do
# `echo "#{Process.pid} #{Time.now}" >> /tmp/daemon_ruby`
# end
require 'timeout'
require 'socket'
require 'logger'
require 'fileutils'