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
#ifndef _VISION_PLAY_ARMV6_ATOMIC_H_ | |
#define _VISION_PLAY_ARMV6_ATOMIC_H_ | |
#if defined(__ARMEL__) && defined(__linux__) | |
typedef void (*LinuxKernelMemoryBarrierFunc)(void); | |
// Using the highly optimized device-specific memory barrier function. | |
inline void MemoryBarrier() { | |
(*(LinuxKernelMemoryBarrierFunc)0xffff0fa0)(); |
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> | |
using namespace std; | |
void swap(int* a, int* b) { | |
int tmp = *a; | |
*a = *b; | |
*b = tmp; | |
} | |
void Perm(int m, int n, int* A) { |
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
# baidu realtime hotspot | |
curl http://top.baidu.com/buzz.php?p=top10 \ | |
| perl -MEncode -pi -e '$_=encode_utf8(decode(gb2312=>$_))' \ | |
| grep "td class=\"key\"" | sed -e 's/^.*_blank\">//g' | sed -e 's/<.*$//g' | |
# sogou top queries | |
curl http://top.sogou.com/hotword[0-3].html \ | |
| perl -MEncode -pi -e '$_=encode_utf8(decode(gb2312=>$_))' \ | |
| perl -ne 'chomp; my @titles = ($_ =~ /title=\".*?\"/g); for (my $i = 0; $i < scalar @titles; ++$i) {$titles[$i] =~ s/title=//; $titles[$i] =~ s/\"//g; print "$titles[$i]\n"}' |
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
There is no an efficient StringBuilder class in C++ std library. std::ostringstream could be used as StringBuilder, but it is inefficient, and it use C++ iostream interface, which was proved a bad practice than printf family in C, although it is more "flexible" than printf family. Here are 2 thin wrapper for gnu asprintf family, which maybe more efficient and more readable than ostringstream. | |
strbuilder.h | |
// strbuilder.h | |
#include <stdio.h> | |
#include <string.h> | |
// This class is more simple to use, but it should be used for one-time printf |
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
sub levenshtein_dist { | |
my ($str1, $str2) = @_; | |
my ($len1, $len2) = (length $str1, length $str2); | |
if ($len1 == 0) { | |
return $len2; | |
} | |
if ($len2 == 0) { |