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
std::vector<std::string> | |
sorted(std::vector<std::string> names) | |
{ | |
std::sort(names); | |
return names; | |
} | |
// names is an lvalue; a copy is required so we don't modify names | |
std::vector<std::string> sorted_names1 = sorted( names ); | |
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
std::shared_ptr<widget> get_widget(int id) | |
{ | |
static std::map<int, std::weak_ptr<widget>> cache; | |
static std::mutex m; | |
std::lock_guard<std::mutex> hold(m); | |
auto& wp = cache[id]; | |
auto sp = wp.lock(); | |
if (!sp) | |
{ |
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
class Stopwatch { | |
using clock = std::chrono::high_resolution_clock; | |
bool is_running() const { return stop_time_ == clock::time_point::min(); } | |
clock::time_point end_time() const { return is_running() ? clock::now() : stop_time_; } | |
clock::time_point begin_time_{clock::now()}, stop_time_{clock::time_point::min()}; | |
public: | |
void stop() { if (is_running()) stop_time_ = clock::now(); } | |
clock::duration elapsed() const { return end_time() - begin_time_; } | |
}; |
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
bool isNumeric(const std::string& input) | |
{ | |
return std::all_of(input.begin(), input.end(), ::isdigit); | |
} |
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
NSString* file = [[NSString alloc] initWithUTF8String:pth.c_str()]; | |
CGImageRef image = [UIImage imageWithContentsOfFile:file].CGImage; | |
[file release]; | |
m_width = CGImageGetWidth(image); | |
m_height = CGImageGetHeight(image); | |
m_poww = std::max<int>(math::high_pow2(m_width), 16); | |
m_powh = std::max<int>(math::high_pow2(m_height), 16); | |
int pitch = m_poww * 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
#!/bin/bash | |
# apply | |
codesign -f -s "iPhone Developer" -v MyApp.app | |
# check it | |
codesign -d --entitlements - MyApp.app |
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 <future> | |
class wait_event | |
{ | |
std::condition_variable cond; | |
std::mutex m; | |
public: | |
void signal() | |
{ | |
std::lock_guard<std::mutex> lock(m); |
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
// Dr. Dobb's | |
// Generalizing Observer By Herb Sutter | |
// http://www.drdobbs.com/cpp/generalizing-observer/184403873 | |
// | |
#pragma once | |
#include <list> | |
#include <functional> |
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
std::string string_format(const char* s, ...) | |
{ | |
va_list args; | |
va_start(args, s); | |
std::string result; | |
int len = vsnprintf(nullptr, 0, s, args); | |
if (len > 0) | |
{ |
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
git config --global push.default tracking |
OlderNewer