Skip to content

Instantly share code, notes, and snippets.

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;
@motoishmz
motoishmz / ofXml_to_std::wstring.h
Last active October 22, 2018 02:08
openframeworks example: convert std::string with an external file --> std::wstring
#include <codecvt>
#include "ofxTrueTypeFontUL2.h" // https://github.com/kentaroid/ofxTrueTypeFontUL2
std::wstring text;
ofxTrueTypeFontUL2 typeface;
void ofApp::setup() {
ofXml xml("multilingual_words.xml"); // have to be saved as UTF-8 with BOM
// do something with xml...
std::string text_from_xml = xml.getAttribute("my_chinese_word");
@kidapu
kidapu / ofApp.h
Created February 23, 2016 11:50
base64 decode + encode sample
// reference : https://gist.github.com/satoruhiga/1687325
#pragma once
static int WIDTH = 300;
static int HEIGHT = 300;
#include "ofMain.h"
#include "Poco/Base64Encoder.h"
@talltyler
talltyler / gist:5345894
Created April 9, 2013 14:01
This code gives the HTML canvas element JavaScript support for letter spacing. Don't confuse letter spacing with kerning http://en.wikipedia.org/wiki/Kerning This code is basically from http://stackoverflow.com/a/15509006
(function(){
var _fillText,
__slice = [].slice;
_fillText = CanvasRenderingContext2D.prototype.fillText;
CanvasRenderingContext2D.prototype.fillText = function() {
var args, offset, previousLetter, str, x, y,
_this = this;
@gre
gre / easing.js
Last active December 7, 2025 08:36
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {