Skip to content

Instantly share code, notes, and snippets.

@ssendeavour
ssendeavour / Qt Layout and Slot.cpp
Last active December 15, 2015 12:39
Gt QHBoxLayout and slot example C++
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
#include <QtGui/QSpinBox>
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
## from http://askubuntu.com/questions/9135/best-way-to-backup-all-settings-list-of-installed-packages-tweaks-etc
dpkg --get-selections > ~/Package.list
sudo cp /etc/apt/sources.list ~/sources.list
sudo apt-key exportall > ~/Repo.keys
rsync --progress /home/`whoami` /path/to/user/profile/backup/here
## Reinstall now
rsync --progress /path/to/user/profile/backup/here /home/`whoami`
@ssendeavour
ssendeavour / detect-encoding-ython-chardet.py
Last active December 18, 2015 17:39
detect encoding of string in python
import chardet
chardet.detect('something中文Chinese')
@ssendeavour
ssendeavour / turn-off-screen.sh
Created September 27, 2013 12:18
Turn Off Screen (Works in Ubuntu 12.04.3)
xset dpms force off
@ssendeavour
ssendeavour / copy-recursively.cpp
Created November 5, 2013 19:28
Copy file and directories recursively in Qt
//https://qt.gitorious.org/qt-creator/qt-creator/source/1a37da73abb60ad06b7e33983ca51b266be5910e:src/app/main.cpp#L13-189
// taken from utils/fileutils.cpp. We can not use utils here since that depends app_version.h.
static bool copyRecursively(const QString &srcFilePath,
const QString &tgtFilePath)
{
QFileInfo srcFileInfo(srcFilePath);
if (srcFileInfo.isDir()) {
QDir targetDir(tgtFilePath);
targetDir.cdUp();
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
@ssendeavour
ssendeavour / PrintCurrentDateTime.cpp
Created July 12, 2014 13:46
print current date and time in Windows Visual Studio 2013 with C++11 chrono
#include <chrono>
#include <iomanip>
#include <ctime>
void PrintLocalTime()
{
std::tm tmNow;
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
time_t t = std::chrono::system_clock::to_time_t(now);
@ssendeavour
ssendeavour / timing.cpp
Created July 12, 2014 14:43
Timing class using C++ 11 and chrono, used to measure time
#include "Timing.h"
double Timing::getEllipsedMilliseconds()
{
if (m_running)
{
setToCurrentTime(m_endTime);
}
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(m_endTime - m_startTime).count()) / 1000000.0;
}
@ssendeavour
ssendeavour / GetLastError.cpp
Created July 23, 2014 15:01
show Windows API error text corresponding to number retured by GetLastError. source: http://msdn.microsoft.com/en-us/library/windows/desktop/bb540534(v=vs.85).aspx
void DisplayError(LPTSTR lpszFunction)
// Routine Description:
// Retrieve and output the system error message for the last-error code
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
@ssendeavour
ssendeavour / redirect-stdout-and-stderr-through-pipe-with-tee.bash
Created April 15, 2015 15:22
How do I write stderr to a file while using “tee” with a pipe?
# stackoverflow.com/questions/692000/how-do-i-write-stderr-to-a-file-while-using-tee-with-a-pipe
command_to_execute 2>&1 | tee -a log
# in bash 4
command_to_execute |& tee -a log