Skip to content

Instantly share code, notes, and snippets.

View Xenofex's full-sized avatar

Eli Wang Xenofex

View GitHub Profile
class AddColumnsForAttrEncrypted < ActiveRecord::Migration[5.2]
def change
tasks = {
alipays: [:private_key],
crawlers: [:username, :password],
delivery_platforms: [:key, :secret, :brand_key, :sid],
meituans: [:api_key],
wechat_service_accounts: [:wechat_pay_api_key, :wechat_pay_certificate]
}
@Xenofex
Xenofex / 慢到被杀死的请求.sh
Last active July 20, 2018 05:50
慢到被杀死的请求
rg 'ERROR -- : reaped' unicorn.stderr.log |\
awk '{ r=match($14, /worker=(.*)/, a); system("rg \x27#" $10 "\x27 production." a[1] ".log | tail -1 | awk \x27{ print substr($7, 2, 36) }\x27 " ) }' |\
awk '{ system("rg \x27" $0 ".*Started\x27 production.*.log") }'
@Xenofex
Xenofex / 门店上架.js
Last active June 6, 2018 05:06
支付宝口碑后台操作
window.$ = jQuery;
nextPage = () => new Promise((resolve => {
$('[data-role=next]').click();
$(document).one("ajaxComplete", () => {
resolve()
})
}));
@Xenofex
Xenofex / redis-keys-size.sh
Created May 20, 2018 00:43
Search redis keys for a pattern, get total memory usage of all the keys and values of them
redis-keys-size() {
redis-cli keys "$1" | awk '{ system("redis-cli memory usage \x27" $0 "\x27") }' | cut -d ' ' -f 2 | awk '{s+=$1} END {print s}'
}
@Xenofex
Xenofex / parse_log.rb
Created December 27, 2017 18:02
解析日志,提取集点请求参数的一个例子
# vim: set nu sw=2 sts=2:
require 'zlib'
class LogParser
class Request
attr_accessor :path, :method, :ip, :started_at, :end_at, :status, :duration, :parameters, :api_key, :id
def parameters=(parameters)
@parameters = parameters
@Xenofex
Xenofex / coffee_script_source_maps_in_dev.rb
Last active January 18, 2016 11:12
An initializer to enable source maps for coffee script in Rails 4.2.5/Sprockets 3.5.2
if Rails.env.development?
require "base64"
module Sprockets
module CoffeeScriptProcessor
DEFAULT_OPTIONS = { "sourceMap" => true }
def self.call(input)
data = input[:data]
input[:cache].fetch([self.cache_key, data]) do
.modal {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 100;
.bg {
position: absolute;
@Xenofex
Xenofex / ScanController.scala
Created April 11, 2015 08:54
ScanController用scala写了一遍
package com.jikabao.scala.merchant
import java.util
import java.util.{Collections, Date}
import com.google.common.collect.{Lists, Iterables}
import com.jikabao.common.ServiceResult
import com.jikabao.common.domain._
import com.jikabao.common.enums.QrCodeActionEnum._
import com.jikabao.common.service.UserHolder
package com.lettrs.lettrs.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import com.lettrs.lettrs.R;
import lombok.Getter;
import lombok.Setter;
@Xenofex
Xenofex / genstrings.sh
Created November 3, 2014 06:55
genstrings for Swift
#!/bin/bash
#
# genstrings which searchs both Objective-C .m files and Swift files
#
# Set the 'PROJECT' variable
# I'm using a short function 'LS' to replace NSLocalizedString. This script searches them both.
#
if ! type -P ggrep >/dev/null; then
>&2 echo "Error: GNU grep 'ggrep' not found. Install by 'brew install homebrew/dupes/grep'"