instruction stringlengths 71 95.1k |
|---|
Just looking for opinions on which is the best way to use exceptions?
Should the exception handling go inside the function or should it go outside the function when you actually call the function. For example, we could have the following function:
def divideMe(a,b):
return a/b
This function is risky because ther... |
I'm working on a Remote Admin Tool (nicknamed Wraith) which works over HTTP. The code is ugly so far but I'm mainly worried about performance and robustness.
Can anyone offer any suggestions as to how to optimise this code and make it more robust?
(I realise Python is a slow and heavy language but surely this program d... |
I'm creating a class library to read/write .3di files which are binary files describing 3D models for a video game. This review is for the write/serialization process.
I've mapped the different structures in the .3di file (header, textures, vertices, etc.) to the classes shown below. Each class implements the IBinarySe... |
I am trying to merge multiple pandas data-frames that I read from a file.
Here is the function I wrote:
def merge_files(args):
list_df = {}
with args.input as data_in:
for line in data_in:
line = line.strip()
df = pd.read_csv(line, sep="\s+")
df.drop_duplicates(inpla... |
I am learning React and wanted to implement a todo app using function components. Any suggestions and criticism is welcome, especially regarding best practices.
import React, {useState} from 'react';
class Todo {
constructor(id, description, complete) {
this.id = id;
this.description = description;
this.... |
I am using JDK 12 and I have developed the custom array list in java with a basic understanding Please let me know if there are any flaws in it that I can correct the same
First the POJO class
public class Employee {
private String id;
private String name;
public Employee(String id, String name) {
... |
How can I make this code snippet better? Those for loops in if don't please me but they are covered with code lines that is dependent to if before and after.
public int hammingDistance(int x, int y) {
String binx = Integer.toBinaryString(x);
String biny = Integer.toBinaryString(y);
int dif = 0;
StringB... |
I have created my first crud javascript application to help me learn and I'm looking to hear from you any improvements or good practices I could apply to the code I've written.
In my html I have a bookshelf div and the html code needed for a form which pop-ups on the click of addNewBook button.
The code initially loads... |
I don't have any experience in cryptography and I've written some crypto code that seem to be working, but I'm not sure if it safe and if the tools and methods I used are right.
Objective
Make it possible to store data (JSON) on remote server without this server being able to read it in plaintext.
My Approach
Upon r... |
I have designed a messaging system below regarding the following assumptions
I would be appreciated for the valuable reviews.
Especially considering;
Multi-threading / SOLID principles / Design patterns
Assumptions:
Messaging System allows users to communicate with each other via messages.
User can be registered to th... |
I wrote a method for a wpf app in .net core to get all users and their group by name if they are in a group from my active directory domaine.
public static void getGroupsWithUsers() {
String currentDomain = Domain.GetCurrentDomain().ToString();
using (PrincipalContext context = new PrincipalContext(ContextType... |
We all know the classic version of counting the number of elements in a C array: sizeof(a)/sizeof(*a)
But this is dangerous, because if used on a pointer it will return garbage values.
So I made this macro, utilizing gcc extensions. As far as I can tell, it works the way it is supposed to, which is causing compiler err... |
Thanks again to everyone for their very useful suggestions concerning a huge integer class I posted here several days ago. I have made many of the suggested changes, perhaps the biggest being in the implementation. In particular, I am now using an array of uint32_t type to store digits with each member representing a b... |
I have been looking for the best approach to creating an extension method that would give me the ability to select in a linq query using async/await with a max degree of parallelism. I'm aware that this can be achieved with the use of different libraries but wanted to create one without. Using postings I found online... |
I have this logic that seems complicated checking the length and adding a colon. I'd like to see if any of you C# experts can help me simplify it. If the replace remove the full text then I am just adding the word Result. If it removes the make then I am just displaying the model.
Is there a way I can remove the if sta... |
I recently had to do a test for a job interview, and the prompt was to code a function that returns the closest number to 0 given an array of negative and positive numbers.
My function works correctly but I heard back from the recruiter saying that my function is not very performant and that the readability was not gre... |
This function formats raw buffer output in manner as Wireshark and many others does:
0x00: 68 65 6C 6C 6F 20 77 6F 72 6C 64 02 6B 68 67 61 |hello world.khga|
0x10: 76 73 64 20 0B 20 0A 05 58 61 73 6A 68 6C 61 73 |vsd . ..Xasjhlas|
0x20: 62 64 61 73 20 6A 61 6C 73 6A 64 6E 13 20 20 30 |bdas jalsjdn. 0|
0x30: 31 3... |
You can find the complete code on github. Since I'm rather new to C++ I thought that it might be a good idea to write a simulation of the n-body problem to apply some of the concepts that I learned in class. The relevant part can be found in main.cpp on the above linked github repo, but the imporant part is given by:
#... |
I was following this tutorial for JavaFX and Gradle:
JavaFX with Gradle, Eclipse and, Scene Builder on OpenJDK11
After completion of the tutorial you will have a simple GUI which you input a lower and upper bound and generate random numbers between them. The generated numbers and their bounds are then saved and listed ... |
I have a big file with a lot of "phrases", like:
sayndz zfxlkl attjtww cti sokkmty brx fhh suelqbp xmuf znkhaes pggrlp
zia znkhaes znkhaes nti rxr bogebb zdwrin sryookh unrudn zrkz jxhrdo
gctlyz bssqn wbmdc rigc zketu ketichh enkixg bmdwc stnsdf jnz mqovwg
ixgken flawt cpott xth ucwgg xce jcubx wvl qsysa nlg qovcqn zx... |
how can I optimize my code for a large set (10000 elements)?
found = False
def subset_sum(numbers, target, partial=[]):
global found
s = sum(partial)
# check if the partial sum is equals to target
if s == target:
print("sum(%s)=%s" % (partial, target))
raise Exception('element found')... |
I'm sure anyone who has used WPF is familiar with the irritating boilerplate code surrounding properties, usually of this form.
class TestViewModel : ObservableObject
{
string m_someValue;
decimal m_someOtherValue;
public string SomeValue
{
get => m_someValue;
set
{
... |
I have a list of raw data like following mockData and need to generate to a object[] format, some key-value pair are required from raw data like first, last, state. but some key-value pair are option like nickname. Eventually, I need to build a object array with some same key-value like raw data, and some key's value d... |
I have an array of bytes 6144 bytes long. I want to extract a set of 4 bytes every 6th set of 4 bytes . So every 24 bytes I want to extract 4 of those bytes and join them in a new array. So
arr=[a0, a1 ,a2 ,a3 ,a4 ...a6143] should become
arrNew=[a0, a1, a2, a3, a24 , a25, a26, a27, ...a1020, a1021, a1022, a1023]
I have... |
Please review my code with the following in mind: Does anyone see a reason to make this asynchronous, why would i do that? How do i work out the maximum number of users it can handle at one time? at what point will i need to optimise it and are there any easy things i can do to handle more users.
import os
import sqlit... |
I'm learning Rust by working through Jamis Buck's The Ray Tracer Challenge. The book instructs the reader on what to build in what order, and provides all required test cases.
Included here are my implementations of 1) an RGB color representation, and 2) a canvas, which is essentially an editable 2-d array of color obj... |
I have completed a solution for the below problem and uploaded it in Git Repo. I would be grateful if somebody can review in term of code quality, design and Kotlin language usage.
Repo
You're given the task of writing a simple console version of a drawing
program. At this time, the functionality of the program is ... |
I'm going through the Head First Design Patterns book and I want to check whether I'm understanding some aspects of the first chapter. Does the code below program correctly to interfaces, encapsulate changeable behavior, and employ composition in a reasonable manner?
// trying to enforce some design pattern habits
// ... |
I've been reading Haskell tutorials and books for a while, but I never actually did serious stuff with it. This is my first attempt.
It parses an OBJ-file in text format. Later on I will add some mesh-representation and more geometry stuff.
Could you please review my code and check for "haskeliness" (like, best practic... |
I'm a Haskell beginner, and I wanted to make a color annotator or color highlighter, one which takes a text as standard input, and outputs that text, with its color words highlighted using the colors themselves. So, it should replace all instances of the word "red" in a text with <span class="color" style="color: #ff00... |
I got asked this question in an interview and I came up with a solution which I shared in the below but apparently it was not enough to pass. I'm looking forward to hearing how this problem could be solved.
The question is : You are given an array of numbers e.g arr= [1, 3, 2, 0, 1, 2, 8, 4, 1] that represents a board ... |
Problem
Balanced number is the number that the sum of all digits to the left of the middle digit(s) and the sum of all digits to the right of the middle digit(s) are equal. The middle digit(s) should not be considered when determining whether a number is balanced or not.
If the number has an odd number of digits then t... |
Problem Statement
An airline wants to allocate seats in their aircrafts such that each group of four passengers travelling together are to be seated next to each other in clusters of 4. A contiguous cluster can have an isle running through it - for example, you can sit one passenger on one side of the isle, and three ... |
I have built a Blackjack simulator in Python. I need to decrease the execution time. I have used a profiler to identify key bottlenecks in the execution.
The following function is responsible for about 15% of the total run time.
def value(self):
value = 0
has_ace = False
for card in self.cards:
val... |
I am practicing coding questions on leetcode. I have been an OOP my whole career, and I am trying to wade into the dark abyss that is functional programming. So I am trying to do things purely functional, e.g. using recursion to try to get to the answer. The problem statement is this: Given a string, find the length of... |
After referencing http://csharpexamples.com/tag/unsafe-bitmap-access/
I tried to put together one for 1 bit per pixel bitmaps.
If you can review this, it would help me greatly in verifying this is the correct way to do it.
This takes a Format1bppIndexed bitmap and locks it in memory, and directly parses the memory bit... |
I have created a fractal tree based on a Lindenmayer System in Python. If you could tell me about any algorithmic or efficiency-based problems in the code, I would be grateful.
import turtle
import time
t = turtle.Pen()
branch = []
code = "1[0]0" # Change this to modify the structure of the tree
t.left(90)
t.up()
t.b... |
I've been learning C# for around 2 weeks and I'm feeling a bit more confident. I wrote this for general practice and am quite proud but hoping to make it faster and more efficient as I progress and learn more.
This program allows the user to input car data i.e. "Model and Price" and then search for the stored data.
(Ne... |
I have recently built a class that is an implementation of kMeans from scratch. I believe there is room for improvement and I would happily receive some feedback. The project can be found at: https://github.com/EmpanS/kMeans-From-Scratch
All code for the class is found below:
# Import useful libraries
import numpy as n... |
Inspired by this answer on stackoverflow for AI implementation in 2048 game.
I have been trying to make AI calculate best move by playing the game given specific times in memory preceding by one specific move first, then averaging the score and declaring move with highest score as best move.
The workflow is fine, i am ... |
I'm looking for some feedback on this code I wrote tackling a general solution to the age old "Add 2 numbers represented by Linked Lists". This specific one aims to be able to sum any given number of linked lists.
Ofcourse, the input linked lists must contain the number in reverse order.
#include<stdio.h>
#include<stdl... |
I wrote a simple algorithm to encrypt and decrypt files in Python using aes-256-cbc.
from Crypto import Random
from Crypto.Cipher import AES
import base64
def pad(s):
return s + b"\0" * (AES.block_size - len(s) % AES.block_size)
def encrypt(message, key, key_size=256):
message = pad(message)
iv = Random.n... |
Can someone help me how to speed up this scraping process getting all the usernames from the # 'cats' on instagram. My goal is to make this as fast as possible because currently the process is kinda slow. Maybe using multithreading?
from instaloader import Instaloader
HASHTAG = 'cats'
loader = Instaloader(sleep=Fals... |
Hey I am in the process of making this game, please could I get any feedback on how to further approach this, as I find it kind of inefficient.
import pygame
import time
pygame.init()
#Creating the Pygame window
X = 500
Y = 500
win = pygame.display.set_mode((X, Y))
pygame.display.set_caption('Last to Pick')
width... |
I've made an iteration of the text game Hunt The Wumpus. The specification came from the text Programming Principles and Practice Using C++ by Bjarne Stroustrup.
Implement a version of the game "Hunt the Wumpus". Hunt the Wumpus" (or just "Wump") is a simple (non-graphically) computer game originally invented by Grego... |
I built a simple web app to manage my friends and I's six nation prediction league. This is my first go at web development so although it works I am guessing that I am not following all best practices or conventions. Any tips would be much appreciated.
The stack I used is:
Neo4j <-> Py2Neo <-> Flask <-> Html, JS, CSS
I... |
I have made a simple website and I have tried to reduce load times as much as possible. All the content that is loaded is necessary.
Is there anything thing I can do to my code, such as structurally, to make it load even faster?
Side Note
I do not want to minify the HTML, as I want it to remain legible and I am not con... |
While rewriting Array so I can practice my javascript, I looked at my implementation of .join(). It seems a little clunky to me.
I've tried to cover all the edges, like making sure separator isn't null before joining, not adding the separator at the end of the string, and writing some documentation.
What I'm looking fo... |
Introduction:
The following script contains code that performs what I would usually do when starting a new scene (add lights, camera, objects). The script will serve as a starting point for most of my future scripts.
In the future, I might use more complex materials, create animations, or use the built-in physics simul... |
I'm a beginner in PHP.
Here my script
$url1 = $chemin.'include/aaa/url1.php?param='.$param.'&page='.$p;
$url2 = $chemin.'include/aaa/url1.php?param='.$param.'&page='.$total_pages;
//url2.php
$url3 = $chemin.'include/aaa/url2.php?page='.$p;
$url4 = $chemin.'include/aaa/url2.php?page='.$total_pages;
//url3.php
$url5 ... |
I need to learn bash at some point in the near future, so I decided to start playing around with it. This is really the first actual script that I've written and would like feedback.
This finds and prints all the prime numbers up to the argument provided to the script:
./primes.sh 100
2
3
5
7
11
13
17
19
23
29
31
37
41... |
I'm looking for combinations, not permutations, and have found some really great examples ranging from using flatMap such as https://stackoverflow.com/a/54329187/669843
The result of ['a', 'b', 'c'] would be an array of arrays of 3 (a, b, and c). The result I'm looking for would also contain arrays of length 1 and 2.
E... |
I have developed the program to rotate the array in java request you to please check it and let me know if there are any flaws in it or where further it can be improved
package com.dataStructures.Arrays;
// Java program for reversal algorithm of array rotation
//Let the array be arr[] = [1, 2, 3, 4, 5, 6, 7], d =2... |
I'm developing a Go application that has lots of packages.
Many of the packages use the same type from a 3rd party library.
Should an interface be defined for the type in each package, and let the interfaces only contain the methods that are used by the package?
Or, we should define a single interface for the whole app... |
I have a set of products(e.g. P0006, P0009, etc.) and a set of production lines (eg. L1H175, L2H175). A product can be produced on a subset of the lines set (and not necessarily all of them).
If we decide to produce a product on a production line(assuming that the line can actually produce it), we need to buy the appro... |
I have implemented a very simple but robust implementation of the Golomb-Rice coding.
To understand my motivation, see the minimalist data compressor that is based on this.
At the moment, the implementation works well.
However, I intend to make it more elegant, concise, and possibly faster.
Any suggestions for improvem... |
I've implemented atoi function as described in leetcode problem string-to-integer-atoi.
I am looking for some feedback on writing this in a more scala native way and being able to include the requirement that:
If the numerical value is out of the range of representable values,
INT_MAX (231 − 1) or INT_MIN (−231) is ... |
I've wrote a C++ program to calculate the determinant of a matrix:
#include <iostream>
#include <string>
double getDeterminant(double arr[], int dimension);
int main() {
//First, the user has to enter the dimension of the matrix
int dimension;
std::cout << "Please enter dimension of Matrix: ";
std... |
This is my implementation of Dijkstra's algorithm. It solves any order square mazes.
from copy import deepcopy
from math import inf
import maze_builderV2 as mb
def dijkstra(maze, order, pos, finalpos):
mazemap = {}
def scan(): # Converts raw map/maze into a suitable datastructure.
for x in range(1, order+1):
... |
After following some suggestions you can find here, I'd like to show you the result:
#include <iostream>
#include <string>
#include <vector>
double getDeterminant(std::vector<std::vector<double>> vect, int dimension);
int main() {
//First, the user has to enter the dimension of the matrix
int dimension;
... |
I'm working on a Slack bot for service desk which sends direct message to user on a Slack when their ticket will be on user_action_needed status. I'm using AWS Lambda to handle Jira incoming webhooks. Everything works well but I think I've got an issue with whole architecture of the app - I quess the code is not so rea... |
I am writing a function to have insert a list of strings into a MySQL database and C#.
The process of creating the list of Components:
User has to scan multiple barcodes and have them stored in a list.
The goal is to take that list and insert it into a MySQL database on the click of a submit button.
Is the function be... |
I've been making a simple "game engine" for fun and I had a lot of trouble designing a decent asset management system. Currently I got it working but it uses a lot of downcasting which is usually bad practise.
The whole code wouldn't really fit here so I'm putting here the relevant parts and linking the whole thing on ... |
I'm creating mazes, and have a Cell class (only relevant code shown)...
public class Cell {
public int Row { get; }
public int Col { get; }
public List<Cell> Links { get; }
public Cell North { get; set; }
public Cell South { get; set; }
public Cell East { get; set; }
public Cell West { get; set; }
pu... |
I'm working on implementing a goal-based pathfinding.
first step is to set a goal and calculate the shortest walkable distance between the goal and all points in the grid, using a brushfire algorithm.
I'm worried about two things here, readability and efficiency, since this is for an RTS game.
int[] GenerateHeatMap... |
Before I begin showing code, I have two main questions which I feel could help me.
What is a service or factory, I've heard of them but why use them?
Should I use one shared instance of ILogger throughout my whole application, I only plan on persisting errors and I can get the reporter from the stacktrace.
So,
I deci... |
I have a set of unique strings, I want to create a unique integer identifier for each string.
Usage I want a function to move back and forth, if I give it an integer it returns the corresponding string and vice versa.
Here is how I am doing it
def str_to_int(S):
integers = list(range(len(S)))
my_dict = dict(zi... |
I got this from a practice problem set, and looking for feedback on my approach.
Suppose you're given a binary tree represented as an array. Write a function that determines whether the left or right branch of the tree is larger. The size of each branch is the sum of the node values. The function should return the str... |
Which of these three methods is the most efficient?
Also, what is the time & space complexity of each?
public class Palindrome {
public static boolean isStringBased(String word) {
if (word == null || "".equals(word)) {
return false;
}
String lowerCasedWord = word.toLowerCase();
... |
Here's my algorithm / approach for transposing a 2D Matrix on the main diagonal.
Before:
a L M d
b G c N
H K e F
I J O P
After:
a b H I
L G K J
M c e O
d N F P
My code:
public class Matrix {
static String[][] matrix = {
{"a", "L", "M", "d"},
{"b", "G", "c", "N"},
{... |
Currently trying to migrate two fields of information into one field. We have many, many objects to go through and it takes roughly 12 minutes to loop through all the objects. That would mean the website would be down for 12 minutes and we do not want that. Is there any way to speed up this migration? It works, it's ju... |
I have a single image of shape img.shape = (500, 439, 3)
The convolution function is
def convolution(image, kernel, stride=1, pad=0):
n_h, n_w, _ = image.shape
f = kernel.shape[0]
kernel = np.repeat(kernel[None,:], 3, axis=0)
kernel = kernel.transpose()
n_H = int(((n_h + (2*pad) - f) / stride) + ... |
I have an Access macro that runs AfterUpdate of a form. It opens an Excel workbook and edits a few cells. I have It working the way I want, but the problem is that the code takes about 25 seconds to run. This is way too long for the users of this database to have to wait. After adding some timing messages, I found that... |
Is this a good way of removing all the nodes that contains a value x?
This function takes as input the head of a list and has to delete all the nodes that contain a given value taken. If there is any better way of doing this can you please show them to me?
node_t *funzione(node_t *head){
int x;
node_t *temp ... |
So I ported a lexer I wrote in C++ over to rust, as I'm starting to learn rust. Since I'm very new though, I don't know any Idioms and good practices in rust. So if anyone could point out some (probably obvious) issues I'd be very thankful.
This is my code:
use std::cmp::PartialEq;
use std::fmt::Debug;
#[derive(Debug,... |
I've been learning more about PHP Objects and Classes, and my immediate reaction was to create a Database Object for handling the MySQLi Connection, Statements and Results. Its not meant to be an ultimate do-all object, but help with WET code. Obviously this has been done before... at least a hundred times.
There's... |
I have a json field in a table that I want to select certain fields from into a new json field. So far I have this, which works, but I feel may not be optimal:
select to_json(new_obj) from (
select big_json_field->'json_property_1' as json_property_1,
big_json_field->'json_property_2' as json_property_2
f... |
How can I get the date of the next occurrence of Friday the 13th?
Below is my attempt. It returns the correct results. I think there must be a better way of writing this without checking thirteenth > start_date for every month. It might also be possible to exploit the fact that every calendar year has a Friday 13th.
im... |
I am still a beginner and I would love to hear some feedback on a small wrapper I wrote for the TMDb API (https://developers.themoviedb.org/3/getting-started/introduction). It is used for queries on a movie database. I tried to make it as simple as possible so all that is needed to get relevant information is the title... |
I am making an user class which I could inherit and use in the future.
(recently started learning Python and OOP)
import mysql.connector as mycon
class user:
host = "localhost"
user = "root"
password = "pass"
database = "USERS"
table = "UserData"
def __init__(self,firstName,lastName,userName,em... |
I have a function that constructs a path based on a function of inputs and creates the parent directory.
When writing a unit test for this function, I want to mock the I/O part of the function, namely the .exists() and .mkdir() methods of the pathlib.Path objects. However, since both are not called until the path ha... |
I wrote this simple scoped thread to use it as a class member to ensure the the thread running on a class method doesn't continue running after the class has been destructed. Also to spawn threads from the main() function to ensure that I don't forget any running threads upon exit .
This can be achieved by calling joi... |
Here is problem:
There is string (domain) divided by dots (like www.part1.partN.com)
Need to build reversed by dot string (like com.partN.part1.www)
Both strings are utf-8 encoded
My solution:
std::string reverseHost(const std::string& host)
{
std::string ret;
ret.reserve(host.size());
size_t tail = host... |
I am using the code below to pass filter selections from table A to table B in Spotfire. I am doing this to create a filtering relationship between the tables, but skipping the creation of a traditional Spotfire table relationship, as this is not advisable in this setting.
The code is associated with a document propert... |
In this code I calculate the statistical functions of values from different files and save them into CSV files (one filer for each statistical function).
def mean(data):
pass
def standard_deviation(data):
pass
def afd(data):
pass
def norma_afd(data):
pass
def asd(data):
pass
def norma_asd(data)... |
I want to associate an error message to a Validator and not have to in the html check for a specific error. aka *ngIf="controls.name.required". I've seen generic error message helpers that build up an javascript object with an index and a message that goes with that index. What I want is to actually associate the err... |
How can I re-factorise this circular nesting dictionary function?
The challenge:
I recently received a data extract with a list of folder names and associated subfolders. The challenge was to produce a reusable function that could provide a summary of the unique folder names and all the nested subfolders.
The data sou... |
I was doing this exercise on codeabbey.
Andrew and Peter play the code-guessing game. Andrew chooses a secret
number consisting of 3 digits. Peter tries to guess it, proposing
several values, one by one.
For each guess Andrew should answer how many digits are correct - i.e.
are the same in the proposed value and in hi... |
I have a question regarding code quality and best practices. My task - to write a feature encoding function that will encode categorical labels, boolean labels as one-hot encoding, timestamps for further usage for ml training.
Input - dictionary of several dataframes, each dataframe consist of several columns of differ... |
This is my second iteration of a function to remove all nodes containing value 'x'. The previous iteration is here.
This function takes as input the head of a list and has to delete all the nodes that contain a given value taken. Is this an improvement on the previous iteration? Is there anything else that can be im... |
Version 1 may be found here.
I have implemented the suggestions by Jon Skeet, plus some of my own. Key differences between versions:
ZonedDateRange class is now immutable.
LocalDate variables no longer are named with "Day".
Some ToString() methods were added.
ZonedDateRange.cs
using System;
using System.Collections.... |
I am built a program that will give the 7 chords that are found a given major or minor key. My program takes in first a key (C, Ab, F#, etc.) then takes in its mode (Major (input is 'M') and minor (denoted by 'm')). From there the program builds the chords in that key in a specific manner depending on the mode where yo... |
I'm calculating a score based on whether or not certain colors shape is selected. Some of the shapes are in groups, some are not. For the shapes which are in groups, only one of them will count towards the score. I have figured out how, as you can see below. However, I have 9 more shapes/scores to add to the Sub. I'm s... |
I have two functions which I would like to simplify. They have largely the same logic, but one is asynchronous and uses one await in a try block. I'd like to have the logic in one place, but could not figure out a clean way of doing that. Any suggestions?
from requests import get, HTTPError
# Dummy functions for exter... |
TL;DR: The algorithm receives a string as input, allocate another string to be the final digest, and start working on them. For each char on the digest (a null character on a first moment), it XORs it with every character from the original string, also XORing it with a set of "random bytes" that are specified in the be... |
I've written a basic event messenger broadcasting service. This is meant to allow for broadcasting events between loosely coupled areas of code where you may not have or care about a direct reference to the specific broadcast source (as you might if using Signals/Slots for example), and the broadcaster does not know wh... |
I had a task to convert some JPG images into PNG format using Python. I successfully did it but I was wondering if somehow I could make my code better than my current one.
Code -
#Python Code
import os
from PIL import Image
path1 = sys.argv[1]
path2 = sys.argv[2]
if not os.path.exists(path2):
os.makedir... |
I need to write a method that will accept a timestamp and takes an array of votes, I need to return the k leading candidates with that timestamp. I came up with the following solution,
Here is the input to the methods:
votes = [{'candidate':'a', 'timestamp':2},{'candidate':'c', 'timestamp': 5},{'candidate':'c', 'times... |
I wonder whether I included too many libraries; also can you point out obvious beginner mistakes?
Is the while loop the best for what I intend, or is there a better way?
Also, is it possible to put more into functions such that the main() looks like this:
int main()
{
call function1
call function2
etc.
return 0;
... |
I am new to C# and would appreciate it if you review my code. This code finds the anagrams in a list of string. Where can I be more efficient in my code? is there any way I can save memory?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Tr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.