Skip to content

Instantly share code, notes, and snippets.

View haxpor's full-sized avatar
🤓
Some of my financial tools https://www.mql5.com/en/users/haxpor/seller

Wasin Thonkaew haxpor

🤓
Some of my financial tools https://www.mql5.com/en/users/haxpor/seller
View GitHub Profile
@haxpor
haxpor / aligned_allocator.cpp
Created September 27, 2019 09:56 — forked from donny-dont/aligned_allocator.cpp
An aligned allocator for placing SIMD types in std::vector
#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>
/**
* Allocator for aligned data.
@haxpor
haxpor / gen100.cpp
Last active September 16, 2019 16:15
Simple program to generate N random numbers into standard output. You can pipe output from program into file manually. Example: echo 50 | ./a.out > random.txt
/**
* Input: n - number of random numbers to generate
* Output: n random numbers printed onto standard output separated by a space.
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
@haxpor
haxpor / genprogress.cpp
Created September 14, 2019 15:10
Generation of progress for UVa problem set. Use input.txt as input executing genprogress.cpp program. You can pipe the output to an actual .md file later.
/**
* Generation of UVa's progress in markdown file.
*
* Input:
* A problem set number separated by a new line, each set will contains 100 problems with number running
* from it to a hundred. Terminate with 0 at the last line.
*
* 1
* 19
* 201
@haxpor
haxpor / stl_vector.h
Created September 2, 2019 16:10
"std::vector" won't use your class's move unless it's marked noexcept. https://stackoverflow.com/a/10788136/571227
#if __cplusplus >= 201103L
private:
// Constant-time move assignment when source object's memory can be
// moved, either because the source's allocator will move too
// or because the allocators are equal.
void
_M_move_assign(vector&& __x, std::true_type) noexcept
{
vector __tmp(get_allocator());
this->_M_impl._M_swap_data(__tmp._M_impl);
@haxpor
haxpor / gist:a3ed3172ffc780b0c923091726d0eb94
Last active September 2, 2019 15:04
non-member function overloading an operator. Example defined in ostream to work with primitive normal types, which be idea to expand for user-defined object to output it into output stream. Excerpted from ostream header. See https://www.quora.com/What-are-the-differences-between-a-member-operator-function-and-a-friend-operator-function.
//@{
/**
* @brief String inserters
* @param __out An output stream.
* @param __s A character string.
* @return out
* @pre @p __s must be a non-NULL pointer
*
* Behaves like one of the formatted arithmetic inserters described in
* std::basic_ostream. After constructing a sentry object with good
@haxpor
haxpor / StructPb.cpp
Created August 24, 2019 03:19
Demonstrate hiding structure layout to public but still allow access.
#include <iostream>
#include <string>
struct PublicData
{
int a;
float b;
// private data
// this is a technique to hide the struct information thus users won't be able to know its layout
@haxpor
haxpor / Dialog.cpp
Created August 21, 2019 08:57
Boiler-plate code for QDialog, QMainWindow, and QWidget. Based on Qt 5.13.
#include "Dialog.h"
#include "ui_Dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
@haxpor
haxpor / SimpleDownloaders_future.cpp
Last active April 5, 2022 08:22
C++ studying of parallel + multithreading (c++11) following https://www.youtube.com/watch?v=_z-RS0rXg9s with some differences. Compile with "g++ -std=c++11 SimpleDownloader.cpp -lpthread -lcurl"
/** Downloader app following https://www.youtube.com/watch?v=_z-RS0rXg9s but
* use libcurl (C API) with some adjusted API usage.
*
* Compile with
* g++ -std=c++11 -DNO_PROXY SimpleDownloader.cpp -lpthread -lcurl
* */
#include <iostream>
#include <fstream>
#include <string>
@haxpor
haxpor / README.md
Created August 15, 2019 08:14
Example of writing extension with c++ for python with cpython.

How to build

  • python3 setup.py build
  • From current directory, cd build/lib.linux-x86_64-3.6 (tested on Ubuntu 18.04 with python 3.6.7).
  • python3 to enter interactive mode
  • import spam
  • spam.system('ls -la') then it should print the current directory listing as output
@haxpor
haxpor / dep.txt
Created July 27, 2019 03:59
Note on package requirement automatically installed by Setup.sh script of ue 4.18
libmono-system-web-extensions4.0-cil
install -y libmono-system-data-datasetextensions4.0-cil
libmono-csharp4.0c-cil libmono-microsoft-csharp4.0-cil mono-dmcs mono-mcs
mono-dmcs
mono-xbuild
mono-devel
libmono-system-runtime4.0-cil
libmono-system-io-compression-filesystem4.0-cil
libmono-system-io-compression4.0-cil
libmono-windowsbase4.0-cil