instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
I am new to Rcpp and am looking to make the following code as fast as possible. Any tips would be greatly appreciated.
It is running a lot slower than I would like.
I have tried vectorising as much as possible but i'm not sure how to vectorise further
In R I can vectorise this easily so i'm pretty sure it should be pos... | stackexchange/codereview |
I am creating a dialect of ActionScript 3.0 and now have a working verifier, or “symbol solving” verifier. The language upgrades ActionScript 3.0 with few operators, light syntax facilities, numeric enums and way more compile-time semantics.
To test verifying, run:
$ git clone https://github.com/shockscript/sxc
$ cd sx... | stackexchange/codereview |
I have a file named feedback.js that I would like to improve.
function feedback(feedbackform) {
// collect the feedbackform data while iterating over the inputs
var data = {};
for (var i = 0; i < feedbackform.length; i++) {
var input = feedbackform[i];
if (input.name && input.value) {
... | stackexchange/codereview |
Each client application would send a filepath and search term to the server. The server then takes that file path reads the file and returns any lines that contain the search term, the server then watches the file for any size increase and if the new lines contain wanted information it gets transmitted.
The first for l... | stackexchange/codereview |
First I would like to thank everyone for whatever help you may offer me. In full disclosure this is a project for a bootcamp class I have. My problem is, and I've asked them about this, that they aren't really teaching anything beyond beginner-level at General Assembly. This seems like the next place to come for the he... | stackexchange/codereview |
I've solved a problem Subset Component
Problem
You are given an array with n 64-bit
integers: d[0],d[1],….,d[n-1].
BIT(x, i) = (x >> i) & 1. (where B(x,i) is the i-th lower bit
of x in binary form.)
If we regard every bit as a vertex of a graph G, there exists one
undirected edge between vertex i and vertex j ... | stackexchange/codereview |
I have a comments page on my site and I was wondering if it is vulnerable to some sort of sql attack or something else. At the moment users can type what they want, they can even write a php script and it will upload to the database. Is this a problem and how can I fix it.
This is the script I use:
$name= $_POST['name'... | stackexchange/codereview |
Context:
I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a certain number of iterations. This question is about the modified version of the code I had posted on Stack Overflow.
Brief ... | stackexchange/codereview |
What is the correct way of referring to a view (a) or (b).?
(a).
TextView textView = (TextView) rootView.findViewById(R.id.text);
textView.setText("Some Text");
(b).
((TextView) rootView.findViewById(R.id.text)).setText("Some Text");
I sometimes use the combination of both in my code. Will that affect my structure ne... | stackexchange/codereview |
Thanks to Gurkenglas for the help with the previous iteration: Haskell - Pig Latin Translator!
Given the constraint that the newtypes are required, what improvements could be made to the following Pig Latin translator?
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
import Control.Monad (when)
import ... | stackexchange/codereview |
As a casual Rubyist I am mainly interested, how ideomatic my solution is.
class Integer
def divisible_by?(n)
(self % n).zero?
end
end
def fizzbuzz(upper_bound)
1.upto(upper_bound).map do |number|
next "fizzbuzz" if number.divisible_by? 3 and number.divisible_by? 5
next "fizz" if number.divisible_by?... | stackexchange/codereview |
Because I needed to execute some actions one by one in seperate thread (not to block GUI) and I couldn't use Task.ContinueWith from .NET 4.0 I decided to write it by myself.
Here is how it evolved thanks to your suggestions.
public class ActionQueue
{
private Thread _thread;
private bool _isProcessed = false;
... | stackexchange/codereview |
I'm trying to generate a report from two doctrine entities.
The fields to filter the report are optional. This is the code I've got now and it looks really bad to me. How can I improve this?
public function filter($accountNumber, $companyName, $branchName, $branchManager)
{
$em = $this->managerRegistry->getManager(... | stackexchange/codereview |
I'm new to Express and SQL, so I don't know the conventional ways of combining the two. Right now I have done it the following way:
app.get('/login', function (req, res) {
res.render('login');
});
app.get('/home', function (req, res) {
res.render('home');
});
app.post('/login', function (req, res) {
db = ... | stackexchange/codereview |
I wanted to use an external global state to a React.js application with a redux-like sort of pattern (with reducers, actions, etc). However, I don't want to use redux itself, as it's just a small project and redux might be too much boilerplate.
Below is a sort of imitation of Redux with React.js Hooks and State. It's a... | stackexchange/codereview |
In this LeetCode problem, Longest Palindromic Substring, it is listed under Dynamic Programming for Google interview preparation. My understanding of dynamic programming is roughly "recursion + memoization + guessing." In the Python solution to this answer below it is not clear to me where the dynamic programming is if... | stackexchange/codereview |
I do a single select in one radgrid, and based upon that selection I want to select multiple rows in a different radgrid:
<telerik:RadGrid ID="rgPaymentLines"> <ClientEvents OnRowSelected="RowPaymentSelected"/> ... </telerik:RadGrid>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javas... | stackexchange/codereview |
I'm starting to learn C and thought it would be a good idea to try and implement some data structures. I started with a very simple stack and would like to hear some opinions.
Stack.c
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
struct Node {
int element;
struct Node* next;
};
struct Node* head;... | stackexchange/codereview |
I'm currently learning C with "The C Programming Language" by K&R. At the moment I'm at the chapter about pointers (since I come from Java, they are new to me). In the book is an example code for a method getint(), which is supposed to read integers from input, but doesn't handle freestanding '+' and '-' correctly.
As... | stackexchange/codereview |
I am working on an HTML5/jQuery todo list app and here is my code so far.
As you might notice, there are some functions called at the beginning of the JS code. These functions work perfectly right now. Is it OK if I declare these functions inside the object literal and then call it using the object? In my opinion, the... | stackexchange/codereview |
I don't feel too comfortable with the use of object oriented programming and the related advanced topics. That's why I went through this exercise of using Python's abstract class to implement an abstract Ansatz class. (An Ansatz is basically something like a mathematical assumption, i.e. we might assume that our soluti... | stackexchange/codereview |
interface IJuiceable
{
void MakeJuice();
}
interface ISliceable
{
void MakeSlices();
}
class Fruit:IJuiceable,ISliceable
{
public string Name { get; set; }
public void MakeJuice()=>Console.WriteLine($"Juice from {Name}");
public void MakeSlices()=>Console.WriteLine($"Slices of {Name}"); ... | stackexchange/codereview |
Edit: This code was reworked and repostetd under a new question: Generic Skip list implementation in C++ Version 3
This is a follow up of:
Non generic Skip List implementation in C++
If you don't know what a Skiplist is: https://en.wikipedia.org/wiki/Skip_list
I continued the work on the Skiplist. I tried to incorporat... | stackexchange/codereview |
Is is possible to make this function more efficient and possibly more readable?
In addition, Am I doing this right? I mean, it works, but would it be better to do a complex query (with annotations) or a simple query and then process the result with a "pure python" code-block?
Here is the snippet:
def save_model(self, r... | stackexchange/codereview |
I wrote a simple game in Java using Swing. Code is working so far but I have no certainty that "spliting" into classes is done well. I would like to know what "design" problems I have in my code. Also I have a problem with understanding exceptions, I don't really know what to do when exceptions occurs. Terminate the pr... | stackexchange/codereview |
I have created the following view extending the JPanel class, the objective of this view is to allow the user to perform 3 CRUD operations create,delete and modify on the entity "Attribute", this entity belong to an entity User or Client, so when the user wants to perform CRUD operations it has to specify if the operat... | stackexchange/codereview |
I have the following array, and I want to convert it to an array without duplicates.
const a = [
{
items: [
{ outerKey: { innerKey: 1 } },
{ outerKey: { innerKey: 2 } },
{ outerKey: { innerKey: 3 } },
],
},
{
items: [
{ outerKey: { in... | stackexchange/codereview |
I was working on representing a large List of information on a number of different pages, and a colleague of mine suggested that I try to make a generic method for the task I was trying to perform:
private <T> List<List<T>> listSplitter(List<T> originalList, int splitCount) {
List<List<T>> listOfLists= new ArrayLis... | stackexchange/codereview |
I think that this code is very bad because it does not agree with DRY principle. Can you advise me how to improve it?
public void WhatSelected(object paramaters)
{
string ElementToProcess = BASM.FindElement(paramaters, true);
SeleсtedCurrent.Add(ElementToProcess);
int i = (from x in AssetS... | stackexchange/codereview |
I am trying to remove empty a String array from ArrayList:
List<String[]> someList = new ArrayList<String[]>();
which contains data like:
[
{ "Loic" , "Remy" , "Fail","Medical"} ,
{ "Faser" , "Foster" , "Pass","Southampton","GK","Young"} ,
{ "" , "" ,} ,
{ "" , "" , "","","",""} ,
{ "Emre" , "Can" , "Pass"... | stackexchange/codereview |
I'm trying to solve this problem with Python 3.8. In my code, I used 3 nested for loops to check every single point and storing the largest area with each set of points. This program works fine, but it's \$ O(n^3) \$ time complexity, and I'm wondering if there are any more elegant/efficient solutions. Is there a more e... | stackexchange/codereview |
Now that I have some infrastructure in place to test it (see my Battleship test framework and the updated GitHub project for the full context), I have finally written a non-trivial bombing strategy class for the May 2015 Community Challenge.
The SmartRandom class guesses randomly until it gets a hit. It then checks fo... | stackexchange/codereview |
Task Description:
Create a div-element and take control over it using a Vue-Instance.
Print an array of hobbies into the div-element. Provide some default hobbies.
Add a 'New Hobby' button and a text-input element. So that the user can add additional hobbies.
When a hobby list-item is clicked, it shall be removed from... | stackexchange/codereview |
I'm a new programmer and I'm periodically going into the Intro To Algorithms CLRS textbook and trying to translate pseudocode into Ruby for skill practice. This is my implementation/translation of insertion sort.
I'm looking for feedback on readability as well as efficiency.
Pseudocode is found on page 17 of Intro To A... | stackexchange/codereview |
I'm implementing std::once_flag and std::call_once for a particular MinGW build where they are not available, using only stuff available in the rest of the standard. The required semantics would be easy to implement with something like:
struct once_flag {
private:
std::mutex _M_mutex;
std::atomic_bool _M_has_ru... | stackexchange/codereview |
I'm looking for some input here. I have a class that contains a value which is updated every few seconds by a method within that class. Right now, access to this value across multiple threads is done via synchronization, which I would like to eliminate. Would this make sense?
class DataSegment {
private Metrics... | stackexchange/codereview |
I'm representing coordinates in a multi-dimensional array, and I'd like to stick as closely to native arrays as possible.
nArray.hpp
#include <stdexcept>
// Array that allows for negative integers
template <typename T, int SIZE> struct nArray {
private:
T array[SIZE];
public:
nArray() {
... | stackexchange/codereview |
To learn about concurrency in Clojure, I wrote a function that accomplishes the following:
Takes a (possibly lazy or infinite) sequence of functions representing tasks to be run asynchronously
Runs the tasks asynchronously and in parallel
Immediately returns a lazy sequence of promises that can be deref'd to get the r... | stackexchange/codereview |
I have made a sliding puzzle solver which is currently for 8-puzzles only. It works too slowly even though it is based on an A* algorithm whose f-score is calculated on the basis of Manhattan Distance and Linear Conflicts. But it solves all the cases correctly.
I would like to improve the time and space consumption of ... | stackexchange/codereview |
I have written a small class that works in extracting Snapchat usernames from common conventions of sentences, manipulating the positioning of certain characters to hopefully extract a valid username.
The script does have some partial protection for validity with its call to SnapchatUtilities.IsUsernameWellFormatted(ex... | stackexchange/codereview |
I'm currently learning about different sorting algorithms and after reading on the concept of the insertion sort of how it's done I've tried to implement it by myself before seeing how it was implemented in the source from which I'm learning.
This was my implementation:
void insertionSort(int arr[])
{
for(int i = 1... | stackexchange/codereview |
My program (which eventually will be containerised) should be able to do the following:
continuously listening for deployment and daemonsets in kubernetes (2 threads)
collect info needed (like annotations)
use the info collected in order to create objects in a remote database
I could use some peer review for the thre... | stackexchange/codereview |
There are two reasons why many people choose weak passwords over stronger, more complicated ones:
They don't know that their passwords are insecure
They don't want to change to a better password because they are generally more complicated and harder to remember
So, I came up with this program: a password trainer! It ... | stackexchange/codereview |
I have this Excel VBA function that takes three parameters. It is essentially a translation mechanism with the following parameters:
A sentence which has to be translated.
A range of words to look for and what to translate them to.
Shows in which column the translation is in the range (usually it's 2).
This function... | stackexchange/codereview |
I am practically brand new to coding and this is my first "real" project I've been attempting. It's an attempt at a vanilla JS game with selectable layout and win conditions (partially implemented). ATM it only has a vertical win condition included as I didn't want too much cluttering of the code (horizontal and diagon... | stackexchange/codereview |
I am trying to learn Elixir, so I decided to write a port of Ruby's Parslet library. I want to define a DSL that lets you define your grammar and given a string can parse it into an AST.
I wrote something, but it's not very idiomatic. I'd love some pointers. Also, I wanted to be able to define rules as follows:
rule :t... | stackexchange/codereview |
How can I improve this code (elegance, best practices, etc)?
""" Simple in-memory database as a response to the Thumbtack coding challenge. """
class SimpleDb(object):
""" Simple in-memory database as a response to the Thumbtack coding challenge. """
def __init__(self):
""" Initialize SimpleDb insta... | stackexchange/codereview |
I want to check the memory usage of a process before and after I copy a large file or folder, and also, I want to get the maximum memory usage during file operation. Is this a good method?
def copy_folder(s,d):
if os.path.isdir(d):
shutil.rmtree(d)
shutil.copytree(s, d)
return get_folder_size(s)
de... | stackexchange/codereview |
I have multiple multidimensional arrays that each have the same structure with different lengths.
arr1 = [["23 Jan",3],["29 Jan",10],["19 Jan",23],["25 Jan",23]]
arr2 = [["31 Jan",7],["29 Jan",12],["01 Feb",4]]
My result would be a merged array without duplicate dates ordered by the date. For the dates that get combin... | stackexchange/codereview |
This is my first attempt at some moderately complex Rust code. Unfortunately, it feels very clunky to me, and I feel as if I am not using all of the features properly:
use std::collections::HashMap;
fn main() {
let mut table: Vec<HashMap<&str, Vec<&str>>> = Vec::new();
table.push(HashMap::new());
table[0].... | stackexchange/codereview |
Inspired by the work Charles Duffy did in this answer and the work of Jonathan Leffler in this one and because I couldn't leave well-enough alone.
I went and wrote expandTilde.sh:
#!/bin/bash
doExpand() {
local path
local -a resultPathElements
for path in "$@"; do
: "$path"
case $path in
"~+")
... | stackexchange/codereview |
I'm getting started on template meta-programming and I wrote a template to compute compile-time positive and negative float powers of 2. I would like some feedback on readability and overall code complexity as I feel like I might be defining too many structures for such a simple computation. The code has to be C++98 co... | stackexchange/codereview |
I'm solving this simple challenge:
Given a vector A with N unique elements greater than 0 and lower or equal than N+1, find the missing element. Example:
A = [1,3,2,5] -> missing number 4
A = [1,3,5,4] -> missing number 2
I've come to the following solution. I'm interested in thoughts and ideas on how to write it as ex... | stackexchange/codereview |
This is a follow-up from my previous review on this site. To be clear, the code is stand-alone, and does not depend on the previous review.
As before my goal is to come up with a design for a chess engine in Kotlin that hides implementation details, and that ensures that the implementation cannot accidentally become sp... | stackexchange/codereview |
I'm comparing two distinct instances and if they are not the same I save to the dB, so I've given snippet of code below of the way I am comparing these instances, I realize I could use reflection and generalize but short of using reflections is there any other way I could optimize the code or make it neater?
publ... | stackexchange/codereview |
This bit of code initializes an array of any given size where each index corresponds to a thread and a value. That is, index 0 has 0, index 1 has 1, and so on. Then, the values, 0 to n, in the indexes are summed.
This code as part of an assignment though I'm wondering if there are any ways it could be improved? Namely... | stackexchange/codereview |
I am currently changing the background colour of a sidebar each time a menu item is clicked using the following code:
$( 'a[href = "#masthead"' ).click(function() {
$('#sidebar').css('background-color', '#3b6dac');
});
$( 'a[href = "#section2"' ).click(function() {
$('#sidebar').css('background-color', '#23d4d7');... | stackexchange/codereview |
I do not program PHP too often. I wanted to write a dice-roller bbc code parser for my forums. What do you see that can be improved?
You can see the code running live here: https://joshuad.net/misc/dice-test.php
<html>
<body>
<p>
<h2>Syntax</h2>
<ul>
<li><strong>Basic Rolls:</strong> NdM: Roll N dice with M sides. i.e... | stackexchange/codereview |
Here I'm trying to develop a simple framework for my own purpose. I'm using PHP and PDO. But, I'm still worried about my password security codes. Below I have posted my codes. it stored like these in my database $1$sr1.F90.$hXd.9DheSMtYmI52KT7fy0. Is this the right way to store passwords? Or Am I make anything wrong he... | stackexchange/codereview |
It is a usual pattern when creating a new component, to load references to other components of the same GameObject. Here is an extreme case:
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(SpriteRenderer))]
[RequireComponent(typeof(Stats))]
[RequireComponent(typeof(Hunger))]
[RequireCo... | stackexchange/codereview |
Taken the following Exercise from Cracking the coding interview:
Given a linked list which might contain a loop, implement an algorithm that
returns the node at the beginning of the loop (if one exists).
EXAMPLE
Input: A -> B -> C -> D -> E -> C [the same C as earlier]
Output: C
My Solution here was to store each ... | stackexchange/codereview |
The latest new refactoring for our friend Rubberduck is Encapsulate Field:
This image, for the sake of brevity, shows the result of the refactoring and the UI together. The three properties below the field are what is inserted by it.
All together, I am pretty satisfied with the code, so I need you to inspect it and he... | stackexchange/codereview |
Well, I'm trying to generate the following:
Input:
Level1a/Level2a/Level3a/Level4a
Level1a/Level2a/Level3a/Level4b
Level1a/Level2a/Level3a/Level4c
Level1a/Level2a/Level3b/Level4a
Level1a/Level2a/Level3b/Level4b
Level1a/Level2a/Level3b/Level4c
Level1a/Level2a/Level3c/Level4a
Level1a/Level2a/Level3c/Level4b
Level1a/Level... | stackexchange/codereview |
I've been playing around with C# 7 and created this if-less and switch-only command-line parser. What do you think of it? Can it be made more C# 7 or otherwise improved? Is the new switch a good alternative to the old if/else?
It splits a string by |=|: (space, equal-sign, colon) into tokens (unless escaped) and remov... | stackexchange/codereview |
Given an array of non-negative integers, find the largest multiple of 3 that can be formed from array elements.
For example, if the input array is {8, 1, 9}, the output should be "9 8 1", and if the input array is {8, 1, 7, 6, 0}, output should be "8 7 6 0".
Looking for code-review, best-practices and optimizations.
... | stackexchange/codereview |
I have the following jQuery which applies a class to my fixed header to shrink it when the user is scrolled any distance down the page:
$(window).scroll(function() {
if ($(this).scrollTop() > 1){
$('div.single-level-nav').addClass("shrunk");
}
else{
$('div.single-level-nav').removeClass("shrunk");
}
});
... | stackexchange/codereview |
I came up with this code after implementing the feedback given by @200_success. The previous one (A faster way to compute the largest prime factor) tested my patience, but still failed to give the answer on time. This one is an improvement as it gives the answer without much delay.
The question (Euler project problem #... | stackexchange/codereview |
As an interesting sub-part of an interpreter -- just the Read part of the REPL -- I present my raw-mode line-oriented editor that I intend to use for my APL interpreter. (The Eval part has been posted for review in comp.lang.c.) It defines a large character-translation table to coordinate the input-form/internal-rep/ou... | stackexchange/codereview |
I needed a mapper for a project I have using Dapper. I tried Automapper and other tools that comes with Dapper (Contrib, Rainbow, etc.), but I couldn't make Automapper work properly and the rest doesn't have what I need, so I did one.
Take in mind that I'm an amateur and not native english speaker ;)
The whole thing is... | stackexchange/codereview |
my use-case (an home task to practice abstraction, exception handling, unitests) is regarding a message-queue with small-fixed-size client requests from stdin of such:
[ENQ] data (insert json data to queue)
[DEQ] (get latest in queue)
[STATUS] (status of queue)
[STOP] (stop server)
[EXIT]
Without an... | stackexchange/codereview |
I'm using WinForms and have a picturebox in my form. This program looks in "C:\image\" directory to find a specified image document, in my case a tif file. There is always only one picture in "C:\image\" directory.
After it locates the file, the program displays the image document in the picturebox.
When I was running ... | stackexchange/codereview |
I'm trying to isolate a webservice in its own class, and I plan to add separate classes to each webmethod there is in the webservice. What I have so far works, but I have this feeling tickling that I've missed something (except for the invisible variable declarations down here, I didn't want to clog the page).
Webserv... | stackexchange/codereview |
Continuing on my VB.NET quest, I came across this slightly more challenging problem.
You are given a 2D matrix, a, of dimension \$M\$x\$N\$ and a positive
integer \$R\$. You have to rotate the matrix \$R\$ times and print the
resultant matrix. Rotation should be in anti-clockwise direction.
Rotation of a 4x5 matri... | stackexchange/codereview |
Here is how to transform a Zorglub (it is an API that I can not modify):
Zorglub transformedZorglub = zorglub.transform()
I am given a java.util.List<Zorglub> and I must transform them all, then afterwards I will perform more operations on the transformed Zorglubs. After transformation I never use the originals anymor... | stackexchange/codereview |
I made a simple mp3 player that plays, pauses and stops a given song, shows the time elapsed, and has a volume control. I read the documentation and can't figure out the difference between the pause and stop methods, although I have configured them to work as I want (i.e., pause lets you resume from where you left off... | stackexchange/codereview |
I have implemented a dynamic array in C. I am a beginner in C so any constructive feedback about improving the implementation would be greatly appreciated.
Header file for the implementation( dyn_array.h)
#ifndef TYPE_H
#define TYPE int
#define TYPE_SIZE sizeof(int)
#endif
#ifndef STDDEF_H
#include <stddef.h>
#endif
... | stackexchange/codereview |
The function below simple allows a logged in user to "star" another user for convenience when trying to find the that user another time. At the moment the function works as it should, it inserts the user giving the star and the user receiving the star into a database table, then grabs the first name and email from the ... | stackexchange/codereview |
At first, I have this HTML I use here:
body {
text-align: center;
}
<form method='post' action=''>
<input type='text' placeholder='post' name='post'>
<div>
<input type='text' placeholder='ref1' name='ref1'>
<input type='text' placeholder='ref1id' name='ref1id'>
</div>
<div>
<input type='text' pl... | stackexchange/codereview |
I worked on my code a bit from the earlier post and was able to make it work. I am new to C++ so please be kind.
I basically have two questions apart from the peer review.
When I use templates definitions in a header and just call it from source, it doesn't work. Why?
To make it work using strings I want to use a type... | stackexchange/codereview |
As an exercise to learn more about multi-threading and atomic operations work in C++, I decided to implement a latch class in C++11 loosely based off of std::latch class from C++20 and would like to know whether this implementation is flawed in any sort of way or form and how I could improve upon it:
#include <cstdint>... | stackexchange/codereview |
I have created a quiz function in my rails application. Since I want to track responses and make it a server-side application I created a table to record the responses of the questions people answer.
create_table "responses", force: :cascade do |t|
t.bigint "question_id"
t.bigint "answer_id"
t.bigint "user_... | stackexchange/codereview |
# Program will display a welcome message to the user
print("Welcome! This program will analyze your file to provide a word count, the top 30 words and remove the following stopwords.")
s = open('Obama 2009.txt','r').read() # Open the input file
# Program will count the characters in text file
num_chars = len(s)
# P... | stackexchange/codereview |
I've written a simple script that calculates the distance between two points in time and returns the duration.
Example: Start - 11:00, End - 11:45, Duration - 0.75
I wanted to make use of ES6 classes and I'd like feedback on the Duration class in particular. For example, should the validation of the start and end argum... | stackexchange/codereview |
Inspired by my merge sort in Scheme, I thought I'd try my hand at implementing other sorting algorithms, starting with simple ones (like insertion sort) and working my way up. So, here we go:
(define (insertion-sort lst (lt? <))
(fold-right (lambda (item sorted)
(let-values (((lhs rhs) (span! (cut lt?... | stackexchange/codereview |
I'm working on a web framework in C++ and there's this part that I need to do something like this:
using valves;
App app;
app.on( (get or head) and "/home"_path , [] (auto &req, auto& res) {
// ...
});
(The code above is not a semi-code, it'll be like that exactly)
In order to implement the (get or head) and "/ho... | stackexchange/codereview |
Can you review the following code to check to see if the Minimum Image Convention is properly implemented?
import random
import math
import matplotlib.pyplot as plt
polymer_chain_vec = []
N = 9
sigma = 2
epsilon = 2
periodic_boundary_int = 5 # size of the periodic box in A
temperature_float = 2 # temperature of the ... | stackexchange/codereview |
A project to automate file organization in Linux using Python. I've always wanted to do this project way before I know how to code. Now that I did, I want to improve it even more.
Used Language: Python.
Compatible System: Linux.
Used Modules: OS Module.
How it works:
When you save/move/copy a file to one of the main d... | stackexchange/codereview |
I've been working on my own dynamically-typed, dynamically-scoped, imperative programming language called Honey Badger and feel that it's reached a stable enough state that I want someone else's eyes on my implementation of the interpreter.
For context, I'm going to walk you through a sample program in the
language ... | stackexchange/codereview |
I have a userform that displays a goal time for workers to shoot for when completing a task. It also has a stopwatch on it that is controlled by a start, stop, and reset button on the userform. If the stopwatch time reaches the goal time and goes over, then there is a box called "extra time" that starts counting up. It... | stackexchange/codereview |
I'm using the repository pattern with a context and ninject as the IOC. I have a service which handles getting and setting page properties in the database.
public class MyContext : DbContext
{
public MyContext() : base ("DefaultConnection")
{
}
public DbSet<PageProperty> PageProperties { get; set; }
... | stackexchange/codereview |
A Collatz sequence for a given positive integer \$n\$ is to take half of \$n\$ if even and \$3n+1\$ if \$n\$ is odd; repeat until the value goes to \$1\$. The question is which number from 1 to 1,000,000 has the longest Collatz sequence?
The Collatz sequence for \$n=13\$ from Project Euler #14:
13 → 40 → 20 → 10 ... | stackexchange/codereview |
I wrote a simple python port scanner today and I would like to get some advice on how to improve on the code in different ways.
I am aware that I can implement threading to reduce runtime but I won't for now as it feels a bit advanced at this time. Rather I would like tips/opinions on how to improve the program in othe... | stackexchange/codereview |
Does anyone have suggestions on how to improve this?
Specifically:
Am I passing and returning references correctly to prevent unnecessary copying?
Am I using destructors and the delete keyword correctly to prevent memory leaks?
Am I throwing exceptions correctly?
Also, just wondering whether it would be possible, wh... | stackexchange/codereview |
I have a very large class which serves as the BaseClass for many AdapterClasses. The base class consists of methods that can be categorized as follows:
Translation: fundamental translation classmethods used by all AdapterClasses. Requires class attributes from AdapterClasses (used internal / external) The tricky part... | stackexchange/codereview |
I have two javascript functions that generate a D3 Stream graph. I feel I may be excessively and unnecessarily iterating over my dataset to get it into the desired form.
How might I optimize or simplify this?
d3.json("/sleeps", function(d) {
sleepStream(d);
});
function sleepStream(d) ... | stackexchange/codereview |
I did the following code challenge for a job interview. They apparently didn't care for my solution and I'm not sure why.
What could I have done better?
Here is the challenge:
Create a small app with the following characteristics:
With the device in the portrait mode, display a fragment with a single
EditText instr... | stackexchange/codereview |
I'm working on writing code which gets several pieces of an image, and reconstructs them to one whole picture. The images are represented by matrices, and two pieces should be "glued" if the right column of one matrix is the same as the left column in the other one.
from images import *
def reconstruct_image(m):
... | stackexchange/codereview |
My program has to detect the real file type of a given file using signatures. For now I'm just checking JPG, but I want to add more.
Dim files() As String = IO.Directory.GetFiles(pictures)
Dim file_data As Byte()
Dim jpg_file_extension() As Byte = {&HFF, &HD8, &HFF}
Dim office_file_extension() As Byte = {&H50, &H4B, &... | stackexchange/codereview |
One of the inspections we wanted to implement in Rubberduck for the next release, is one that finds all unassigned variables in a VBA project.
Implementing this inspection has been ...complicated (it's the most complex inspection in the Rubberduck code base so far). Here's the code:
public class VariableNotAssignedIns... | stackexchange/codereview |
Here is my breadth-first search (bfs) and depth-first search (dfs) code for graph traversal. Please give me some constructive reviews on it.
#include<stdio.h>
#include<stdlib.h>
#define null 0
typedef struct node//node of a linked list
{
struct vertex* info;//info part of node
struct node* next;// next point... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.