This file contains hidden or 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
| // Example output from this code: | |
| // Tue Jan 13 12:09:53 2015 (from ctime) | |
| // 20150113_12_09_53 (from strftime) | |
| // 20150113_12_09_53 (from put_time) | |
| #include <ctime> | |
| #include <chrono> | |
| #include <iomanip> | |
| // Get current time |
This file contains hidden or 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
| Windows Registry Editor Version 5.00 | |
| [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] | |
| "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,00,00,3a,00,00,00,00,00 |
This file contains hidden or 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
| // Checking for math error in C++ | |
| #include <cerrno> | |
| #include <cmath> | |
| #include <cstring> | |
| #include <iostream> | |
| std::cout << log(0) << std::endl; | |
| if (errno) | |
| std::cout << std::strerror(errno) << std::endl; |
This file contains hidden or 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 to execute a function in parallel across multiple data | |
| # Adapted from code in Sec 9.5 of book Python Cookbook (2 Ed) | |
| import threading | |
| import time | |
| import Queue | |
| class MultiThread(object): | |
| def __init__(self, function, argsVector, commonArgs, maxThreads=5, queue_results=False): |
This file contains hidden or 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
| # Sample code to write data of certain format to binary file | |
| # For details of parameters passed to pack method see: | |
| # https://docs.python.org/2/library/struct.html | |
| import struct | |
| # Assume these are values of fields of a class/struct in C/C++ | |
| a = 1 # unsigned int | |
| b = 2 # signed char | |
| c = -1 # signed int |
This file contains hidden or 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
| # Helps define a constant in Python | |
| # From Section 6.3: Defining Constants | |
| # Python Cookbook (2 Ed) by Alex Martelli et al. | |
| # | |
| # Usage: | |
| # import const | |
| # const.magic = 23 # First binding is fine | |
| # const.magic = 88 # Second binding raises const.ConstError | |
| class _const: |
This file contains hidden or 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
| // Sample code to demonstrate emplace_back operation of vector | |
| #include <iostream> | |
| #include <vector> | |
| struct Creature | |
| { | |
| Creature() : is_mammal_(false), age_(0), population_(0) | |
| { | |
| std::cout << "Default constructor called\n"; |
This file contains hidden or 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
| # Check if Qt4 is present | |
| find_package(Qt4 REQUIRED) | |
| # Add Qt headers for compiling | |
| include( | |
| ${QT_USE_FILE} | |
| ) | |
| # Add Qt definitions for compilation | |
| add_definitions( |
This file contains hidden or 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
| # Add this to your ~/.config/fish/config.fish | |
| function ranger-cd | |
| set tmpfile "/tmp/pwd-from-ranger" | |
| ranger --choosedir=$tmpfile $argv | |
| set rangerpwd (cat $tmpfile) | |
| if test "$PWD" != $rangerpwd | |
| cd $rangerpwd | |
| end | |
| end |