Skip to content

Instantly share code, notes, and snippets.

Avatar

Maksim Krylosov makryl

View GitHub Profile
@makryl
makryl / emscripten_localStorage_fs.js
Last active Sep 19, 2020
Synchronous LocalStorage file system for Emscripten
View emscripten_localStorage_fs.js
var Module = {
// ...
preInit: [
function() {
// create LSFS and mount 'data' local storage item into '/data' directory
FS.createFolder(FS.root, 'data', true, true);
FS.mount(LSFS(), { key: 'data' }, '/data');
}
]
};
@makryl
makryl / sanity-test2.js
Last active Feb 28, 2017
test node webrtc connections limit
View sanity-test2.js
var webrtc = require('..');
var RTCPeerConnection = webrtc.RTCPeerConnection;
var RTCSessionDescription = webrtc.RTCSessionDescription;
var RTCIceCandidate = webrtc.RTCIceCandidate;
var total = 0;
var limit = parseInt(process.argv[process.argv.length - 1]) || 1;
for (var i = 0; i < limit; i++) {
@makryl
makryl / gist:9092213
Last active Feb 23, 2020
file_get_contents with detect any UTF or one specified 8-bit encoding (default Windows-1251)
View gist:9092213
<?php
file_get_contents_utf_ansi($filename, $defAnsiEnc = 'Windows-1251')
{
$buf = file_get_contents($filename);
if (substr($buf, 0, 3) == "\xEF\xBB\xBF") return substr($buf,3);
else if (substr($buf, 0, 2) == "\xFE\xFF") return mb_convert_encoding(substr($buf, 2), 'UTF-8', 'UTF-16BE');
else if (substr($buf, 0, 2) == "\xFF\xFE") return mb_convert_encoding(substr($buf, 2), 'UTF-8', 'UTF-16LE');
else if (substr($buf, 0, 4) == "\x00\x00\xFE\xFF") return mb_convert_encoding(substr($buf, 4), 'UTF-8', 'UTF-32BE');
You can’t perform that action at this time.