A simple structure to hold 2d uint8 arrays in C that can be easily adjusted to hold other things in other dimensions.
Usage is as follows:
struct uint8_tensor * t = create_tensor(2, 2);
t->set(t, 0, 0, 0);
t->set(t, 0, 1, 1);| function getMimeTypeFromExtension(extension = "txt") { | |
| if (extension[0] === ".") { | |
| extension = extension.substr(1); | |
| } | |
| return { | |
| "aac": "audio/aac", | |
| "abw": "application/x-abiword", | |
| "arc": "application/x-freearc", | |
| "avi": "video/x-msvideo", | |
| "azw": "application/vnd.amazon.ebook", |
| /** | |
| * Returns a UTC-3 datetime string from a given date object | |
| * @param {Date} date The date to retrieve the string from (default current date) | |
| * @returns {'2021-07-29 23:37:25' | string} A string in the format "yyyy/mm/dd hh:mm:ss" | |
| */ | |
| function getBrazilianDateTimeString(date = new Date()) { | |
| date.setTime(date.getTime() - 3 * 60 * 60 * 1000); | |
| return date.toISOString().replace("T", " ").split(".")[0]; | |
| } |
| <?php | |
| function getBrazilStateFromZipCode($cep = '') { | |
| $cepNum = intval(preg_replace("/[^0-9]/", "", $cep)); | |
| if ($cepNum >= 69900000 && $cepNum <= 69999999) { | |
| return "AC"; | |
| } else if ($cepNum >= 57000000 && $cepNum <= 57999999) { | |
| return "AL"; | |
| } else if ($cepNum >= 69000000 && $cepNum <= 69299999) { | |
| return "AM"; |
| export function generateJSDocsFromObj(obj) { | |
| if (typeof obj !== "object") { | |
| return typeof obj; | |
| } | |
| if (obj instanceof Array) { | |
| if (obj.length <= 0) { | |
| return "any[]"; | |
| } else { | |
| return generateJSDocsFromObj(obj[0]); | |
| } |
| // adapted from c++ on stackoverflow: https://stackoverflow.com/a/57210516/5974331 | |
| // opens a new console windows for the current process | |
| // returns 1 on success | |
| int CreateConsole() { | |
| if (!AllocConsole()) { | |
| return 0; | |
| } | |
| FILE *fDummy; | |
| freopen_s(&fDummy, "CONIN$", "r", stdin); |
| // Warning: undefined behaviour if the network interface does not have an IP (might fail or might return the next interface ip) | |
| function getNetworkAdapterIp(adapter_name = "Adaptador de Rede sem Fio Wi-Fi", ip_version = 4, cp = require("child_process")) { | |
| process.stdout.setEncoding('utf-8'); | |
| /** @type {Buffer} */ | |
| const ipconfig_output = cp.spawnSync("C:\\Windows\\System32\\ipconfig.exe", ["/all"]).output[1]; | |
| const adapter_config = ipconfig_output.toString("utf-8").split(adapter_name + ":")[1]; | |
| if (!adapter_config) { | |
| return "ERROR - could not find adapter on output:\n" + (JSON.stringify(ipconfig_output.toString("utf-8"))); | |
| } else { |
| const b = (i, j, k) => i + (j - i) * k; | |
| const ib = (i, j, k) => (k - i) / (j - i); | |
| // clamped (limit return to be between i and j parameters) | |
| const _b = (i, j, k) => k < 0 ? i : (k > 1 ? j : i + (j - i) * k); | |
| const _ib = (i, j, k) => k < i ? 0 : (k > 1 ? j : (k - i) / (j - i)); | |
| /* | |
| b(0, 1, 0) === 0 | |
| b(0, 1, 1) === 1 | |
| b(5, 10, 0.5) === 7.5 |
| #include <stdio.h> // snprintf | |
| #include <windows.h> // wchar | |
| // Convert a WIDE CHAR ARRAY (wchar *) into a CHAR ARRAY (char *) in a memory safe way. | |
| // Handles unicode characters by writing \uXXXX exactly like C compilers and JSON parsers. | |
| int convert_wchar_array_to_char_array(const WCHAR * input, char * output, size_t output_buffer_size) { | |
| if (input == NULL || output == NULL || sizeof(WCHAR) != 2) { | |
| return 0; | |
| } | |
| if (output_buffer_size <= 0) { |
| var sigmoid_lookup_size = 128; | |
| var sigmoid_lookup = (new Float32Array(sigmoid_lookup_size+1)).map((a,i) => 1/(1+Math.exp(-(i-(sigmoid_lookup_size/2))/(sigmoid_lookup_size/32)))); | |
| function real_sigmoid(x) { | |
| return 1 / (1 + Math.exp(-x)); | |
| } | |
| function cached_sigmoid(x) { | |
| if (x < -16) { |