Skip to content

Instantly share code, notes, and snippets.

View angelfan's full-sized avatar

耿返 angelfan

View GitHub Profile
# frozen_string_literal: true
module SessionRedisPatch
def generate_unique_sid(_session)
loop do
sid = generate_sid
first = with do |c|
[*init_session(c, sid, @default_options)].first
end
break sid if [1, true].include?(first)
# -*- coding: utf-8 -*-
from fabric.api import env, run
env.user = 'root'
env.hosts = ['10.1.69.24', '10.1.51.22']
env.port = '22'
env.git_clone = "git@gitlab.tuhu.cn:gengfan/treasure.git"
env.base_dir = "/root/apps"
env.app_name = "treasure"
env.domain_path = "{base_dir}/{app_name}".format(base_dir=env.base_dir, app_name=env.app_name)
@angelfan
angelfan / stringify_keys.rb
Created July 28, 2016 10:04 — forked from mkuhnt/stringify_keys.rb
Deep Stringify Keys of hash even with embedded arrays
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
if Array === value
value.map{|v| transform_hash(v, options, &block)}
else
value
end
@angelfan
angelfan / dbconfig.rake
Created July 28, 2016 10:03 — forked from ka8725/dbconfig.rake
database.yml generator. Global Rake implementation
require 'yaml'
desc 'Generates database.yml, optional arguments: [adapter, user, password]'
task :dbconfig => 'database.yml'
file 'database.yml', [:adapter, :username, :password] do |t, args|
Dir.chdir('config')
args.with_defaults(:project_path => Dir.pwd)
DBConfigGenerator.new(t, args).generate
end
@angelfan
angelfan / si.rb
Created March 21, 2016 02:03 — forked from rasefon/si.rb
Similar Image Compare
require 'RMagick'
$scale_size = 256.0
$img_fn1 = ARGV[0]
$img_fn2 = ARGV[1]
$scale_size = ARGV[2].to_f if ARGV[2]
def calculate_threshold(img_fn)
dir_name = File.dirname(img_fn)