This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#对字典排序 | |
dic = {0: 1, 2: 2, 4: 4, 6: 1, 7: 1, -6: 1} | |
dic_after = sorted(dic.items(), key=lambda x:x[1]) | |
# 如果想按key来排序则sorted(dic.items(), key=lambda x:x[0]) | |
# dic_after为一个列表: [(0, 1), (6, 1), (7, 1), (-6, 1), (2, 2), (4, 4)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1.拨打电话 | |
// 给移动客服10086拨打电话 | |
Uri uri = Uri.parse("tel:10086"); | |
Intent intent = new Intent(Intent.ACTION_DIAL, uri); | |
startActivity(intent); | |
//2.发送短信 | |
// 给10086发送内容为“Hello”的短信 | |
Uri uri = Uri.parse("smsto:10086"); | |
Intent intent = new Intent(Intent.ACTION_SENDTO, uri); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bitmap bitmapOrg = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.moon); | |
Matrix matrix = new Matrix(); | |
matrix.postRotate(-90);//旋转的角度 | |
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, | |
bitmapOrg.getWidth(), bitmapOrg.getHeight(), matrix, true); | |
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); | |
———————————————— | |
版权声明:本文为CSDN博主「阳光岛主」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 | |
原文链接:https://blog.csdn.net/ithomer/article/details/8142689 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//属性为:android:backgroup,如果直接给背景色将会报错: | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_selected="true"><shape> | |
<gradient android:angle="0" android:centerColor="#00a59f" android:endColor="#00a59f" android:startColor="#00a59f" /> | |
</shape></item> | |
<item android:state_focused="true"><shape> | |
<gradient android:angle="0" android:centerColor="#00a59f" android:endColor="#00a59f" android:startColor="#00a59f" /> | |
</shape></item> | |
<item android:state_pressed="true"><shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <mutex> | |
#include <Windows.h> | |
// callback test | |
// API part | |
typedef void(__stdcall *CallbackEvent)(const char* pStr, bool bOK, void * any); | |
// API part |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float invSqrt(float x) | |
{ | |
float xhalf = 0.5 * x; | |
int i = *(int*)&x; // get bits for floating value | |
i = 0x5f3759df - (i >> 1); // gives initial guess | |
x = *(float*)&i; // convert bits back to float | |
x = x * (1.5 - xhalf * x * x); // Newton step | |
return x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
先由 x=1+r2 ,r2代表根号2,逆推根是这个时的方程,得到 x^2-2x-2=0 ,变形得: x^2=2+1/x | |
两边同时除以x得: x=2+1/x | |
这样我们就得到一个递归式,根据这个递归式写出一个递归函数: | |
**/ | |
#include<cstdio> | |
double g2(int n,double ans){ | |
if(n>0){ | |
return g2(--n,(2+1/ans)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** c语言标准库没有截取部分字符串的函数,为啥?因为用现有函数strncpy,很容易做到! **/ | |
char dest[4] = {""}; | |
char src[] = {"123456789"}; | |
strncpy(dest, src, 3); | |
puts(dest); | |
//输出结果为 123 | |
//strncpy函数中的参数是字符串数组的名字,而数组名本质上是指针,那么,src+3 就可以实现将 src中从第4个字符开始复制n个字符给 dest 了 | |
char dest[4] = {""}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <stdio.h> | |
#include <sys/socket.h> | |
#include <linux/in.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> |