0%

1. interface struct 能否相互嵌套

  1. struct struct //继承(不能多态), 如果内部struct实现了接口, 它也相当于实现了接口
  2. struct interface //可以内部用interface多态
  3. interface interface //单纯的导入
  4. interface struct //不允许
阅读全文 »

cannot execute binary file exec format error

是因为mac和ubuntu的二进制格式不一致

问题

Go是一门编译型语言,所以在不同平台上,需要编译生成不同格式的二进制包。
由于Go 1.5对跨平台编译有了一些改进,包括统一了编译器、链接器等。
编译时候只需要指定两个参数:GOOS和GOARCH即可。

阅读全文 »

安装mosh

1
2
sudo apt-get install mosh //server
brew install mobile-shell //mac

需要先设置本地

locale-gen zh_CN.UTF-8

远程服务器开启 mosh-server

需要aws开启udp mosh的端口

客户端连接

1
mosh ubuntu@ec2-54-191-9-26.us-west-2.compute.amazonaws.com -ssh="ssh -i 'aws.pem'"

1. fork别人的仓库

首先,在 GitHub 上 fork 到自己的仓库,如 docker_user/blockchain_guide,然后 clone 到本地,并设置用户信息。

1
2
3
4
5
$ git clone git@github.com:docker_user/blockchain_guide.git
$ cd blockchain_guide
$ #do some change on the content
$ git commit -am "Fix issue #1: change helo to hello"
$ git push
阅读全文 »

iOS使用openAL控制声音的输出设备

项目中播放ios录音的时候使用的是AVAudio相关库, 播放音效又是用的openAL.
如果同时或交替播放这两类声音, 会造成声音一会从听筒发声,一会从扬声器发声.
千辛万苦找到解决方案:

1
2
3
4
5
6
7
8
9
10
Interesting enough, it can be done!

Basically you add a property listener to get route change events:
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback,0);

Then in the callback, determine if its a headphone being plugged-in and override the audio route:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);

Too simple...

iOS AVAudioSession 监听静音开关

录音使用AVAudioSession播放的时候, 无法识别Iphone手机的物理静音开关,需要修改下模式

1
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

修改成

1
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];//监听静音

vector deque

在使用 vector、deque遍历删除元素时,也可以通过erase的返回值来获取下一个元素的位置:

1
2
3
4
5
6
7
8
9
10
11
std::vector<int> Vec;
std::vector<int>::iterator itVec;
for( itVec = Vec.begin(); itVec != Vec.end(); )
{
if( WillDelete( *itVec) )
{
itVec = Vec.erase( itVec);
}
else
itList++;
}
阅读全文 »

问题提出:有一个模板函数,函数在处理int型和double型时需要进行特殊的处理,那么怎么在编译期知道传入的参数的数据类型是int型还是double型呢?
如:

1
2
3
4
5
6
7
#include <iostream>
template <typename TYPE>
void typeCheck(TYPE data)
{
//do something check data type
//std::cout<< out put the type
}

这里就需要用到C++11的type_traits头文件了,type_traits头文件定义了很多类型检查相关的方法,上面的例子具体用到了其中两个结构:

阅读全文 »

1. git 基础

1.1 git的基础操作

  1. 命令git add 把文件添加到仓库

  2. 命令git commit 把文件提交到仓库

  3. 命令git pull 把远程仓库拉取文件

  4. 命令git push 把文件提交到远程仓库

  5. 命令git log 查看git提交日志

  6. 如果嫌输出信息太多, 可以加上–pretty=oneline参数. 另外也可以花式log输出, git lg查看下

    1
    git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
  7. 命令git diff 查看版本之间文件修改变化

    1
    git diff 87b91b6 f9b3075 [--name-only]加上可以只看文件名字
阅读全文 »