Skip to content

Instantly share code, notes, and snippets.

View daa233's full-sized avatar
🎯
Focusing

Du Ang daa233

🎯
Focusing
  • OUC -> Megvii
  • Beijing, China
View GitHub Profile
@daa233
daa233 / Few commands in bash #1.md
Last active February 13, 2016 10:05
Some commands on bash learned in LPTHW ex46.

Few commands in bash.

find

find . -name "*.pyc" -print

find all files with .pyc postfix.

find . -name "*.pyc" -exec rm {} \;
@daa233
daa233 / UpdateUIEverywhere.md
Created February 13, 2016 10:01
Android tip. Update UI everywhere.

How to update UI in some non-main threads?

Solution 1:

Use Handler and send Message.

Solution 2:

Force to run on UI thread.

new Thread() {
    public void run() {
        runOnUiThread(new Runnable() {
 @Override
@daa233
daa233 / About Hash Set in java.md
Created March 25, 2016 12:10
Cast HashSet<String> to String[]

It can be implemented as following, but why?

String[] checkedToDeleteStringArray = checkedToDeleteHashSet.toArray(new String[0]);

getWidth和getMeasuredWidth的区别

getWidth()

public final int getWidth() Return the width of the your view. Returns: int The width of your view, in pixels.

getWidth()得到的是view在父Layout中布局好后的宽度值,如果没有父布局,默认的父布局是整个屏幕。

getMeasuredWidth()

Like getMeasuredWidthAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

自定义View时居中绘制文本需要注意

canvas.drawText(text, x, y, paint)

第一个参数是我们需要绘制的文本,第四个参数是我们的画笔。主要是第二和第三个参数的含义,这两个参数在不同的情况下的值还是不一样的, x默认是这个字符串的左边在屏幕的位置,如果设置了paint.setTextAlign(Paint.Align.CENTER);那就是字符的中心, y是指定这个字符baseline在屏幕上的位置。y不是这个字符中心在屏幕上的位置,而是baseline在屏幕上的位置。

【参考资料】http://blog.csdn.net/lovexieyuan520/article/details/43153275

C语言中数组的初始长度能不能由用户输入来决定? 在我学C语言时,老师通过VC6.0告诉我们不可以。但是现在我用gcc(ver. 5.4)却可以编译成功,而且gcc没有对数组越界进行报错。具体来说,如果定义数组int a[n],初始长度由用户输入的n来决定,那么越界部分既可以读取,也可以写入;如果定义数组int b[2],即初始长度固定为某个整数,那么可以读取越界值b[2]、b[3]等,但是无法写入(运行程序时,向越界部分写入时会报stack smashing的错误)。读取到的越界部分的值均是没有初始化过的、内存中的随机值。

#include <stdio.h>

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    int a[n];
/**
* @file: PointerIncrement.cpp
* @description: p为指针变量,p++代表什么?
*
* @author: Du Ang
* @date: Apr. 21st, 2017
*/
#include <iostream>

Libraries have been installed in: /usr/local/lib

If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following:

  • add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution
  • add LIBDIR to the 'LD_RUN_PATH' environment variable
# -*- encoding=utf-8 -*-
# Python2 代码
import os
import csv
# Open the csv and write headers.
with open("files_count.txt",'wb') as out:
outwriter = csv.writer(out)
# outwriter.writerow(['Directory','FilesInDir','FilesIncludingSubdirs'])
def plot_confusion_matrix(cm, classes,
normalize=False,
title='Confusion matrix',
cmap=plt.cm.jet):
"""
This function prints and plots the confusion matrix.
Normalization can be applied by setting `normalize=True`.
"""
plt.imshow(cm, interpolation='nearest', cmap=cmap)
plt.title(title)