Skip to content

Instantly share code, notes, and snippets.

View Akira-Hayasaka's full-sized avatar
🏠
Working from home

Akira Hayasaka Akira-Hayasaka

🏠
Working from home
View GitHub Profile
auto get_bbox = [](const vector<ofVec2f> pts) -> ofRectangle
{
auto xpair = std::minmax_element(pts.begin(), pts.end(),
[](const ofVec2f& a, const ofVec2f& b) {
return a.x < b.x;
});
auto ypair = std::minmax_element(pts.begin(), pts.end(),
[](const ofVec2f& a, const ofVec2f& b) {
return a.y < b.y;
});
@Akira-Hayasaka
Akira-Hayasaka / get_buf_from_img.cpp
Created June 7, 2019 07:19
ofImage to ofBuffer
auto get_buf_from_img = [](ofPixels& img, ofBuffer& buf, ofImageFormat fmt) -> ofBuffer
{
buf.clear();
ofSaveImage(img, buf, fmt);
return buf;
};
@Akira-Hayasaka
Akira-Hayasaka / hex_str_to_int.cpp
Created January 18, 2019 01:44
hex_str_to_int
std::stoul("0x" + s, nullptr, 16)
auto conv_utf8_to_sjis = [](string srcUTF8) -> string
{
int lenghtUnicode = MultiByteToWideChar(CP_UTF8, 0, srcUTF8.c_str(), srcUTF8.size() + 1, NULL, 0);
wchar_t* bufUnicode = new wchar_t[lenghtUnicode];
MultiByteToWideChar(CP_UTF8, 0, srcUTF8.c_str(), srcUTF8.size() + 1, bufUnicode, lenghtUnicode);
int lengthSJis = WideCharToMultiByte(CP_THREAD_ACP, 0, bufUnicode, -1, NULL, 0, NULL, NULL);
char* bufShiftJis = new char[lengthSJis];
WideCharToMultiByte(CP_THREAD_ACP, 0, bufUnicode, lenghtUnicode + 1, bufShiftJis, lengthSJis, NULL, NULL);
string strSJis(bufShiftJis);
delete bufUnicode;
@Akira-Hayasaka
Akira-Hayasaka / main.cpp
Created July 11, 2018 05:00
no console
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
#include "ofMain.h"
#include "ofApp.h"
int main()
{
ofGLWindowSettings glWindowSettings;
glWindowSettings.setGLVersion(2, 1);
glWindowSettings.width = 1920;
@Akira-Hayasaka
Akira-Hayasaka / win_send_window_back
Created February 19, 2018 21:00
send window to back
HWND AppWindow = GetActiveWindow();
SetWindowPos(AppWindow, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
//
// TheradedVLCPlayerEx.cpp
// ofxVLCVideoPlayerExample
//
// Created by Akira Hayasaka on 2017/01/16.
//
//
#include "TheradedVLCPlayerEx.hpp"
@Akira-Hayasaka
Akira-Hayasaka / get_bit_flag.cpp
Created September 14, 2017 21:23
get bit flag
vector<string> get_signed_char(const char byte)
{
vector<string> busy_state;
for (auto i = 7; i >= 0; i--)
{
busy_state.push_back(ofToString((byte>>i) & 1));
}
std::reverse(begin(busy_state), end(busy_state));
return busy_state;
}
vk1D::LCtrl
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; NEEDS '*' because LCtrl key-repeat is otherwise interpreted as ALT+LCtrl.
*LCtrl::
CtrlTabbed := false`
@Akira-Hayasaka
Akira-Hayasaka / gcd_lcm.cpp
Created May 16, 2017 05:08
greatest common divisor & least common multiple
static int getGCD(int a, int b) // greatest common divisor
{
if (a == 0)
return b;
return getGCD(b%a, a);
}
static int getLCM(int a, int b) // least common multiple
{
return abs(a * b) / getGCD(a, b);