instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
Is there any way to simplify the following C# helper class to numerate a string for Json.Net?
internal static string CreateContact(string title)
{
var createContact = new {Title = title};
string output = JsonConvert.SerializeObject(createContact);
return output;
}
[JsonProperty(PropertyName = "9")]
public ... | stackexchange/codereview |
I wrote this function to map value to a color
I am looking for some general feedback on how I can improve the efficiency of the function. and if there is better way to do it.
function getColor($value, $values_range, $opacity = '0.7') {
$deltaS = ($values_range['max'] - $values_range['min']) / 2;
$ds = ($... | stackexchange/codereview |
In my project, I have a type BalanceByBucket that is an immutable type and has a bunch of methods.
I have another class called a FundBalance which is basically just a BalanceByBucket that has an extra int FundID property applied to it. I want this FundBalance to also have access to all the same methods as BalanceByBuck... | stackexchange/codereview |
I am solving the Prime Reduction challenge on Kattis.
Consider the following process, which we’ll call prime reduction. Given an input x:
if x is prime, print x and stop
factor x into its prime factors p1, p2, …, pk
let x = p1 + p2 + ⋯ + pk
go back to step 1
Write a program that implements prime reduction.
Input
Inp... | stackexchange/codereview |
I am adding some check box filters on a HTML table, based on whether a check box is checked or not, and I am toggling rows. Is there anyway I could improve this code? There is no issue with it at the moment I could think of e.g. performance wise, but maybe someone could help me with decreasing number of lines.
HTML
<... | stackexchange/codereview |
I'm trying it out just to see if I could solve it. It would be great if I could receive tips on how to improve it.
//input
var decimal = prompt("Please enter a decimal number");
if (decimal >= 1 && decimal < 1000000000) {
//convert to binary
var binConvert = parseInt(decimal, 10).toString(2);
//reverse bin... | stackexchange/codereview |
How can I make this piece of code better? The problem to be solved is in the topmost comment.
#include <iostream>
#include <vector>
#include <cassert>
#include <stdint.h>
#include <iterator>
#include <queue>
/*
* Shuttle Puzzle:
* A Shuttle Puzzle of size 4 consists of 4 white marbles, 4 black marbles, and a strip o... | stackexchange/codereview |
I decided to make an extension for Spicetify (modified Spotify client). It generates a playlist of similar songs based on their average audio features.
//@ts-check
// NAME: Feature Shuffle
// AUTHOR: CharlieS1103
// DESCRIPTION: Create a playlist based on the average features of a playlist
/// <reference path="../glo... | stackexchange/codereview |
I recently had to install VNC on mass across a lot of computers on a domain and needed some info about their PC, for example:
Host name
Username
MAC Address
IPv4 Address
Domain name
Once all of this info is gathered, it is compiled into a text file and uploaded to a FTP server. To save files from being conflicted wit... | stackexchange/codereview |
I would like some advice which relates to the "fat model skinny controller" concept in Rails.
See my show action in the Micropost controller
def show
@micropost = Micropost.find(params[:id])
@tags = @micropost.tag_counts_on(:tags)
@responses = @micropost.responses
@response = current_user.respons... | stackexchange/codereview |
This is my first shot at asyncio. I'm looking for any pointers you might have. Especially:
Are there any race conditions?
This code doesn't scale as expected. In my project I need to call caget 4k times.
As a background thread I need to make 4k network calls (caget, which is a third party function I can't change) wh... | stackexchange/codereview |
I have been writing some code to add to our company's Bill of Materials template Excel file. Every project that we do has its own unique Bill of Materials. I am attempting to make it more dynamic and to add some functionality that it didn't previously have. I have created an add-in BOM MACROS.xlam that each user will a... | stackexchange/codereview |
Problem Statement
You are situated in an N dimensional grid at position (x1, x2, …, xN).
The dimensions of the grid are (D1, D2, …, DN). In one step, you can
walk one step ahead or behind in any one of the N dimensions. (So
there are always 2×N possible different moves). In how many ways can
you take M steps s... | stackexchange/codereview |
I need to parse the following input string into a hash table with the following format:
Input:
'1001=23;1001B=5;1002=0;1003=5;'
Output:
=> {'1001'=>23,'1001B'=>5,'1002'=>0,'1003'=>5}
My solution:
def parser input
output = {}
input.split(';').map {|ar| ar.split('=')}.each {|id, c| output[id]=c.to_i}
output
end
p... | stackexchange/codereview |
I want to inform the Receivers about new contracts we have this week. After I sent the Emails, the Information about sent contracts are stored in MS SQL Database.
To avoid that someone become the same Email about contract more than one time I perform this steps:
I have the Collection with new contracts as the input
I ... | stackexchange/codereview |
I am a beginner and trying to send data from AWS DynamoDB to Azure Queues. Note that this code will be invoked 10,000 and alot more. Can you guys review it once.
using System;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Amazon.Lambda.Core;
using Amazon.Lambda.DynamoDBEvents;
using Amazon.DynamoDB... | stackexchange/codereview |
This might be difficult for me to describe clearly but I will try anyway. Also note that this is entirely speculative; it might not even be able to run any faster (that is why I am asking).
This is a question directed at performance. I have been trying to improve the performance of a method and have managed to improve... | stackexchange/codereview |
I wrote a little factory to dynamically load assets in angular resolve. Is it well structured and can it be made prettier?
app.factory('loadAssets', function ($q) {
var jsPath = "scripts/",
cssPath = "css/",
imagesPath = "images/",
head = document.getElementsByTagName("head")[0]; // define ... | stackexchange/codereview |
I want to handle input like the following
ls -al | awk '{print $1}'
Now to parse it I couldn't tokenize at whitespace because of the quotations and I had to make a special case for awk instead. The code below successfully parses the command-line input. Is there a better way?
int handleToken(int awk, char *token, char ... | stackexchange/codereview |
I have two tables, devices and device_properties.
The devices table columns are as follows:
id
ip
mac
device_property_id
created_at
updated_at
The device_properties table columns are as follows:
id
property_name
cli_enabled
created_at
updated_at
At the moment I have the following code to retrieve an array of devic... | stackexchange/codereview |
I saw a programming puzzle. Find a string containing letters from a to z such that its MD5-hash starts like 314159265359. I am a junior programmer so I would like to know if I can solve the problem faster that checking firs strings a-z, then aa-zz, then aaa-zzz and so on. As the computation takes time, I save results t... | stackexchange/codereview |
I have to do some encoding and then assign the result to a label. Is there a more optimal (or concise) way to write this?
// encoding fix
NSString *correctStringTitle = [NSString stringWithCString: [[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding]
... | stackexchange/codereview |
I've got a class that is like a facade, like an engine for my application which is responsible for fetching data from url and summing it.
I have got problem with proper names for my methods.
executeNBPParserEngine is like method that connects everything to one. It gots if and else statement. If statement checks if th... | stackexchange/codereview |
You are given 3 strings: text, pre_text and post_text. Let L be a
substring of text. For each substring L of text, we define
pattern_score as follows:
pre_text_pattern_score = highest n, such that first n characters of L are equal to the last n characters of pre_text and occur in the same
exact order.
post_t... | stackexchange/codereview |
I am getting back into python after a year of not doing it at all. I just wrote a bit of code to create a file that looks like this:
1,2
1,1,1,1
-1,0,1
42,17
Then I decided to take the average of each line and put it into a list. For this I wrote the following:
def line_averages():
out_file = open("data.csv", "w")... | stackexchange/codereview |
Feel free to tell about every possible issue (style, errors, inffective solution etc.) you found. Here is the main part of what I want to be reviewed, through there is some related code on GitHub.
Header
#ifndef PRIM_GRAPH_MST_H
#define PRIM_GRAPH_MST_H
#include <list>
#include "graph.h"
class PrimGraphMstImplementat... | stackexchange/codereview |
I'm trying to improve the following code for testability.
public function can_apply_extension()
{
$search_dates = [
Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1),
$this->billing_verified_to
];
$record = ORM::factory('a model')
->where('cre... | stackexchange/codereview |
I'm new to Python. For learning purposes, I want to create desktop application by using QtWebKit and Flask. You can find the source code here
Main idea is:
create a form including a QWebview widget
create a Flask app
run Flask app on QWebview
It works correctly but I want to know:
How can I improve my code?
is ... | stackexchange/codereview |
I've produced some JavaScript code for a Video Player, but my experience in coding is with C# and the differences between the languages and my lack of experience has made me wonder I'm not following the correct guidelines.
I'm just wondering if anyone doing a once-over would have any good criticisms and pointers they c... | stackexchange/codereview |
Usually in C++, the language rules automatically convert types as necessary. For example, I can pass a pointer-to-derived in place of a pointer-to-base, and the same with references.
There are occasions where one needs to specify a type to which a value should be coerced, but less strongly than a cast. Some cases wher... | stackexchange/codereview |
I am solving interview questions from here.
Problem :Given a singly linked list, determine if its a palindrome. Return 1 or 0 denoting if its a palindrome or not, respectively.
Notes:Expected solution is linear in time and constant in space.
For example,
List 1-->2-->1 is a palindrome.
List 1-->2-->3 is not a palindro... | stackexchange/codereview |
I am using EdgeJS in my application. The application is used to run a user-provided javascript program from C#. Because we allow execution of user scripts some sandboxing is required. I am using vm2 for sandboxing. Is it correct to add custom logic by overriding a function exposed by NodeJS library?
Here is the C# prog... | stackexchange/codereview |
How can I improve this code?
#import sys
#sys.setrecursionlimit(1500)
def get_input():
input_str = input("Enter elements to be sorted: ")
try:
lst = list(map(int, input_str.split()))
except:
raise TypeError("Please enter a list of integers only, seperated by a space!!")
return lst
def ... | stackexchange/codereview |
I recently tried to solve the Josephus Problem on Sphere Online to help answer this question but am getting TLE for any solution I come up with.
The exact parameters of the problem are:
This is new year in Planet X and there is something special! A
classroom in this planet is looking for a new class leader using an
... | stackexchange/codereview |
For the past months I have been learning plain javascript without jquery or libraries/frameworks. So now, when I develop a website, I want to write all of the JS code by myself to fully understand what is going on and to learn the language.
So far so good. I tried to implement a slideshow with a fading background image... | stackexchange/codereview |
I'm not sure if there's a standard view where the placement of a success result should be in a conditional that can return multiple statuses. The success condition of this function is in the middle of the conditional block:
def redeem(pin)
success = false
message = nil
if !self.date_claimed.nil?
message = 'Re... | stackexchange/codereview |
background story my girlfriend watches about 12 TV-Show episodes everyday and i keep telling her it's not good. I have made this script that kicks her out of my account for 20 times in an hour.
However, After 20 logouts it gives out a Technical difficulties error and i want to improve as to why?
import sched, time
from... | stackexchange/codereview |
I am trying to optimize the following (now C) radix sort code for use in my game engine library. The basis for this code was inspired by this youtube video on a C++ implementation called skasort that used templating to sort STL containers. The current first pass code sorts in-place in most-significant-byte (MSB) order ... | stackexchange/codereview |
Inspired by Swift's @autoclosure feature, I tried writing a brief C++-14 header that permits "optionally" lazy parameters (by "lazy" I mean @autoclosure-like; I chose the word "lazy" in emulation of lazy evaluation in languages such as Haskell). From this post on interesting Swift features:
The @autoclosure attribute ... | stackexchange/codereview |
I need to review this code:
import java.util.HashMap;
import java.util.Map;
// REVIEW
public abstract class Digest {
private Map<String, byte[]> cache = new HashMap<>();
public byte[] digest(String input) {
byte[] result = cache.get(input);
if (result == null) {
synchronized (cache... | stackexchange/codereview |
I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except array.length.
Here i am attached my code. How to achieve that thing more efficiently.
var str = "i am javascript";
// result "i ma tpircsavaj"
function reverseString(m... | stackexchange/codereview |
I have the following code which does 2 things:
Return a scanned fingerprint as base64
Store this print as bitmap
While the code works most of the time, sometimes an invalid bitmap is saved (I can't open the file). I think there are some improvements (padding?) that can counter this strange behavior. The 'firstPixel' ... | stackexchange/codereview |
I know my way around jQuery and JavaScript a little bit but as for optimising, I'm a bit weak but willing to learn new stuff.
I'm currently loading videos onto our site from Vimeo when a user clicks the appropriate image area. This is working fine, but I feel it's not an entirely performant way to go about doing it.
D... | stackexchange/codereview |
I currently have a working implementation of a + and - tank level thingy (I don't really know what to call it). In which will be able to 'add' or 'remove' so-called 'liquid' from the container.
However, I feel my implementation of this is very inefficient, and would appreciate your input on this matter.
$(document)... | stackexchange/codereview |
In the Wikipedia article about the binary search algorithm, a small paragraph in
particular got my attention:
Midpoint and width
A different variation involves abandoning the L and R pointers and using a current position p and a width w. At each iteration, the position p is adjusted and the width is halved. Knuth stat... | stackexchange/codereview |
I have a PupilService which is calling the PupilRepository.AttachPupil() method.
I have an N to M relation between SchoolclassCode and Pupil.
Technical logic:
A pupil can be related to many SchoolclassCode like "Math 7 a" or "English 8 c".
Business logic:
A pupil can be related only to SchoolclassCode like "Math 7 a" ... | stackexchange/codereview |
I'm attempting to parse an SVG file to get all of the colors that are present in the file. SVGs are XML based and their structure can vary a bit. For example:
<svg viewBox="-80 -80 160 160">
<g stroke="black" fill="none">
<path d='...' fill='#0FF'/>
<path d='...' fill='#F0F'/>
...
</g>
</svg>
and
<sv... | stackexchange/codereview |
I have the following log4j2.properties file:
status = info
name = my-app
# properties
property.name = my-app
property.basePath = log
property.filename = ${basePath}/${name}.log
# console layout
appender.console.type = Console
appender.console.name = console-logger
appender.console.layout.type = PatternLayout
appender... | stackexchange/codereview |
Here is my simple ticketing system:
<?php
session_start();
session_id();
ob_start();
require("../configuration/config.php");
$GetTickets = $con->query("SELECT * FROM tickets WHERE open='true'");
if(!$_SESSION['Admin']) {
header('Location: login.php'); exit();
... | stackexchange/codereview |
I have written this big function to do some formatting in my python code. Would you be able to suggest anyways to make this smaller ?
def disfun(String1,String2,String3):
if String3 == "A" or String3 == "B":
if String3 == "A":
pass
elif String3 == "B":
pr... | stackexchange/codereview |
I have a project here that looks pretty good and does exactly what I want it to do. The codepen is here. What I need to find out is if these divs that flip can be shortened in any way:
<div class="flip-container" id="flipcontainer">
<div class="flipper" id="flipper">
<div class="front" id="front">
... | stackexchange/codereview |
I've started learning MonoGame and C# lately, so in order to get more confident with both and do something not completely trivial, I've built a Naughts and Crosses game.
I am using 7.1 version of C# (value tuples here and there...)
The game does the following:
Plays Tic-Tac-Toe (AI is unbeatable)
Keeps score for play... | stackexchange/codereview |
I wanted to have a DataTable with cells in direction that is top to bottom or bottom to top and left to right or right to left.
LR - LEFT to RIGHT
RL - RIGHT to LEFT
BT - BOTTOM to TOP
TB - TOP to BOTTOM
To do that, below is the method I created
internal DataTable GetContainerLocationMap(int row, int column, strin... | stackexchange/codereview |
I write protocol messages encoder/decoder for my project.
All messages have 2-bytes header (1 byte - message type, 1 byte message sub-type) and body.
There are two types of messages:
Plain message - no encoding
Encoded message - AES encoding
I would like to get your feedback on:
Overall design and coding style
Prop... | stackexchange/codereview |
This is one of tasks, which I had to do for the recruitment process to be started in some company. Unfortunately they didn't like it so I've decided to share it here for discussion.
Philo5.h
#ifndef PHILO5_H_
#define PHILO5_H_
//Number of philosophers
const int PHIL_COUNT = 5;
//How many times each philosopher will e... | stackexchange/codereview |
Below is a snippet of code of a little practice project. I am still pretty new to EF and I was wondering if there is a way to write the below statement so that all required data is eager loaded since I have the ID parameter.
public ActionResult Index(int? id)
{
var viewModel = new InstructorIndexData
... | stackexchange/codereview |
I recently came across the need to be able to allow a user to select a value from a select list, and have it dynamically displayed in an unordered list and have the value disappear from the unordered list. The use then needed to be able to click and remove the row, which would then allow the value to reappear in the se... | stackexchange/codereview |
I'm writing a program to split the words contained in an hashtag.
For example I want to split the hashtags:
#Whatthehello #goback
into:
What the hello go back
import re,pdb
words = []
# corncob_lowercase.txt contains a list of dictionary words
with open('corncob_lowercase.txt', 'rb') as f:
for read_word in f:
... | stackexchange/codereview |
I am solving a puzzle (Finding if there exists an input for a given automata for which no matter what the starting state is, final state would be same everytime) and have written following Python code. A few testcases are written in check method in the code. For these cases program is running fairly fast. However, for ... | stackexchange/codereview |
I have an input text file which contains distance between 2 cities shown below
Luebeck Hamburg 63
Hamburg Bremen 116
Hamburg Hannover 153
Hamburg Berlin 291
Bremen Hannover 132
Bremen Dortmund 234
Hannover Magdeburg 148
Hannover Kassel 165
Magdeburg Berlin 166
Berlin Dresden 204
Dresden Leipzig 119
Leipzig Magdeburg 12... | stackexchange/codereview |
For a while now I've been after a lock-free, simple and scalable implementation of a multiple producer, single consumer queue for delegates in C#. I think I finally have it. I've run basic tests on it showing it works, and the design is so simple that I've managed to convince myself it is rock-solid.
This relies on a c... | stackexchange/codereview |
I'm currently working on CSRF prevention and I would love to hear your feedback for my code. I assume that there are no XSS vulnerabilities in order for the CSRF protection to work. Furthermore, I assume that all state-changing/critical actions are done via post-requests. One token is generated per session.
Here is the... | stackexchange/codereview |
Convert the string:
(id,created,employee(id,firstname,employeeType(id), lastname),location)
to the following output:
id
created
employee
- id
- firstname
- employeeType
-- id
- lastname
location
The solution I came up with is given below. I want to improve it, but without using regular expressions. Please help me... | stackexchange/codereview |
Can you please share your thoughts on the following simple httphelper in Go? Thanks in advance.
I mainly would like to know whether returning a channel of a custom type seems like a good idea and if so , how could I improve it for only receive chans.
package services
import (
"bytes"
"encoding/json"
"io/io... | stackexchange/codereview |
I'm currently creating a class that will have a bunch of my most common database functions. This is the first method I've made, I would appreciate any feedback, thanks!
public static function insert($table, $params) {
// Define initial query
$query = "INSERT INTO `{$table}` (";
// Format rows to insert
... | stackexchange/codereview |
I am getting a compiler warning when running my code analysis. It is CA2202. It is saying that I have not properly disposed my dataset through all exception paths. Here is the code:
private System.Data.DataSet MyDataSet()
{
DataSet dat_set = new DataSet();
using (SqlConnection conn = new Sq... | stackexchange/codereview |
Greetings.
Lately I've tried to use a branch of text_formatting rules to enhance my productivity while working with different integration tools such as Git, but this formatting convention went so
deep into my life that I thought that writing my To-Do list while adhering to it would be
a good idea.
Since the element or... | stackexchange/codereview |
Today I created a script in Excel that migrates data from a specific Word document and copies a portion of it to a cell in Excel (the date to be specific).
The file input is
Last name, First Name, Grade - (Rank) (Completed On YYYY-MM-DD HH:mm:ss)
and each person is on a new "paragraph" (aka line) in Word.
Sub Search... | stackexchange/codereview |
I am trying to model person in OOPS using immutability.
I have created an object bond with age as 25. To change the age I have created a new object and returned it.
Is there any better way to change the age instead of passing all the values of object again? Is this a correct way to do?
import java.io.*;
import java.uti... | stackexchange/codereview |
I wrote some code that loops for specific data and then fills the missing cells in another sheet. The code works perfectly but it takes too much time to fill the missing cells (values).
What I tried to do is to Test if Cell B is blank or not , then I created 2 variables :
x for activesheet values which need to be fill... | stackexchange/codereview |
My postfix program essentially allows the user two input options to calculate a postfix equation:
Confirmations after each input (after an input, the user is ask for another number, operator, or final result)
No confirmation after each input (user is only asked for a number of inputs (values and operators), and the fi... | stackexchange/codereview |
I'm learning C and have made this very simple function to compare two strings. I would like to know how it can be improved:
int match(char* string1, char* string2)
{
size_t i = 0;
while (string1[i] != '\0' || string2[i] != '\0') {
if (string1[i] != string2[i]) {
return 0;
}
... | stackexchange/codereview |
In my Python application, I am using Tarjan's algorithm to compute strongly connected components. Unfortunately, it shows up under profiling as one of the top functions in my application (at least under cPython, I haven't figured out how to profile under Pypy yet).
I've looked at the code, but I don't see any obvious ... | stackexchange/codereview |
I currently have an Excel workbook which pulls data from a website that lists sign language interpreters from here.
There are 7 different regions, or tables, I pull from. The data is put into Sheet1, Columns A, C, E, G, I, K, M - all starting in row 1. The VBA I have written then sorts/splits this data into Sheet2 us... | stackexchange/codereview |
I have recently come up with an idea to retrieve additional data through Pipe, and I am not sure if I created a cool solution or terrible abomination. I will try to present the problem and my solution. I will include most important parts of the code, but should something be unclear please let me know.
Angular version i... | stackexchange/codereview |
The code snippet below examines a nuget package file (zip file with meta) and extracts all file names referenced inside. The final result should be a Set<string> with all file names. My problem is that the code looks like a nested Linq query in c# and the usage of Seq.iter blocks me to build the Set collection. Can you... | stackexchange/codereview |
I am trying to provide a fluent API for authorization based on roles.
As you will see I separated my implementation in two related Interfaces the Session and the Query. The session provides all roles, permissions and user information, so one may query it later via the Query object.
I also separated the implementation ... | stackexchange/codereview |
I use the following function in a PowerShell script to check and - depending on the value of the $Action - either add or remove an Active Directory User Object from a Security Group.
Function Update-Group-Membership ($Action, $ADUser_Properties, $GroupName, $LogPathFileName) {
$CurrentGroupMembers = Get-ADGroupMem... | stackexchange/codereview |
I have a tabs nav element that has two tabs, it needs to show a component based on what tab was clicked and hide the other component. If the clicked tab is already "active", the component needs to remain showing.
I have this working, but it seems very inefficient to me. Can anyone show me a better way to do this?
Her... | stackexchange/codereview |
I've been learning Python 2.7 for about a week now and have written a quick program to ask for names of batters and printing a score sheet. I have then added the names to a list which I will use more in other future functions.
I have a few questions:
I feel like there is too much repetition in my code, such as the pro... | stackexchange/codereview |
I have this counting sort for byte values running in linear time with respect to array length:
Arrays.java
package net.coderodde.util;
import java.util.Random;
/**
* This class contains static methods for sorting {@code byte} arrays.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Apr 24, 2019)
*/
public fin... | stackexchange/codereview |
I made a little program that allows users to download a local copy of all their GitHub repositories for backup purposes. I've tried to write idiomatic Rust code, but I'm sure there are ways I could improve my code as a novice:
extern crate github_rs;
extern crate serde_json;
extern crate hyper;
extern crate terminal_si... | stackexchange/codereview |
I want to write a simple binary file reader and writer class. The class below can read or write file. main.cpp read 500 bytes from tmp.bin and copy at the end of the tmp_copy.bin file. How can I improve my code?
binaryfile.h
#ifndef BINARYFILE_H
#define BINARYFILE_H
#include <fstream>
#include <string>
using uchar = u... | stackexchange/codereview |
Inspired by this question on Stack Overflow, I've attempted to code such animation, mostly to get some more practice with async, promises and Q.js:
(Live demo)
function addOutput(s) {
$('<div>').text(s).appendTo(wnd);
//return Q.defer().promise;
return Q.delay(100).then(function() { return addPrompt(); });
}
fun... | stackexchange/codereview |
I have tried to design the parking lot problem. Here is the problem statement.
Design a parking lot with multiple floors where customers can park
their cars. Each parking floor will have many parking spots. The
system should support multiple types of parking spots such as Compact,
Large, Handicapped, Motorcycle, etc. ... | stackexchange/codereview |
I encountered the concurrency-zip project in OSTEP By Remzi Arpaci-Dusseau. So basically, I've built a simple compression program that uses Run-length Encoding, and multi-threading in C. But I couldn't find any correct solution so I think I can use this forum for code review.
Essentially, the idea is based on Producer-... | stackexchange/codereview |
I don't remember the exact wording of the question, but it is clearly an activity selection problem, which is
[...] notable in that using a greedy algorithm to find a solution will always result in an optimal solution.
I put a rough description of the problem in the docstring, and present it together with my solution... | stackexchange/codereview |
Can you please review my code for reusability, clarity, readability and any bad stuff or bad practices?
Brief Description:-
Its a card memory-game, when you click two cards, it sees if they are same symbols and if yes, it matches them and keeps them open, if cards does not match it closes them and player tries to match... | stackexchange/codereview |
I've written a project for handling various Facebook things and I ran into the issue where one project named the users profile Profile while normally they would be named UserProfile. When I was checking if the FacebookUser model was related to a User, I could just User.objects.get(userprofile__facebook=facebook_user) ... | stackexchange/codereview |
What could I improve on this code?
from random import randint
guesses = 0
randomNum = (randint(0,100))
numPlayer = 0
while (numPlayer!=randomNum):
numPlayer = int(input("Guess the number(0-100)"))
if (numPlayer>randomNum) :
print "It's -"
elif (numPlayer<randomNum) : print("It's +")
guesses=g... | stackexchange/codereview |
Here's my attempt to write a function that flattens a nested dictionary structure in Python 3.6
This came about because I had a nested dictionary structure of data I wanted to visualize in the library Bokeh.
I didn't like other examples that require a recursive function call. (I find it difficult to reason about, and ... | stackexchange/codereview |
I'm working on a password brute-forcer that takes in a password from the user and brute-forces solutions until it finds a match. I was wondering if there is any way to improve performance or readability?
import itertools
import time
Alphabet = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXiuYZ1234567890-_.")
Pa... | stackexchange/codereview |
I wrote a C++ PEG packrat parser generator and would love to get some feedback on the code and/or syntax. I currently use the << operator for defining grammar expressions and linking the handler functions that are called when a rule is matched. These functions can then store a value of an arbitrary C++ type in the corr... | stackexchange/codereview |
This is my first attempt at making a singly linked-list class. Would this sort of implementation be sufficient for interviewing quality?
class Node(object):
def __init__(self, data, next_node = None):
self.data = data
self.next = next_node
def __repr__(self):
return str(self.data)
cl... | stackexchange/codereview |
Hi i have created a game of noughts and crosses in c++
I am new to this so the code is a bit messy, but i would love to get any feedback from you lot about the actual game and not the code for now.
main functions that i have added is playable music from the beginning which can be turned off in the menu and also the opt... | stackexchange/codereview |
This is another entry for The Ultimate Tic-Tac-Toe review.
My design criteria were:
A DLL which encapsulates the data, i.e. the game state
Don't include the GUI, nor the decision-making (game-playing) logic
Be careful not to allow corrupted state
Make it as small (few lines of code) as possible
Here's the DLL code:
u... | stackexchange/codereview |
I'm trying to improve my understanding of recursive and iterative
processes. I've started with SICP, but have branched off to try and
find a few exercises when I started having difficulty. Currently I've
been looking at a series of posts on the subject by Tom
Moertel.
Tom's code
defines a node object for binary search ... | stackexchange/codereview |
I did this spider that checks the stock of references list (around 3500 references).
Now the spider takes around 37 seconds to scrape 400 references. The CPU is around 5%, the network card (1Gbps) around 18%. My internet connection is 300Mbps symmetric and it's only connected to this computer.
Any idea to improve perfo... | stackexchange/codereview |
In PHP/Laravel I have the following function. Can you please review my approach?
private function array_swap_assoc($key1, $key2, $array)
{
$newArray = array();
foreach ($array as $key => $value) {
if ($key == $key1) {
$newArray[$key2] = $array[$key2];
} elsei... | stackexchange/codereview |
I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it.
fx.m file:
function v = fx(t,x,vx)
v = vx;
fy.m file:
function v = fy(t,y,vy)
v = vy;
gx.m file:
function v = gx(t,x,y,vx,vy)
global G M;
v = -G*M*(x/((x^2+y^2)^(3/2)));
gy.m file:
function v = gy(t,x,... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.