Skip to content

Instantly share code, notes, and snippets.

View sqbing's full-sized avatar

Rider Woo sqbing

  • Microsoft
  • Suzhou, Jiangsu, China
View GitHub Profile
@sqbing
sqbing / setprocname.c
Created October 17, 2013 08:36
Set process name in Linux/Mac.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int setproctitle(const char ***ppp_argv, const char *title)
{
int i = 0;
int size = 0;
const char **pp_argv = *ppp_argv;
@sqbing
sqbing / fft.cpp
Created January 20, 2014 08:01
Segment fault with Aquila::OouraFft::ifft()
#include <iostream>
#include <aquila/global.h>
#include <aquila/source/WaveFile.h>
#include <aquila/tools/TextPlot.h>
#include <aquila/transform/FftFactory.h>
#include <algorithm>
#include <cstdlib>
int main(int argc, const char *argv[])
{
@sqbing
sqbing / GetPartitionSize.c
Created April 15, 2014 01:29
Get Partition Size
#include <stdio.h>
#include <sys/vfs.h>
#include <string.h>
#include <errno.h>
int main(int argc, const char *argv[])
{
if(argc < 2){
printf("%s PATH\n", *argv);
return 0;
loginResponse: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tornado/web.py", line 1141, in _when_complete
callback()
File "/Library/Python/2.7/site-packages/tornado/web.py", line 1162, in _execute_method
self._when_complete(method(*self.path_args, **self.path_kwargs),
File "/Library/Python/2.7/site-packages/tornado/web.py", line 183, in post
raise HTTPError(405)
HTTPError: HTTP 405: Method Not Allowed
- (void)doLogin{
// 发送登陆表单
NSURL *url = [NSURL URLWithString:@"http://www.v2ex.com/signin"];
loginRequest = [ASIFormDataRequest requestWithURL:url];
[loginRequest addPostValue:username forKey:@"u"];
[loginRequest addPostValue:password forKey:@"p"];
[loginRequest addPostValue:once forKey:@"once"];
[loginRequest addPostValue:@"/" forKey:@"next"];
[loginRequest setUserAgentString:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36"];
[loginRequest setShouldRedirect:NO];
@sqbing
sqbing / demuxing.c
Created September 24, 2014 05:42
demuxing media file
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
static AVFormatContext *fmt_ctx = NULL;
static AVCodecContext *video_dec_ctx = NULL, *audio_dec_ctx;
static AVStream *video_stream = NULL, *audio_stream = NULL;
static const char *src_filename = NULL;
@sqbing
sqbing / mediainfo.cc
Last active August 29, 2015 14:06
libmedia example
#define UNICODE
#include <iostream>
#include <string>
#include <MediaInfo/MediaInfo.h>
#include <MediaInfo/MediaInfo_Const.h>
// Taking effect only for ascii charactors
void string_to_wstring(std::string &str, std::wstring &wstr){
wstr = std::wstring(str.begin(), str.end());
}
@sqbing
sqbing / crc32.c
Created September 24, 2014 05:56
crc32 example
#include <stdio.h>
#include <stdint.h>
static uint32_t crc32table[256] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
@sqbing
sqbing / md5.c
Created September 24, 2014 05:59
md5 encoding example
#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
#define u_char unsigned char
int main(int argc, const char *argv[])
{
u_char hashb[64], hasht[128], *text = hasht;
MD5_CTX md5;
@sqbing
sqbing / zmq_instance.cc
Created September 24, 2014 06:03
zmq example
#include <iostream>
#include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/any.hpp>
#include <inttypes.h>
#include <signal.h>
#ifdef __cplusplus
extern "C"{
#endif