instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
I'm learning how to use Python with the Raspberry Pi. I successfully followed the tutorial for how to have a Python script run on the Pi to check for new email and turn on an LED if any new messages are in an inbox. I wanted to give myself a challenge by adding a feature to blink a secondary LED to indicate the number ... | stackexchange/codereview |
This script creates an adhoc network using hostapd.
I have tested it and seems to work reliably.
I am new to linux networking and not sure if this is a recommended way to create an adhoc network this way.
#!/bin/bash
#set -x
DEVICE=wlan0
CONFIG_FILE=./hostapd.conf
ConfigureDevice()
{
if ! sudo iwconfig 2>/dev/null ... | stackexchange/codereview |
I have written a code that will parse JSON file from a cuckoo report.
The issue is am not a good coder. I have got the program to give me the desired output.
The real challenge that I am facing is I have written multiple file open and close. How can I reduce it to a minimum? Because the JSON file are huge and the parsi... | stackexchange/codereview |
I'm trying to optimize my code (time optimization) based on this problem:
Let S be a set of strings. Each string in S is associated with a
set of elements. Consider, for example, S = {"home", "tree"}.
Implement a data structure that is a collection of sets and supports
the operations Union, Move and Print. Initi... | stackexchange/codereview |
I'm updating a solution that I wrote a while ago. I've got a WinForm that does Update/Insert/Delete on a particular database table.
I've got all of the database access code in the form. Is this bad practise? On the one hand, I know you should separate presentation and data access. Also, it would make unit testing easie... | stackexchange/codereview |
For educational purposes, I have implemented the AES block cipher in python. I decided to follow the interface for block cipher modules as defined in PEP 272. The implementation consists of two python files, aes.py and block_cipher.py
aes.py (~300 lines of code)
# coding: utf-8
"""
Advanced Encryption Standard.
The ... | stackexchange/codereview |
Please review this code :
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
float height[4]={17.5,8.4,2.9,7.9};
ofstream file;
file.open("BINARY.DAT", ios::binary | ios::out);
file.write((char*)&height, sizeof(height));
for(int i=0;i<4;i++)
height[i]=1;
file.close();... | stackexchange/codereview |
I'm newbie in Python but I want to know some tricks to make my code look cute. I know that syntax of Python allows to do this, but I don't know how.
Suppose I have file with lines of format "x y z" and I want to parse it and make some objects. Now code looks like this:
class Point(object):
def __init__(self, x, y, ... | stackexchange/codereview |
I am trying to make a very simple error handler that would catch and handle all kinds of errors in both development and production environments. The idea is to keep it as simple as possible yet useful in the production environment.
In order to do so I am converting all errors into exceptions. Then I will need just a si... | stackexchange/codereview |
I came up with a small optimization while practice coding insertion sort in Python. It's mostly about not accessing the input array too much and letting the hardware do element shifts instead of swapping manually. Could someone comment on my coding style as well as the optimization idea?
Original Version
# this version... | stackexchange/codereview |
Just finished creating my first bot using Discord.js for the chat application, Discord. This is my first bot and first javascript program I have ever created. I'm mainly interested in ways I can optimize the code and make it a bit cleaner. Any help or suggestions is greatly appreciated.
Github Repo
Main:
/*
File: Jarvi... | stackexchange/codereview |
I have this code which compares two adjacent time stamps. If they are less than 15 min apart, it adds a new time stamp (row) in between with the new time stamp equal to the previous time + 15 min and value equal to the previous time stamp. If there is more than one-time stamp missing (more than 15 min interval), it add... | 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 |
Cost of nodes are represented by a matrix (called world), heuristic cost estimate/g score/f score are all represented in matrices.
The world and its size are stored in global dynamic variables. It looks like this:
1 1 1 1 1
1999 1999 1999 1999 1
1 1 1 1 1
1 1999 1999 1999 1999
1 1 1 ... | stackexchange/codereview |
I have two collections - Movies and Watchlist. Both of these have Views that output Movie and WatchlistMovie Views. If you click add on a movie you should see it appear in the Watchlist colum`. If you remove then the movie should be removed. When clicking the add and remove buttons the view should rerender to show the ... | stackexchange/codereview |
I am trying to throttle SemaphoreSlim (i.e. allow initialization with a negative initialCount). A scenario could be that you're hitting an API and may notice degradation due to a server overload, so you'd want to start throttling requests to, say, 10 concurrent requests. However, you would be keeping count of the concu... | stackexchange/codereview |
Level traverse binary tree question:
Given a binary tree, return the level order traversal of its nodes'
values. (ie, from left to right, level by level).
For example:
Given binary tree {3,9,20,#,#,15,7},
3
/ \
9 20
/ \
15 7
return its level order traversal as:
[
[3],
[9,20],
[15,7]
]
Th... | stackexchange/codereview |
Scenario: Count the total number of times a char occurs in a word.
For instance, "aaabbcccdddaaaa" should print out "a7b2c3d3".
Can you please critique my code?
import java.util.HashMap;
import java.util.Map;
public class Demo {
public static void main(final String[] args) {
final Demo d = new Demo();
... | stackexchange/codereview |
I have seen programs to solve sudoku puzzles but to be honest.. They were badly written.
First of all, readability of the program itself was horrible and the code was really long and confusing.
So I decided to start from scratch, using my own style to write really good solver.
What I have this far is reading a board in... | stackexchange/codereview |
This is a follow-up to this question with bug fixes, question and code improvements from @dfhwze, @PieterWitvoet, @HenrikHansen, @t3chb0t. I am still hoping for an improved approach or algorithm rather than micro-optimizations to the code.
.Net provides String.IndexOfAny(string, char[]) but not String.IndexOfAny(string... | stackexchange/codereview |
I want to check if the length of phone number is appropriate for specified country (let's consider that only some countries have restriction, another countries accept phone number with various length). I have a Map, where the correct pairs are defined so this map can be used as a reference in the condition:
public stat... | stackexchange/codereview |
Input: An array of integers.
Output: That same array, but with the even numbers at the front and the uneven numbers at the back of the array.
I wrote three different solutions, depending on the needs of the client.
First solution:
// linear time not stable and not in-place
private static void partition1(int[] a){
/... | stackexchange/codereview |
I've implemented Conway's Game of Life using the raw Windows API and GDI as an exercise. I'm wondering if there is room for improvement, though.
Beware, large amount of code following:
CGOL.h:
#include <Windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <time.h>
#include <sal.h>
#define IDT_TIMER1 1001
#de... | stackexchange/codereview |
I have addressed the critique for this post and resubmitted it for iterative review; C++ multithread pool class.
Class for creating thread pools with the latest C++ standard. Currently C++17 and C++2a.
It currently only accepts and executes parameterless routines.
Multiple functions may be enqueued via variadic templa... | stackexchange/codereview |
I was recently presented with the following problem...
You are given a collection of singly-linked lists (SLLs).
Return true if any of them share a common node (or “intersect”), or false otherwise.
Additional notes
Please don’t use recursion.
Assume the SLLs might be very large in length (in the millions).
Stop traver... | stackexchange/codereview |
I have a type that models the Arithmetic concept and use it as an opaque typedef (AKA strong typedef, see Note below) in some projects.
I've put the code into its own repository along with some tests and would like some eyes taking a look into it.
Note: for opaque typedef I understand the definition given in N3515.
P... | stackexchange/codereview |
I am trying to create a web crawler for student research. I have already finish it, but I would like to tell me if the way I use is the best one. (probably it isn't :p)
The crawler is for the cnn site and the only thing I want to get, is the text of the news.
Here is an example link: link
Here is my code:
def cnn_crawl... | stackexchange/codereview |
In my rumblings developing flask applications I found the caching decorator. The decorator is a short and well-written piece of code, but I feel like it misses the few points bellow:
It only caches on the server side and doesn’t leverage the
client-side cache - meaning that clients still have to go and hit the
server ... | stackexchange/codereview |
I've been doing some JavaScript for fun again. This time I tried my hand at drawing the Dragon curve - a neat fractal that consists of one line traveling across the plane, never crossing itself, and creating an interesting shape in the process.
There's several ways to go about generating the Dragon curve; for instance,... | stackexchange/codereview |
From Coderbyte:
Have the function StringReduction(str) take the str parameter being
passed and return the smallest number you can get through the
following reduction method. The method is: Only the letters a, b, and
c will be given in str and you must take two different adjacent
characters and replace it with ... | stackexchange/codereview |
I was given 15 minutes to write the code to reverse a singly-linked list.
What do you think of the code style here?
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LinkedListQuestions
{
[TestClass]
public class ReverseLinkedList
{
[TestMethod]
public void ReservseLinkedListTes... | stackexchange/codereview |
I will try to be as concise as I can:
The goal: trying to universalize a specific section of a project, that is dealing with the SQL database transactions.
To assist you with your answer, I've pasted the following (just for reference):
a usage code: GetTestOfTablTime() returns a DataTable
class: SQLDBInteraction is a... | stackexchange/codereview |
This program has the goal to teach the user words of another language. The user has to learn words of a current section and than they get tested. The program can be modified easy. The programmer just has to add the new name of the language and the corresponding translations in the Words class.
I would like to know how ... | stackexchange/codereview |
A few days ago I finished a coding challenge for a potential job.
I was super happy with my code, till I got the response that my code wasn't good enough. :( So, apparently I'm still making mistakes, I've asked for feedback but no response. I really want to know what are my weak points are so I can improve.
Can anyone ... | stackexchange/codereview |
I have <button>s that when pressed expand or collapse the contents of all the <details> within the document. The code works, but as a novice in JavaScript, I am not very confident in its performance and/or efficiency. Could you please review it.
expandDetBtn = document.getElementById("showBtn");
collapseDetBtn = docu... | stackexchange/codereview |
I have written Haskell code to my spec to help me grasp types and syntax, because I am learning.
I hope to generalize it further to accommodate more kinds of equations. I am (perhaps prematurely) worried that repeated usage of delta in multiple places is going to slow down my code, but I don't see how I can avoid it.
I... | stackexchange/codereview |
The following code was written to create custom directory listings for the Abyss Web Server. It attempts to provide an improved example of the included documentation for doing so in Python. However, some modules such as cgi and cgitb are deprecated and should be replaced to modernize this example code even more.
Could ... | stackexchange/codereview |
Method implemented in parent class (extends SherlockFragmentActivity) (source)
ViewPager viewPager; // initialized in onCreate method
public void toggleActionBar() {
try {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
Frame... | stackexchange/codereview |
I have created a program but I feel the def common(friendships, person1, person2) function can be more efficient, if anyone has any good idea how I can improve it I would appreciate it.
from My_graph import Graph
def friends_of_friends(friendships, person):
"""Return the set of friends of the person's friends.
... | stackexchange/codereview |
I have the following redundant-feeling design to convert between enums and strings regarding a class that stores enums. The approach doesn't scale if there are more enums and in any event, less-redundant code is also better.
Questions
If there will be more enums, would it be possible to avoid defining two explicit con... | stackexchange/codereview |
I try to make a middleware stack system in the rack way (but not for HTTP request).
Here is the main class:
class MiddlewareStack
def self.stack middleware
@middlewares ||= []
@middlewares << middleware
end
def self.middlewares
@middlewares
end
def self.next payload
next_middleware = @midd... | stackexchange/codereview |
This code is used to toggle buttons within a div:
var chosen = {};
var form_name = 'the_div';
function(what) {
if('number' != typeof what) { // toggle-one
var el = $(what);
var name = el.html();
var ch = ['success','default'];
if( !chosen[name] ) ch.unshift(ch.pop());
el.remov... | stackexchange/codereview |
I have the structure Corporation/Company/Facility/Storage and only Storage could be part of Facility, and Facility could be part of Company, and Company part of Corporation. My main problem is for the code to work I need to add the Corporation to itself.
public class BusinessEntityData
{
public Guid ID { get; set; ... | stackexchange/codereview |
I want to get some practice in writing C libraries and so started with something I can use straight away, a logging library. It is very basic and only has two levels: log everything and log only errors. Use logd (log debug) to log any low level thing and if log everything level set, that item will be logged. Use log... | stackexchange/codereview |
I am trying to find missing positive integer in an. array.I don't know where my function not working ?
question given
Given an unsorted integer array, find the first missing positive integer.
Given [1,2,0] return 3,
[3,4,-1,1] return 2,
[-8, -7, -6] returns 1
my function works on following above cases works fine..
... | stackexchange/codereview |
i do have two dimentional array of data in php.
I do want to add another column with constant to that array for passing tabular data to next program.
i am iterating and adding manually. What can be alternate code?
my code:
if( is_array( $arrSource )){
foreach( $arrSource as &$dataRow){
... | stackexchange/codereview |
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
var async = require('async');
var context = {};
context.settings = require('./settings');
async.series([setupDb, setupApp, listen], rea... | stackexchange/codereview |
I am concerned about creating too many objects in my code.
Am I using duplicate code? Can I cut down on the number of lines of code?
Note: I only want to use recursion to solve this. Any suggestions on the design of the program and naming convention used here are appreciated.
import java.util.ArrayList;
class Subse... | stackexchange/codereview |
I wrote the following atexit implementation for Bash
#! /bin/bash
set -e
ATEXIT=()
function atexit_handler
{
local EXPR
for EXPR in "${ATEXIT[@]}"; do
echo "evaluating $EXPR"
eval "$EXPR" || true
done
}
trap atexit_handler EXIT
function atexit ()
{
local EXPR
for EXPR in "$@"; do
ATEXIT+=("$E... | stackexchange/codereview |
In one of my app, i m using custom navigation bar view to handle all Navigation Bar Properties.
Is it good practice to use custom navigation in given below way? Any Optimizations need to be done. It would be helpful to me, if you have any valuable suggestions.
Source Code ---->
.h
#import <UIKit/UIKit.h>
@protocol VCN... | stackexchange/codereview |
This is my 1st F# program so I'm open to any and all criticism on my syntax and the way I approached the problem.
Challenge
Project Euler 16: Power Digit Sum
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
open System
open System.Numerics
let digitP... | stackexchange/codereview |
Like the title suggests, I wrote a script in Python that uses the python3-lxc library to automate the creation of Linux LXC containers. I realised that containers can be great when I'm writing (and even installing other) apps and setting up FreeBSD-ish* jail environments to organise my workspaces for whatever project t... | stackexchange/codereview |
Task
Input - integer number (year)
Print one number - the next year, in which all digits are pairwise different, and there are no digits 2 and 0. If there will never be such a year, print -1.
My solution (correct)
Could you please recommend time / space complexity optimizations?
vector<char> toVec(int n) {
vector<c... | stackexchange/codereview |
I am upgrading a traditional jQuery based app by converting a few parts of it into ReactJs components and use Socket.io for the data transfer medium.
There are a few React components spread across the page. The React components will receive updates from the socket connection in their componentDidMount method.
For examp... | stackexchange/codereview |
I have a method which takes a certain generic object, which basically orders these objects based on a list of tags. Because I want to use this method for multiple objects, I have created a class which only contains the Id, list of tags and an average rating from each object, it looks like this:
public class Recommender... | stackexchange/codereview |
A project I'm working on often has lists within lists within lists etc. The original author often uses complicated linq expressions, but when adapting them I mostly get hopelessly bogged down and resort to foreach's which makes me feel like a lesser being (joke). With an expression such as the following, what would t... | stackexchange/codereview |
I am learning about clean and maintainable code. I heard that functions should be no more than 20 lines long (preferably 5 - 10 lines). I have come across this Bob Martin quote where he said:
“The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than tha... | stackexchange/codereview |
I'm quite new to trying to write my own macros and I've been able to piece this one together, but it takes quite some time to run. Here is the macro for one value (I have to create workbooks for ~20 different values). Are there any ways I can improve its speed?
Also, I am assuming I can just replicate my For/Next loop ... | stackexchange/codereview |
All that the program does is query a database that I have setup, when the user selects the returned fields, which are populated based on the selection of the field above it.
The application is basically 3 classes:
DbConnect: Generates queries that are sent to the database
Nested - QueryFields: Contains all user-sel... | stackexchange/codereview |
I am a student doing their AS Computing course and I have created a piece of code in which a message can be typed and then scrambled by moving letters along the alphabet. I was wondering if anyone knew any way in which this could be improved.
while(True):
message = input("What would you like the message to say? ").low... | stackexchange/codereview |
The following code I am using to lookup the description based on a "Partition Type" in either a string, an integer or hex value. By calling parttype(parttype) in the below code.
Is there a more pythonic way for this?
__PARTTYPE_TO_DESCRIPTION__ = {
"00": "Empty",
"01": "DOS 12-bit FAT",
"02": "XENIX root",
... | stackexchange/codereview |
This is part of a game made in Unity3D.
I wrote this class to convert geographic coordinates into lambert 2008 coordinates based on this reference document:
http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf
Reason is that I'm using a Belgian National Geographic Institute map as background, a... | stackexchange/codereview |
I have written the following code using a dynamic programming technique. Can I use ArrayList here? Please let me know if I can improve this code.
package com.java.fib;
import java.math.BigInteger;
import java.util.HashMap;
public class Fibonaci {
public static void main(String[] args) {
System.out.prin... | stackexchange/codereview |
I've written some classes to encapsulate the limits given for datasheet parameters, e.g. for the classic 741 op amp:
As the above example datasheet snippet shows, there are some challenges for representing the values in the "min", "typ" (typical), and "max" columns -- including cases where there is no typical value, a... | stackexchange/codereview |
I'm still working on a parser that can parse log entries from a game called HearthStone, the overall idea is that it will read the log file live when the game is running, parses the log file and show interesting and useful data in real time.
For the question the focus is on the API I have created to parse log entries. ... | stackexchange/codereview |
I'm looking for ways to make this calculator more efficient and/or make the code a little easier to read.
#include <iostream>
#include <cstdlib>
using namespace std;
// variables to be used in the program
double result, valueA, valueB, valA, valB;
int choice;
char cont;
//functions to perform the calculations
doub... | stackexchange/codereview |
I'm currently creating a client/server application (using Java) and I want to make it fully controllable by an input stream (currently the console). At the moment only one class have to be controlled, but I want my code to stay easy to develop.
I found a solution but I think I can do better, so that's why I post this m... | stackexchange/codereview |
I'm creating my own little toolbox for pinging IP interfaces (for the test, only in localhost). In the future I'm thinking of piping the output to a text file. But I'd like to focus on improving the performance for now.
For now, scanning a class A IP range is pretty fast, but for a B range (65025 addresses) it's very l... | stackexchange/codereview |
I made a small shell implementation in C.
It reads stdin and executes the command. It can also take in a file name from argv and execute all the arguments in the file.
It supports redirection with > and you can also run multiple commands with & in between commands.
It has 3 built in commands which are cd, path and exit... | stackexchange/codereview |
I need to redo a migration occasionally. The workflow is usually something like this:
find or ls | grep the migration using some keyword
copy the timestamp
paste the timestamp in bundle exec rake db:migrate:redo VERSION=123
As I hate repetitive work, I wrote a small bash script that allows running a migration using o... | stackexchange/codereview |
I testing F# code which calculates "nearness" of two N-dimensional points using a least square euclidean distance algorithm. The class library is written in F# and the calling will be from VB.NET. The code will eventually be used for scientific binary data, however I wanted a simple real world test environment.
I ch... | stackexchange/codereview |
The goal here is to create a Top Level Menu that automatically pulls child pages without the need to manually add them to said menu. I didn't know any other way to accomplish this without a walker, of which I'm not very familiar with.
I was playing around with it and was able to get the submenus to work with this. The... | stackexchange/codereview |
I have this script that moves a box around the screen and the loops the second part of the movement. I have altered the code to drop another three boxes (4 in total) into the animation so the boxes follow each other around the screen.
I want it to work exactly like it does, but I'm sure there's a much better way of doi... | stackexchange/codereview |
I have written this function to create a URL:
function createUrl(urlPath) {
const endpoint = url.parse(env.config.get('myEndpoint'));
endpoint.pathname = path.posix.join(endpoint.pathname, urlPath);
return endpoint;
}
const basically creates a mutable object whose properties can still be modified.
Here, I... | stackexchange/codereview |
I was asked to write code to get the cheapest hotel to stay based on the input. There are three hotels with different weekend and weekday rates and rating. So when the input string is passed with the customer type and the dates, I had to return the cheapest hotel based on the rates and if there is a tie return hotel wi... | stackexchange/codereview |
This is Exercise 1-21 of K&R (2nd edition).
I've seen someone else's post about it but it doesn't solve the problem the way my code does, and I wasn't sure whether I was allowed to post my code as an answer and ask for feedback (it just seemed better to create a new thread and ask for advice here, didn't wanna pollute... | stackexchange/codereview |
Still pursuing the white rabbit, I had an IPresenter interface implementation featuring this method:
Private Sub ExecuteAddCommand()
Dim orderNumber As String
If Not RequestUserInput(prompt:=GetResourceString("PromptExcludedOrderNumberMessageText"), _
title:=GetResourceString("AddPr... | stackexchange/codereview |
I want to write a Python script where the input is a genotype (e.g. "CCDd") based upon the following Punnett square. The output should be the phenotype (e.g. "seal").
My code works, but doesn't look that 'pythonic' at all.
def colour(input):
if len(set(input)) == 2 and input[0] != 'C' and input[2] != 'D':
... | stackexchange/codereview |
This is a fictional email sending program for a e-store I've done for practice purposes. EmailSenderProgram is a program sending emails to customers. Currently it sends two types of email: "welcome" and "please come back" email. It's supposed to run daily and write a debug log each day if it worked or not. Posted earli... | stackexchange/codereview |
I have a requirement to implement a generic UniqueIdentifier which can cover identifiers like OrderId, TrackingID, scannableId and other Ids. The ids, as they are now, are either Long or String.
Below is my implementation of the UniqueIdentifier class --
public class UniqueIdentifier {
String stringValue;
Long ... | stackexchange/codereview |
Implementing OAuthAuthentication with OWIN and Identity to secure Web API and let external application like Chrome Extension to access our self hosted API for getting and posting data through our server.
I know this is the basic implementation of OAuth. Could this still be improved in terms of security and best practic... | stackexchange/codereview |
These two classes are part of a larger program that I am developing. The user is supposed to interact with the program using handheld red, blue, green or yellow discs and moving them in front of a webcam. The program tracks the movement and color of these discs and draws small circles of the corresponding color in a ce... | stackexchange/codereview |
I wanted to solve a problem where I sort an array of any size and return the minimum number of swaps.
The explanation for the distance 2 is that I choose 3 neighboring elements ABC and then swap them to CBA.
My code partially works as long as the array isn't too big, but pretty inefficient in my opinion.
Anyone have a ... | stackexchange/codereview |
I have got it working in a way so that there is one superclass, MathObject. In this implementation there is only a Constant subclass. I was forced to implement an abstract MathObject add(MathObject that) and an abstract MathObject add(Constant that) for reasons.
I would like to get that abstract MathObject add(Constant... | stackexchange/codereview |
I am looking for feedback to perfect my code developed for WPF in terms of speed, stability and resiliency. My code is supposed to handle synchronous status polling as well as asynchronous Commands to numerous TCP servers (more than 20). I am using a BlockingCollection to funnel these Polls & Commands and using the APM... | stackexchange/codereview |
I'm a complete newbie to Elixir, but I managed to bang together this working example of Ascii85 for a project I'm working on in my spare time.
I find some awkward repetition in here which I have tried to replace with iteration but it just made the code harder to read. There is also some lop-sided behaviour which I'm no... | stackexchange/codereview |
I have watched Professor Sheep's Leetcode 140: Word Break II
YouTube video here
CPP code here
My own Python translation code is below. I am thinking that the code can be optimized by traversing from right to left in this case as the code only start working with the last word. I have submitted both implementation to lee... | stackexchange/codereview |
I'm working on a web application using Bottle, and it is, at this point, functional.
The gist of it is that I have a database of drinks, with associated IDs, and associated sets of ingredients. the name and ID of the drink are passed to the client, which displays them.
Currently, when the program loads up, all drinks ... | stackexchange/codereview |
I need to extract some data from the environment variables using Go. This data can be string, boolean or integer, so I ended up writing three functions.
package main
import (
"fmt"
"os"
"strconv"
)
func getStrEnv(key string) string {
val := os.Getenv(key)
if val == "" {
panic(fmt.Sprintf("s... | stackexchange/codereview |
I have to:
1) Apply the Observer-Observable pattern to the original code.
2) starting from the original code, I have to suppose that the modification of the array fields (slot machine numbers) should be done in parallel by 3 NumberGenerator threads instead of just one.
My output seems to work fine but I'm wondering if ... | stackexchange/codereview |
In my nested for loops below, it is sometimes necessary to exit the outer loop and then continue program execution. Since loop labels and other goto-like constructions are heavily discouraged, I'm a bit afraid of raptors. Is this usage OK? Is there a better way to structure the program?
my @objects = load_objects();
OU... | stackexchange/codereview |
I am trying out different data structures to learn more about smart pointers. I have created a queue implementation which has push, pop, front, back and size functions.
#include <iostream>
#include <memory>
#include <cstddef>
template<typename T>
class Queue
{
std::unique_ptr<T[]> q_ptr;
int front_idx = -1;
... | stackexchange/codereview |
I have a use case which says:
Your REST service will consume a JSON object that contains a list of
emails for subscribers at the start of the subscription period, and a
list of subscribers at the end of the subscription period. Your
service must return a list of subscribers who are new, subscribers who
stayed,... | stackexchange/codereview |
I'm emulating a little bit the .on() from jQuery in an old Mootools version. One of the project requirements is that Mootools can't (shouldn't) be upgraded (using version 1.2.x).
Basically I'm checking the element itself and its two closest ancestors (like .parents() in jQuery).
My working code is:
Element.implement({
... | stackexchange/codereview |
I made the looks of asteroids using pygame. I still need to implement collisions but since it is running incredibly slow with 'amount' anything above 10. Please rip my code to shreds and explain why it is bad so that I can improve. :)
import pygame
import pygame.locals
import numpy
import random
asteroids = []
paused ... | stackexchange/codereview |
static const unsigned char from_base64[] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 2... | stackexchange/codereview |
For a while now I have been working to construct a program to calculate a lot of mathematical constants. Before I explain, here's the code:
Code
#include <boost/math/constants/constants.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/math/special_functions.hpp>
#include <complex>
#include <iostre... | stackexchange/codereview |
I'm a novice to programming completely. I'm trying to teach myself C++. I want to write code to create two vectors and read their elements from input.
vector<int> v1, v2;
/*Reading vector values*/
cout << "Enter the elements of 1st vector" << endl;
int ele;
while (cin >> ele)
v1.push_back(ele);
cout << "enter the e... | stackexchange/codereview |
The goal of this module is to take in a string (user input, someone copy and pasting a large list of proxies) and parse it into an array of objects.
I appreciate any and all feedback, but I'm specifically interested in improving the stringToProxy function.
Namely I'm unsure about mutating the string parameter, seems li... | stackexchange/codereview |
I've written a generic data adapter that can make use of a cache, for use in a data access layer. It presents an interface allowing CRUD operations, as well as retrieving all objects of a certain type.
IEntity.cs:
using System;
namespace GenericDataAdapter
{
public interface IEntity
{
Guid Id { get; se... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.