Skip to content

Instantly share code, notes, and snippets.

View shenjing023's full-sized avatar
🎯
Focusing

liuwei shenjing023

🎯
Focusing
  •  北京
View GitHub Profile
@shenjing023
shenjing023 / example.go
Created August 26, 2020 06:17
[Golang] os/exec 带超时 command
package main
import (
"log"
"os/exec"
"time"
)
func main() {
cmd := exec.Command("ping", "www.baidu.com")
##
# chang the image color to another color, such as white to red
##
import Image
import numpy as np
im = Image.open('test.png')
im = im.convert('RGBA')
data = np.array(im) # "data" is a height x width x 4 numpy array
@shenjing023
shenjing023 / rapunzel_moviepy.py
Created May 22, 2020 08:05 — forked from Zulko/rapunzel_moviepy.py
Tangled + MoviePy
"""
This creates the following GIF, where the text appears to be "embedded"
in the video and "disappears" behind rapunzel.
http://i.imgur.com/gxEHfLX.gif
"""
from moviepy.editor import *
import numpy as np
import skimage.morphology as skm
"""
An alternative text clip for Moviepy, relying on Gizeh instead of ImageMagick
Advantages:
- Super fast (20x faster)
- no need to install imagemagick
- full-vector graphic, no aliasing problems
- Easier font names
Disadvantages:
@shenjing023
shenjing023 / decorator.go
Created September 5, 2019 15:21 — forked from saelo/decorator.go
Decorators in Go
package main
import (
"fmt"
"reflect"
)
func Decorate(impl interface{}) interface{} {
fn := reflect.ValueOf(impl)
@shenjing023
shenjing023 / example.md
Created December 16, 2017 07:26
[qmlRegisterType的一种用法] #qml

原来一直以为qmlRegisterType一次只能注册一个类,今天看了一个大佬的源码之后,发现同一个模块名可以导入多个类 示例:

qmlRegisterType<ClassA>("Class",1,0,"Class1");
qmlRegisterType<ClassB>("Class",1,0,"Class2");
qmlRegisterType<ClassC>("Class",1,0,"Class3");

这样在qml文件可以这样使用

import Class 1.0
@shenjing023
shenjing023 / example.md
Created December 16, 2017 03:20
[qml中可以使用的javascript库] #qml
@shenjing023
shenjing023 / example.md
Last active December 15, 2017 01:43
[QML添加第三方字体] #qml

在main.cpp中添加

QFontDatabase::addApplicationFont("xxx.ttf")

然后就可以在qml文件中使用font.family="xxx"来设置字体,这样比在qml文件中使用Fontloader更方便。

@shenjing023
shenjing023 / example.md
Last active August 24, 2017 01:51
[Qt跟踪鼠标事件] #Qt

bool mouseTracking

这个属性保存的是窗口部件跟踪鼠标是否生效。

如果鼠标跟踪失效(默认),当鼠标被移动的时候只有在至少一个鼠标按键被按下时,这个窗口部件才会接收鼠标移动事件。

如果鼠标跟踪生效,如果没有按键被按下,这个窗口部件也会接收鼠标移动事件。

也可以参考mouseMoveEvent ()和QApplication::setGlobalMouseTracking ()。

@shenjing023
shenjing023 / example.md
Last active August 23, 2017 10:20
[Django过滤器总结] #django
  1. 形式:小写:{{ name | lower }}

  2. 串联:先转义文本到HTML,再转换每行到<p>标签:{{ my_text|escape|linebreaks }}

  3. 过滤器的参数

  • 显示前30个字:{{ bio | truncatewords:"30" }}
  • 格式化:{{ pub_date | date:"F j, Y" }}
  • 过滤器列表:{{ 123|add:"5" }} 给value加上一个数值
  • {{ "AB'CD"|addslashes }}: 单引号加上转义号,一般用于输出到javascript中
  • {{ "abcd"|capfirst }}: 第一个字母大写
  • {{ "abcd"|center:"50" }}: 输出指定长度的字符串,并把值对中