Skip to content

Instantly share code, notes, and snippets.

@DxPoly
DxPoly / 0_reuse_code.js
Created December 6, 2016 09:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@DxPoly
DxPoly / dingding_scan_login.rb
Last active June 24, 2019 09:54
钉钉扫码登录第三方网站
# 用于rails的代码片段,省略了各种引入第三方库的代码
class Dingding
def self.get_user_info_by_code code
timestamp = (Time.now.to_f * 1000).to_i
sign = hmac_sign(APP_SECRET, timestamp)
url = "https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=APPID}&timestamp=#{timestamp}&signature=#{sign}"
RestClient.post(url, { tmp_auth_code: code }.to_json, { 'Content-Type' => 'application/json' }) do |response|
return JSON.parse(response.body).symbolize_keys
# Question 1: polymorphism - define a function called addall()
def addall(x,y):
if type(x) != type(y):
print 'Test for the function call, addall(',repr(x),',',repr(y),'): The data you entered is not correct.'
elif type(x) in [int, float, list, tuple]:
print 'The function call, addall(',repr(x),',',repr(y),'), returns',x+y,'.'
elif type(x) == set:
print 'The function call, addall(',repr(x),',',repr(y),'), returns',x|y,'.'
elif type(x) == dict:
z = {}
@DxPoly
DxPoly / cross_tab.prg
Created December 9, 2021 08:32
cross tab
%% http://tomorrowssolutionsllc.com/ConferenceSessions/Turning%20Data%20Sideways.pdf
%% https://github.com/VFPX/FastXTab/
LOCAL oXTab AS FastXTab OF "fastxtab\fastxtab.prg"
oXTab = NEWOBJECT("fastxtab", "fastxtab\fastxtab.prg")
WITH oXTab AS FastXTab OF "fastxtab\fastxtab.prg"
.cColField = 'gu_count'
.nMultiDataField = 2 %% 以 gu_count 和 gunum 分组,每组显示多个数据
.acDataField[1] = 'clnum' %% 第一计数据是 clnum
.acDataField[2] = 'payroll' %% 第二个数据是 payroll
@DxPoly
DxPoly / cart.liquid
Last active April 17, 2024 13:40
LIF shopify cart page
<!-- /sections/cart.liquid -->
{%- liquid
assign hide_quantity = 'quantity--hide'
if settings.cart_show_quantity
assign hide_quantity = ''
endif
assign ajax_disable = false
assign no_ajax_class = ''
if settings.cart_style == 'compatible'
@DxPoly
DxPoly / cart.liquid
Last active April 28, 2024 09:55
对比 demo cart.liquid
<!-- /sections/cart.liquid -->
{%- liquid
assign hide_quantity = 'quantity--hide'
if settings.cart_show_quantity
assign hide_quantity = ''
endif
assign ajax_disable = false
assign no_ajax_class = ''
if settings.cart_style == 'compatible'
@DxPoly
DxPoly / calc_pvq.sql
Last active May 7, 2024 02:38
calc pvq total
SELECT *
FROM (
SELECT
o.distributor_id,
ui.firstname || ' ' ||ui.lastname distributor_name,
ui.phone,
ui.email,
to_char(o.state_date, 'YYYY-MM') qualified_date,
sum(o.pvq) pvq_total
FROM user_infos ui
@DxPoly
DxPoly / epub_processer.py
Created December 5, 2024 10:19
Pragmatic Bookshelf EPUB file processer
import re
import zipfile
import tempfile
import os
import shutil
from pathlib import Path
def process_html_content(content):
"""
Add <pre> tags around <table class="processedcode"> elements
@DxPoly
DxPoly / new_order_cv.sql
Created April 15, 2025 04:09
Regen CV Calculation
-- 新增订单 CV 数据清单(1.1 - 4.30)
WITH OrderParticipants AS (
-- 收集所有有效的订单和关联分销商
SELECT
CASE WHEN ru.role_id = 2 THEN
o.distributor_id -- 分销商自己的订单
ELSE
o.personal_sponsor_distributor_id -- 客户订单,关联到赞助人
END AS effective_distributor_id,
o.id AS order_id,