Skip to content

Instantly share code, notes, and snippets.

View HViktorTsoi's full-sized avatar

KINO HViktorTsoi

  • BUAA
View GitHub Profile
@HViktorTsoi
HViktorTsoi / .html
Last active January 30, 2018 14:09
Flask-Jinjia2 Pagination template, the pattern is like '/display/<page_number>'
{% macro pager(_uri, total, limit, curr_page, left=3, right=7) -%}
{% set uri=_uri %}
{% if total > limit %}
{% set page_num = total//limit if total%limit==0 else total//limit+1 %}
{% set pre_page = curr_page - 1 %}
{% set pre_page = 1 if pre_page < 1 else pre_page %}
{% set next_page = curr_page + 1 %}
{% set next_page = page_num if next_page > page_num else next_page %}
{% set begin_idx = 1 if curr_page <= 3 else curr_page - left %}
{% set end_idx = begin_idx + right %}
@HViktorTsoi
HViktorTsoi / snap.svg图层置顶方法
Created April 9, 2018 12:10
snap.svg图层置顶方法
parentElement.add(layerElement)可以实现将layerElement置顶(即使这个layer已经存在于parentElement中了)
@HViktorTsoi
HViktorTsoi / getObject.vue
Created April 11, 2018 09:49
snap.svg 获取变换矩阵对象
svgElement.transform().localMatrix.split()
@HViktorTsoi
HViktorTsoi / applicathon.yml
Created April 18, 2018 05:48
SpringBoot部署
# 文件夹结构设计
# 数据文件夹的顶层为data文件,之后,根据用途细分,例如temp, user
web-path:
upload-dir: '/var/www/CancerDiagnose/'
temp-file-dir: "data/temp/"
user-data-dir: "data/user/"
# 在用户文件夹中,按照用户id进行细分,然后,每个id夹有具体的功能细分文件夹,例如"data/user/1/patientAvator"
user-data:
patient-avatar: "patientAvatar/"
patient-xray: "xray/"
@HViktorTsoi
HViktorTsoi / WatchProp_Children.vue
Created April 19, 2018 13:16
vue监听子组件的prop属性从而实现响应式解耦
<template>
<!-- 添加图像的dialog -->
<el-dialog
title="上传X线片"
:visible.sync="addDiagnoseDialogVisible"
width="30%"
center>
<span slot="footer" class="dialog-footer">
<el-button @click="addDiagnoseDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="saveXRay">确 定</el-button>
@HViktorTsoi
HViktorTsoi / UltrasonicImageService.java
Created April 28, 2018 04:13
Spring JPA中, 对于数据库中存在的JSON字段, 并且该字段对应Java对象,Specification分页查询方式
@Override
public Page<UltrasonicImage> getAllUltrasonicImageByStatus(String status, Integer page, Integer num, User user) {
if (page == null || page < 1)
page = 1;
if (num == null || num < 0)
num = 10;
Sort sort = new Sort(Sort.Direction.DESC, "createTime");
Pageable pageable = new PageRequest(page - 1, num, sort);
Page<UltrasonicImage> ultrasonicImages = ultrasonicImageRepository.findAll((root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
@HViktorTsoi
HViktorTsoi / txt
Created July 14, 2018 10:41
Ubuntu下 Android Studio配置 踩坑
科学上网
这年头,没有梯子真的是无法生存,连个android SDK都更新不了,好吧,接下来安装shadowsocks-qt5
sudo add-apt-repository ppa:hzwhuang/ss-qt5
sudo apt-get update
sudo apt-get install shadowsocks-qt5
适用于ubuntu14.04 及以上,全部说明请看https://github.com/shadowsocks/shadowsocks-qt5/wiki/%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97
安装完以后chrome+SwitchySharp是可以科学上网的,但是ubuntu居然不支持shadowsocks的代理(实测LinuxMint是支持的),android studio 也不支持,所以就需要另一个小软件:polipo,通过它把shadowsocks的 socks5代理转换成http代理
安装
sudo apt-get install polipo
对于某一采样率K的音频文件 如果其是16bit的 则代表1s内有K个16bit的数据 而不是K个字节(8bit)的数据
@HViktorTsoi
HViktorTsoi / PCMReader.java
Created August 7, 2018 13:10
解析16bit位宽PCM时将byte转换为short的方式
/*
* 将raw数据中的二进制转换为实际的音频信号 由于默认音频格式为16bit 小端存储 因此这里只使用high和low两位
* 如果用其他bit宽度需要修改此函数
*
* */
public static int rawAudioDataToShort(byte high, byte low) {
byte[] byteArray = {high, low};
return ByteBuffer.wrap(byteArray).order(ByteOrder.LITTLE_ENDIAN).getShort();
}
@HViktorTsoi
HViktorTsoi / shuffle.py
Created September 3, 2018 11:55
numpy shuffle一个或多个有对应关系的矩阵
X Y是二维的numpy矩阵
permutation = list(np.random.permutation(m))
shuffled_X = X[:, permutation]
shuffled_Y = Y[:, permutation].reshape((1,m)) # reshape是为了保证矩阵不会自动转化为向量