Skip to content

Instantly share code, notes, and snippets.

🤓
Keep working...

Wasin Thonkaew haxpor

🤓
Keep working...
Block or report user

Report or block haxpor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@haxpor
haxpor / aligned_allocator.cpp
Created Sep 27, 2019 — forked from donny-dont/aligned_allocator.cpp
An aligned allocator for placing SIMD types in std::vector
View aligned_allocator.cpp
#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>
/**
* Allocator for aligned data.
@haxpor
haxpor / gen100.cpp
Last active Sep 16, 2019
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
View gen100.cpp
/**
* 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 Sep 14, 2019
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.
View genprogress.cpp
/**
* 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 Sep 2, 2019
"std::vector" won't use your class's move unless it's marked noexcept. https://stackoverflow.com/a/10788136/571227
View stl_vector.h
#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 Sep 2, 2019
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.
View gist:a3ed3172ffc780b0c923091726d0eb94
//@{
/**
* @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 Aug 24, 2019
Demonstrate hiding structure layout to public but still allow access.
View StructPb.cpp
#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 Aug 21, 2019
Boiler-plate code for QDialog, QMainWindow, and QWidget. Based on Qt 5.13.
View Dialog.cpp
#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 Aug 15, 2019
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"
View SimpleDownloaders_future.cpp
/** 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 Aug 15, 2019
Example of writing extension with c++ for python with cpython.
View README.md

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 Jul 27, 2019
Note on package requirement automatically installed by Setup.sh script of ue 4.18
View dep.txt
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
You can’t perform that action at this time.