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 Jun 1, 2020

SELECT CONCAT('DROP DATABASE `',schema_name,'` ;') AS `-- stmt`
  FROM information_schema.schemata
 WHERE schema_name LIKE 'match\_%' ESCAPE '\\'
 ORDER BY SCHEMA_NAME;

@googya
Copy link
Author

googya commented Jun 2, 2020

   Host gitlab.com
       PubkeyAcceptedKeyTypes +ssh-rsa
       HostName gitlab.com
       IdentityFile ~/.ssh/gitlab_work
       User git

@googya
Copy link
Author

googya commented Jun 10, 2020

SELECT concat('DROP TABLE IF EXISTS `', table_name, '`;')
FROM information_schema.tables
WHERE table_schema = 'MyDatabaseName';

@googya
Copy link
Author

googya commented Jun 11, 2020

ssh -nNT  -L 16377:localhost:16377 root@100.86.183.61

相当于新建了一个本地代理(正向), 代理服务的端口号为 16377,本地其他应用, 能通过这个代理服务访问远程(100.86.183.61) 16377 所提供的服务, 达到的效果是: 对远程服务来讲, 服务的发起者是(远程机器)本地发起的。

例子, 有些 mysql 服务器设置某些用户只能本地访问, 不允许远程登录。 但有时候确实需要远程登录, 怎么办呢, 此时, 这条命令就非常有用

ssh -R 8888:localhost:80 yourname@yourvps.com 
# -R 表示Remote 转发 
# 这一句表示 forward my (local)localhost port 80 to (remote)machine at port 8888

这条命令相当于建立了一个反向代理(reverse proxy, 类比 Nginx Caddy 之类的)把远程的请求(yourvps.com:8888) 转到本地的 80 端口来

@googya
Copy link
Author

googya commented Jun 16, 2020

class String
  def camel_case_lower
    self.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
  end
end

%w[
  lend_success_notify
  redeem_success_notify
  borrow_success_notify
  repay_success_notify
  margin_call_notify
  liquidation_notify
  payment_send_notify
  payment_receive_notify
].each do |column|
  t = <<-TXT
    @Column(name="#{column}")
    private String #{column.camel_case_lower};
TXT

puts t, "\n"
end

@googya
Copy link
Author

googya commented Jul 2, 2020

require 'http'

HTTP.post("http://api.sendcloud.net/apiv2/mail/send", 
          :form => {
  :apiUser => 'secret', # Verification using api_user and api_key
  :apiKey => 'cool',
  :from => "leslie@leslie.net", # The sender, use the correct email address instead
  :fromName => "noname",
  :to => "leslie@leslie.net", # The recipient address,use the correct email address instead, multiple addresses with '; '
  :subject => "debank compund screenshot",
  :html => 'debank compund screenshot: attachments',
  :attachments => [
    HTTP::FormData::File.new("/tmp/debank_0.png"), 
    HTTP::FormData::File.new("/tmp/debank_1.png"),
    HTTP::FormData::File.new("/tmp/debank_2.png")
  ]
}

)

@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