This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3] | |
[1, next] -> [2, next] -> [3, next] -> null | |
struct Node { | |
public: | |
int data; | |
Node* next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function sleep(ms:number):Promise<void> { | |
return new Promise<void>((resolve:any) => setTimeout(resolve, ms)); | |
} | |
export async function crop(image:HTMLImageElement, x:number, y:number, width:number, height:number, image_type:string = "image/png", recurs_depth:number = 0):Promise<HTMLImageElement> | |
{ | |
const canvas = document.createElement("canvas"); | |
if(image && image.height && image.width) | |
{ | |
canvas.width = image.width; | |
canvas.height = image.height; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <fstream> | |
#include <array> | |
#include <exception> | |
#include <string> | |
#include <iostream> | |
#include <cmath> | |
#include <random> | |
#include <thread> | |
#include <mutex> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function blendAlphaCopy(color0:RGB, color:RGB):void | |
{ | |
const alphant:number = color0.alphaNormal(); | |
const alphanc:number = color.alphaNormal(); | |
const a:number = (1 - alphanc); | |
const a0:number = (alphanc + alphant * a); | |
const a1:number = 1 / a0; | |
color0.color = (((alphanc * color.red() + alphant * color0.red() * a) * a1)) | | |
(((alphanc * color.green() + alphant * color0.green() * a) * a1) << 8) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* CrossPlatform.hpp | |
* | |
* Created on: Jan 11, 2021 | |
* Author: andrewrubinstein | |
*/ | |
#ifndef CROSSPLATFORM_HPP_ | |
#define CROSSPLATFORM_HPP_ | |
#include <inttypes.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Makefile for conway/SDL2 | |
# | |
CC = g++ | |
CXX = g++ | |
INCLUDE = -I/usr/local/include/SDL | |
CFLAGS = | |
CXXFLAGS = -O3 -std=c++2a $(INCLUDE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <iostream> | |
#include <string_view> | |
#include <exception> | |
bool isOperator(char c) noexcept | |
{ | |
return (c == '*' | c == '/' | c == '+' | c == '-'); | |
} | |
bool is_digit(unsigned char c) noexcept | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
int main() | |
{ | |
//extend this calculator to be able to evaluate eny postfix expression | |
//building a simple calculator | |
std::string input("2 3 -"); | |
std::stringstream tokens(input); | |
int a = 0, b = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <array> | |
#include <iostream> | |
void naive_solution(std::string &left, std::string &right) | |
{ | |
for(int i = 0; i < right.length(); i++) | |
{ | |
//to check if the given character in the right matches any character in the left | |
for(int j = 0; j < left.length(); j++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jobs = 1200; | |
const example_input = 27; | |
const threads = 16; | |
const example = async () => { | |
const pool = new ProcessPool<number, number>(Math.floor(threads), (input:number) => { | |
let fib = (x:number) => x <=1 ? x : fib(x-1) + fib(x-2); | |
return fib(input); | |
}, [], []); | |
const input:number[] = []; |
NewerOlder