Skip to content

Instantly share code, notes, and snippets.

@googya
Last active August 30, 2020 05:57
Show Gist options
  • Save googya/e52e4407536bb463a0ce9760e81ff885 to your computer and use it in GitHub Desktop.
Save googya/e52e4407536bb463a0ce9760e81ff885 to your computer and use it in GitHub Desktop.
code snippets

sending mail using sendcloud

response = RestClient.post "http://api.sendcloud.net/apiv2/mail/send", :attachments => File.new('all.sql','rb'),:apiUser => 'metalist',:apiKey => 'key',:from => "leslie_wen@qq.com",:fromName => "noname",:to => "leslie_wen@qq.com",:subject => "users assets",:html => 'users assets: attachments'
@googya
Copy link
Author

googya commented Jul 9, 2020

require 'sequel'
require 'jdbc/mysql'

url = "jdbc:mysql://192.168.159.128:13306/exchange_m_v1_test?user=ceshi&password=ceshi"
# puts url
DB = Sequel.connect(url)

# ACCOUNT_ID = DB["select account_id from t_interest_account where principal_coin = 'BTC' and interest_coin = 'USDT';"].first[:account_id]

def interest_for_btc(interest)
  <<-SQL
  UPDATE t_interest_account SET
    untransferred_interest = untransferred_interest + #{interest}
    , all_interest = all_interest + #{interest}
    , due_interest = due_interest + #{interest}
    ,updated_at = NOW() WHERE principal_coin = 'BTC' AND interest_coin = 'USDT' AND platform_id = '52';

  INSERT INTO t_interest_statement (from_coin, to_coin, from_account, to_account, from_amount, to_amount, ex_rate, operation_type, inserted_at, updated_at)
  VALUE('USDT', 'USDT', 'manual_nst_interest', (select account_id from t_interest_account where principal_coin = 'BTC' and interest_coin = 'USDT'), #{interest}, #{interest}, 1, 'LOAN_NST_INTEREST_COLLECTION', NOW(), NOW());
SQL
end

def interest_for_other(coin, amount, interest)
  <<-SQL
  UPDATE t_loan_account SET
    all_amount = #{amount},
    current_amount = #{amount},
    all_interest = all_interest + #{interest},
    current_interest = current_interest + #{interest},
    remained_interest = remained_interest + #{interest},
    untransferred_interest = untransferred_interest + #{interest},
    updated_at = NOW() WHERE coin = '#{coin}';
SQL
end

def parse_data()
  puts Dir.pwd
  f = IO.read("/tmp/interestdata")
  rows = f.split("\n")
  rows.map {|e| e.split(/\s|\t/)  }  
end

def generate_sql(rows)
  sql = ""
  rows.each do |row|
    if row[0] == "BTC"
      interest = row[-1]
      sql << interest_for_btc(interest)
      sql << "\n"    
    else
      interest = row[-1]; amount = row[2]; coin = row[0]
      sql << interest_for_other(coin, amount, interest) 
      sql << "\n"
    end
  end
  
  sql
end

def execute_sql(sql)
  DB.transaction do
    DB["UPDATE t_loan_job_control SET job_state = 1 WHERE id  = 1;"]
    DB[sql]
  end
  puts :DONE
end

rows = parse_data
sql = generate_sql(rows).to_s
puts sql
execute_sql sql

⚠️: DB.run(sql) 的时候, 有问题, 用 DB[sql] 则没有问题,具体原因待查

@googya
Copy link
Author

googya commented Jul 29, 2020

find . ! -newermt 2020-07-29 ! -type d -delete

@googya
Copy link
Author

googya commented Aug 26, 2020

# find files  created  5 days ago

find . -mindepth 1 -mtime +5 

@googya
Copy link
Author

googya commented Aug 30, 2020

ruby bin/console

非常方便调试一些代码

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require_relative '../aws_email.rb'

begin
  require 'pry-byebug'
  binding.pry
rescue LoadError
  require 'irb'
  binding.irb
end

puts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment