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);| // | |
| // | |
| // Works both on windows and linux | |
| // | |
| // | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <fcntl.h> | |
| #include <errno.h> |
| // Incomplete source for a program that computes a root of a polynomial of any size with a guessing-based approach | |
| // | |
| // File: approximate-root | |
| // Compilation: gcc -o main approximate-root.c | |
| // Run: ./main | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| double get_value_of_n_degree_polynomial(double x, double *coeficients, int coeficients_length) { |
| /* | |
| Simple http server (with multiple connections) | |
| */ | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <arpa/inet.h> | |
| #include <sys/socket.h> | |
| #include <sys/wait.h> |
| <?php | |
| // Ever needed to test an application that uses Memcache but didn't have it installed locally? | |
| // This class saves its information to a local folder named "data" with the raw data passed to it. | |
| // Each different key saved creates a new file on your system. | |
| // Currently the only methods supported are Memcache::get and Memcache::set. | |
| /** | |
| * A class that mimicks the Memcache php dependency minimalistically by saving data to local storage. |
| 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) { |
| #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) { |
| 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 |
| // 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 { |
| // 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); |