instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
In my project, I have three different userforms to display, optimized for three different aspect ratios. I need my code to call the screen resolution of the user's monitor, then check to see which category it belongs to, and finally choose the appropriate userform.
I've gotten as far as categorizing, but I'm self-taugh... | stackexchange/codereview |
In order to save memory space. Strings inside an embedded device are stored in a particular way. Each 32-bit location holds up to 4 chars instead of only 1 char in the usual case.
I wrote a function that convert an encoded string back to its original string. I am new to Python, so I would like to know whether or not I ... | stackexchange/codereview |
I am new to Jquery plugins, I was searching a lot about widgets and plugins, however I am still not sure if this code is okay. Should I use widgets for stateful plugins? Or is this plugin correct? Does this code have any downsides? I was trying to make a container here, where you can add/remove elements.
(function($... | stackexchange/codereview |
I want to get a result from the website when I submit a form. There are several things that can go wrong.
In a simple scenario I want to return:
true - when form was submitted
false - when form wasn't submitted
null - when we don't know if form was submitted or not
I did that ugly try, because of NullReferenceExcept... | stackexchange/codereview |
I am new at python and trying to solve the longest collatz series question. So I want to find out between 5 and 8, which number produce the longest collatz series and listed the series.
Here is my code, but now it is showing all series:
def collatz(n):
collatzseq = 0
while n != 1:
print(n)
... | stackexchange/codereview |
Context: My question comes from needing to iterate different np.arange arrays. The main motivation is to calculate all the possible combinations between the arrays, let's say a, b, c, x, y, z where the last 3 (x, y, z) can be arrays OR floats.
The reason behind is that every combination can be evaluated then in equatio... | stackexchange/codereview |
Lately I have been researching how to best unit test an EF repository and given a properly tested repository, what to test in the controller.
My research did not reveal many sound examples or explanations but I did what I could. Now I am kindly asking that you review my tests in order to verify their correctness.
Examp... | stackexchange/codereview |
I wrote a solution for a jug problem (given two jugs of water of different sizes find the steps needed to get specific amount of water in one of the jugs). I'm hoping for some input on my code. How can I make it better? More readable?
Optional - Is there a faster or more efficient solution I should look into?
#!/usr/bi... | stackexchange/codereview |
I'm writing a little library for some undocumented file formats. The original program uses a path string to find files in an archive and this function tries to do the same.
The archive contains a magic string, an offset into the file list, the data in the files and the file list itself. A entry in the filelist consists... | stackexchange/codereview |
Please critique my code. (Specifically, I'm not sure if my use of member variables is appropriate.)
Here is the main structure of my BST class:
public class bst {
private Node root;
public class Node {
int data;
Node left, right;
private Node(int data) {
this.data = data;... | stackexchange/codereview |
I implemented ArrayList functionality in C as follows:
#include <stdlib.h>
#include <assert.h>
#include "ArrayList.h"
struct _arraylist {
size_t size;
void ** data;
};
struct _arraylist *arraylist_create() {
/* Allocate Memory */
struct _arraylist *list = malloc(sizeof(struct _arraylist));
assert(... | stackexchange/codereview |
I am pretty new to Python and just wanted to make sure I am going in the right direction with my coding style.
After reading this, I'm not so sure.
The following is a convenience class that has operations used a lot in my main code.
import requests
try: import simplejson as json
except ImportError: import json
"""
Ba... | stackexchange/codereview |
I have an input group:
<div class="input-group">
<div class="input-group-addon">
@Html.DisplayNameFor(m => m.StorageId)
</div>
@if(ViewData.ModelState["StorageError"] !=null && ViewData.ModelState["StorageError"].Errors.Count>0)
{
<div class="a" title="@ViewData.ModelState["StorageError"... | stackexchange/codereview |
I'd appreciate if someone could cast an eye over my dodgey coding and give me some feedback.
The use / purpose of the sheet/script is to quality grade calls, emails and chats with customers. A form is filled out and then the script takes over.
We feed in a persons name, it grabs the last 9 forms for them.
It sorts the... | stackexchange/codereview |
For fragments I have this code to create a new instance:
public static FoodDetails newInstance(Food food) {
FoodDetails foodDetails = new FoodDetails();
Bundle args = new Bundle();
args.putParcelable(FoodConstants.BundleConstants.FOOD_OBJECT, food);
foodDetails .setArguments(args);
return foodDetail... | stackexchange/codereview |
Problem Statement:
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some... | stackexchange/codereview |
I want to write my C# code in a way which makes effects (state, I/O, etc) explicit in the type signature. I have started to understand monads, and have some acquaintance with algebraic effects, though not deeply so. I have attempted to implement a monad for working with algebraic effects in C#. The purpose is to allow ... | stackexchange/codereview |
The aim of this script is to snapshot the current working directory of a git repository to another branch. Afterwards, it switches back to the original branch and restores the original state, including the working directory and staged changes.
#!/bin/sh
function git_snapshot() {
# Usage: SNAPSHOT=$(git_snapshot <bac... | stackexchange/codereview |
I started implementing algorithms to learn them in order to get better at programming. Here is a merge sort one and criticisms / optimizations are welcome.
import unittest
import random
def mergeSort(list):
"""Sorts a mutable list.
Args:
list: An unordered list
Returns:
The sorted list.
"... | stackexchange/codereview |
The final product is the following pokédex page, here for Bulbasaur:
the blurry sprite is just a placeholder
the perspective effect disappears when the mouse hovers over the text
Any place where I pass pokemon.type1 or type directly in the className field gets the corresponding rule from global.css. The content is t... | stackexchange/codereview |
Any sequence of characters starting with a non-whitespace character and ending with any of the following is considered to be a sentence by this program :-
a full stop '.' followed by whitespace
an exclamation mark '!' followed by whitespace
a question mark '?' followed by whitespace
end-of-file
Also, any sequence of ... | stackexchange/codereview |
I just finish coding this code which use for control robot using compass sensor with PID control to control motors. Trying to make javascript object for necessary job.
Please guide me for a better code.
Watch Video to get how it works
I use johnny-five package for control Arduino and pid-controller for PID control.
var... | stackexchange/codereview |
I am still learning PowerShell and I would like your opinion on my log writing function. It creates a log entry with timestamp and message passed thru a parameter Message or thru pipeline, and saves the log entry to log file, to report log file, and writes the same entry to console. In Configuration.cfg file paths to r... | stackexchange/codereview |
I'm fairly new to Java and was trying to make a program that's generates the primes from 2 - 100. I originally had a design of my own making but it was fairly inefficient so I did some research and come across the Sieve of Eratosthenes, which is supposedly the the efficient way to find primes from 2 - n.
public class S... | stackexchange/codereview |
I have always suffered with too many conditionals in some of my methods. The following is a pseudocode/skeleton of one of my method like that:
private List<ReturnType> DoSth(string name = null)
{
List<ReturnType> names = new List<ReturnType>();
for (int i = 0; i < somearray.Length; i++)
{
if (somec... | stackexchange/codereview |
I am trying to create logger wrapper which will be used by calling application installed on IBM WAS. Since I am using java util logger, I will have to add handlers for each logger programmatically.
Please share your views. I am more concerned about the way I am using file handlers and closing them.
Here is Transaction... | stackexchange/codereview |
Another graph algorithm, this time to create a priority or build order. Provided with a starting List<Project> and List<ProjectWithPrerequisite> the algorithm will return the order to build them in. For a list of projects a, b, c, d, e, f and their corresponding prerequisites where a, d means that a is a prerequisite f... | stackexchange/codereview |
I am looking to make the following code more efficient since it it rather lengthy. However I need to include in the code constructor classes that include accessor methods for the container number, height, radius 1, radius 2, and a method that computes the liquid that the container can hold. So I am looking to leave the... | stackexchange/codereview |
I have a piece of code where I have string pairs (eg. 'a' and 'AA'), where both have their own unique ids. Id for first object is configured by user and second id is received at some point during runtime.
Example code:
http://repl.it/BE5N
Is there smarter way to load/save second ids from/to a file?
It feels somewhat un... | stackexchange/codereview |
I'm wrapping ui-select in my own directives to pre-configure and style it, as I need it for my app in different select widgets. They appear on many pages, for example accountSelect, countrySelect, contactSelect and so on.
What I really dislike is, that I'm mostly copy-and-pasting the directive's code and then just chan... | stackexchange/codereview |
I have a grid and a class Vehicle, which will have starting point(X, Y on the grid) and direction(one of N,E,S,W) taken from user and there will be commands, L & R turns the vehicle 90 degrees around left and right respectively and M moves the vehicle one unit to faced direction.
For instance, if the command is M and... | stackexchange/codereview |
I was looking into SOA to better utilize SIMD instructions. I implemented a generic wrapper object that lets you chose the amount of individual vectors each structure consists of. I am using xsimd and boost libraries if you're interested in testing it out.
Next step would be to make initializing the buffer easier, like... | stackexchange/codereview |
I have written a short function as part of my program that strips the quotation marks (") from a list of lists. An example of the input data is:
[['"foo"', '"Spam"', '123', '"Angry Badger"'],
['"dead"', '"Parrot"', '321', '987']]
The target result would be:
[['foo', 'Spam', '123', 'Angry Badger'],
['dead', 'Parrot',... | stackexchange/codereview |
I needed a quick caching mechanism to save a bitmap (picture). There was no way I could get the bitmap to the class where I need to upload it to the server so for the sake of organization and code cleanliness I created this. I have never seen this before implemented this way but to me this not only fits the purpose but... | stackexchange/codereview |
When building a sh_binary with dependencies using Bazel, a tree of Runfiles containing the dependencies is generated:
my_executable
my_executable.sh
my_executable.runfiles/
__main__/
a_dependency/
lib_dependency.sh
When deploying such a binary to a typical Unix filesystem, one would install the... | stackexchange/codereview |
Project Euler 7: What is the 10 001st prime number?
I currently have this code:
let primesfound = 0;
for(i=0;i<Number.MAX_SAFE_INTEGER;i++){
if(isPrime(i)){
primesfound++
}
if(primesfound==10001){
console.log(i)
break;
} else{
console.log(i + `and ${primesfound} found`) //testing line
}
}
but... | stackexchange/codereview |
I have written the following Query to retrieve some object's ID. If there are objects in the list that have a larger numbinbatch than the saveditems number in the batch, then it should take that. If not, then it should take the first number from the lower number in batches.
I am wondering if this could be shortened. I'... | stackexchange/codereview |
I made a script that scans a folder of 723 documents (pdf, pptx, docx) to extract the 'Name', 'Type', 'NbPages', 'Creation Date', 'Period Date', 'Countries', 'Summary', 'Indicateurs', 'Path'. I think I am not doing it right as I do several loops and each run through the text to extract their respective information. As ... | stackexchange/codereview |
For my programming class, we have been tasked with creating a Sudoku solver; the first step of the project was to create a program which would display the game board based on input provided by the user.
import math #To be used later
def board_filler():
"""Creates the sudoku board from user input"""
board = [... | stackexchange/codereview |
Two strings are said to be anagrams of each other if the letters of
one string may be rearranged to make the other string. For example,
the words 'elvis' and 'lives' are anagrams.
In this problem you’ll be given two strings. Your job is to find if
the two strings are anagrams of each other or not. If they are no... | stackexchange/codereview |
I've created a simple User Login page. Here User is authenticated [username, password] and if it is a valid user, values like username, name and role of the user is stored in the Session.
And according to the role of the user, the user is redirected to different pages. This is simple code, but please help me to make my... | stackexchange/codereview |
This Python module contains helper functions to download the result page of SEDE queries and extract columns from it, most prominently:
fetch_sede_soup(label, url): download the page of SEDE results, cache it or else use previously cached content, and return as a BeautifulSoup instance
fetch_table(label, url): fetch a... | stackexchange/codereview |
I'm using Spring boot - 2.3.3.RELEASE and gradle.
Note- I'm using Factory and Strategy pattern. This project is going to be used as a Library for other projects to import and use the methods exposed by Service layer.
Here is the folder structure: https://i.stack.imgur.com/aQSJf.jpg
I would appreciate if the community c... | stackexchange/codereview |
I've posted this to Stack Overflow, but someone voted to close as they felt it was opinion based, so I'm bringing it over to Code Review.
I have some Linq fluent chains to shape an original IEnumerable of objects into the proper form.
During this process, I'd like to capture and log the reason why some objects are "rej... | stackexchange/codereview |
I just care if it's any of the common formats so that later when I list all files, for those that are images, I can generate previews based on mime type.
So PHP.NET suggest to use exif_imagetype function to check if file is an image. In case of success an integer will be returned indicating one of 18 constants.
The che... | stackexchange/codereview |
This was one of my assignments in which I had to create a backup script that will individually compress all files (of an arbitrary number) of file-types (indicated by their .extension).
Example: backup a b c will take all files ending in .a, .b and .c and compress them using tar, keeping the original file, and naming t... | stackexchange/codereview |
Anybody mind providing an opinion on whether or not this is a good or bad example of Task Cancellation and why. I have my own opinion and I've been told that its baseless, just trying to find out who is off base. I don't think its me, but I am okay with it being me. I just need to know its me so I can evolve if require... | stackexchange/codereview |
I have previeous;y posted my php code with way to many nested blocks I hope I fixed it right.
I'd also like some tips on my OOP, as this is new to me.
class event {
//Builds the event in html
public function renderEvent($Array) {
echo "</p>";
echo "<p>";
if ($Array['ad']) {
e... | stackexchange/codereview |
I wrote this script to help me keep track of who has worked together and for what project or discussion in my classes.
I make a Google Sheet with the names of the students going across the first row and down the first column. Each student gets a number corresponding to their location in the spreadsheet. The value is th... | stackexchange/codereview |
I'm not very familiar with webpack, and I was very afraid that what I implemented for cache busting would break something. What I have seems to work. When I open up the built folder, under pub, I see 3 files:
main.someHashHere.js
index.html
manifest.someOtherHashHere.js
Previously, before I implemented cache-busting,... | stackexchange/codereview |
One of the URL in my application is vulnerable to XSS attack, so I am handling it in the below way.
I created a util class:
import java.util.regex.Pattern;
public class HtmlUtils {
public final static String tagStart = "\\<\\w+((\\s+\\w+(\\s*\\=\\s*(?:\".*?\"|'.*?'|[^'\"\\>\\s]+))?)+\\s*|\\s*)\\>";
public fin... | stackexchange/codereview |
I tried creating a function to check for a match between two email fields, let's say EMAIL and CONFIRM email. I absolutely try to avoid jQuery validate. It is not worth it for a single field. For the rest I use HTML5 properties like required, pattern, etc. and it works well. This is why I want to deliver seamless exper... | stackexchange/codereview |
I have several controls that are bound from database tables. Putting my OOP thinking cap on I figured since all of the controls will have a SqlCommand name and an associated SqlDataReader object I decided to make the following interface to program to.
public interface IBoundControl
{
string GetCommandName... | stackexchange/codereview |
I'm an amateur at assembly, but am trying to get better at it. For fun, I decided to write code that takes in a char array and increments the number represented in binary.
Here are a few input-output examples:
inc("10001010") = "10001011"
inc("0") = "1"
inc("1") = "10"
inc("100") = "101"
Code:
section .bss
result:... | stackexchange/codereview |
This is what I implemented in Rust to get the maximum number of consecutive 1s in list of binary numbers.
impl Solution {
pub fn print_values(nums: Vec<i32>) -> i32{
let mut result = 0;
let mut count = 0;
// let mut end = 0;
// NotE: Change the if so that it check
// if 0 el... | stackexchange/codereview |
Question: was using get_dummies a good choice for converting categorical strings?
I used get_dummies to convert categorical variables into dummy / indicator variables for a cold start recommender system. It's only using category type information and some basic limited choices.
The code works and the output seems good. ... | stackexchange/codereview |
I have written a tic-tac-toe game in Haskell and was wondering if anyone could provide any hints on how it could be improved
import Data.Bits
import System.IO
import Data.List
type Board = (Int, Int) -- the first Int is X's board, the second Int is O's board
data Player = X | O deriving (Eq, Show)
emptyBoard :: Board... | stackexchange/codereview |
I want to change all the pixels in an image to have the same value, in terms of the HSV colour space.
At the moment I'm running the following code:
private Bitmap changeVForAllPixels(Bitmap bitmap, float newV)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] rgbs = new int[width * he... | stackexchange/codereview |
Still oiling my Forth. Below are few essential algorithms for in-place merge. Please review.
Some introductory comments:
>swap< is not a cute smiley. I am trying to tell that two pointers are going towards each other at each swap.
rdrop drop looks hideously ugly. Any suggestions?
lower-bound and upper-bound must be un... | stackexchange/codereview |
I am making a plugin for Firefox, this is (more or less) my first time working with JavaScript. Is this a reasonable design for working with both values and lists in a database?
function set(key, value) {
// Sets a key-value pair in the browser's local storage
browser.storage.local.set({ [key]: value });
}
fun... | stackexchange/codereview |
Situation
So I have made a list of PictureBoxes on my form that looks as follows:
All images have a panel behind them that is 4px lager (2xp all around the picture box). The images are named x1, x2, xn.. respectively. The panels behind the images are named y1, y2, yn.. respectively.
I want this to happen smoothly when... | stackexchange/codereview |
Please take a look at the following code. This is my attempt at understanding concurrent applications.
class Program
{
static void Main(string[] args)
{
var consumers = new List<Consumer>
{
new Consumer(1000),
new Consumer(900),
new Consumer(800),
... | stackexchange/codereview |
I've written a simple script to refresh the page when the page has been updated.
How it works:
The Javascript polls a PHP script and sends it the current URL and the current version, the PHP script then queries MySQL which returns the true version of the page.
Here is the PHP
if (isset($_GET['URL']) && isset($_GET['Cur... | stackexchange/codereview |
There have been a few questions over on SO recently about securely storing credentials in Powershell scripts. Because ConvertFrom-SecureString uses DPAPI it makes the output only valid for that user, which makes creating credentials for service accounts etc. occasionally awkward.
I have had this script lying around for... | stackexchange/codereview |
I wrote a program that will take a number from 0 to 999,999,999,999 and spell out that number in English.
How could I improve the readability of my code?
class Say
UNITS ={
1=> "one",
2=> "two",
3=> "three",
4=> "four",
5=> "five",
6=> "six",
7=> "seven",
8=> "eight",
9=> "nine"
... | stackexchange/codereview |
I use at to schedule jobs and atq to display the scheduled jobs. But it mildly irritates me in that I have to look up each job individually. I wrote a Python script to display the scheduled job under the scheduled time.
(In my world all the commands will begin 'task')
So instead of
stafflinux$atq
8 Mon Aug 18 09:... | stackexchange/codereview |
I haven't used Unix, etc. for 40 years, so I am a bit rusty. I need to back up the databases on my website(s) once a week and then retrieve them automatically from my development machine. So this is step one and is working fine as a crontab job on Apache. It emails me a message with status/error.
I am creating a fo... | stackexchange/codereview |
Hello today after few weeks of learning I tried some form validation.
I am wondering how I could improve my code and what things I missed.
Here is a preview hosted on github + repository.
And here is my code :
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="mai... | stackexchange/codereview |
Is this best practice way to send messages to the user?
Update: This has been changed to a simple function call.
/**
*Message - Sends message to the .innerHTML of an element
*/
var Message = ( function ()
{
var messages =
{
name: 'Please enter a valid name',
email: 'Please e... | stackexchange/codereview |
Based on the sample variants, I need to get all combinations of all variants. In the example I have 3x3x2=18 variants.
## SAMPLE VARIANTS
sizes = ['small', 'medium', 'large']
colors = ['red', 'green', 'blue']
materials = ['cotton', 'linen']
## ITERATE TO ALL VARIANTS
titles = []
sizes.each do |size|
colors.each do |... | stackexchange/codereview |
I've prepared a simple login form, using prepared statements to prevent SQL injections. How secure is this ?
<head>
<title>Login</title>
<?php
session_start();
// set up a token
$form_token = md5(uniqid('auth', true));
// session form token
$_SESSION['form_toke... | stackexchange/codereview |
I have been trying to improve python combined with Postgres.
At this moment im only sending two values to database which are etc:
link = "https://www.mathem.se/varor/vegetarisk-fars/vegofars-fairtrade-1000g-anamma"
store = "mathem"
and I do have few options that I want to be able to do with Postgres and that is to fe... | stackexchange/codereview |
I love the "projections" introduced by the ranges library, and I would like to use them in algorithms that haven't been rangeyfied yet.
I had the idea of using them through a function like this:
#include <utility>
#include <functional>
template<typename TFn, typename TProj = std::identity>
auto
constexpr proj(TFn &&Fn... | stackexchange/codereview |
I've implemented selection sort, heap sort, insertion sort, and iterative quicksort using C++11. Am I using the correct STL data structures/algorithms? Am I using move semantics correctly in my code?
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <iterator>
#include <utility>
#in... | stackexchange/codereview |
I've been assigned a tast to implement an SMTP client-server protocol providing limited functionality and the Solution for this is to execute a typical execution simiilar to this transcription:
S: 220 [ip]
C: HELLO [email]
S: 250 Hello [email], pleased to meet you
C: MAIL FROM: <email1@email.com>
S: 250 ok
C: RCPT TO: ... | stackexchange/codereview |
This code does the following:
Read CSV file and determine sub_type based on series_desc.
Turn row into dictionaries new_person and new_subscriptions.
Check list people for the new_person and add the person if it is actually new.
Check each person in the list people for the new_subscription and add it if it is not ther... | stackexchange/codereview |
I have created a game called 'runes' in C. It is similar to Chess, but has a bigger board and different pieces. I would like to know how I can improve the code, for example, by adding proper error checking and by fixing any bugs. (This is probably not called 'broken code' because the main functions work fine.) Also, th... | stackexchange/codereview |
I was just writing code, and wanted to make a piece that removes everything after the character ? if it's found within the URL.
if (strstr($url, "?")) {
$url = strstr($url, "?", true);
}
Can I make this any shorter? It doesn't feel right to type the "same thing" twice with strstr.
| stackexchange/codereview |
"Regular Expression Matching" is a hard problem on LeetCode (problem #10):
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input... | stackexchange/codereview |
The start of a simple Scrabble solver.
What I have so far:
Add a word to the trie
Return a sorted list with the all possible combinations, based on the letters input
Some basic tests
Edit
Since it hasn't received any answer yet...
Added a joker letter, for getting the best possible words
Please critique any and al... | stackexchange/codereview |
I am trying to learn clear and concise C++. Currently I'm learning classes in school, and to practice I have made a Fraction class.
I'd appreciate any help regarding style, cleanliness or anything else that would be good to know.
(I know using namespace std; is frowned upon, but it's required in our course.)
#include <... | stackexchange/codereview |
This was my original posting: Check that a data file contains the expected number of rows and columns of integers
I updated the code. Still what could I improve on?
Another question I have is how come my last method fileContent() does not need any throws declaration in the method header?
import java.io.File;
import ja... | stackexchange/codereview |
I have the following piece of code:
for (var i = 0, len = legend.allItems.length; i < len; i++) {
(function (i) {
var item = legend.allItems[i].legendItem;
item.on('mouseover', function (e) {
var posLeft = 0,
posTop = 0,
parentWidth = chart.chartWidth;
... | stackexchange/codereview |
Over the past 2 days I've developed a simple library application, but I'm not sure about relations between classes I designed and where I can use composition,add interface or design pattern. I would like to get your feedback on the design.
package com.library.main;
import com.library.models.BookDirectory;
import com.l... | stackexchange/codereview |
I'm fetching some data by using bs4, and want to know why access speed gets slower as my program progresses.
I'm using thread, and I know threading isn't so fast because of GIL.
My problem is that my program gets slower gradually.
When the number of word is over 300,it become much slower than that of word is about 100 ... | stackexchange/codereview |
When sanitizing the $_POST passed from the controller to the model, I need to sanitize the input and there are 2 options that I can think of.
For the first one, I can nest the if blocks like this:
if(!empty($username))
{
if(!empty($password))
{
//login the user
}
... | stackexchange/codereview |
Oftentimes I find myself using context inside threads, multiple times. The problem is that I do not want to hold a long-lived strong reference of it in my threads to avoid leaking it. I keep a weakReference to it in global space and when my activity dies, it will obviously not prevent any GC events or such.
I have made... | stackexchange/codereview |
I am doing old versions of the Canadian Computing Competition, on a website where I can run my solution against some test cases they have. I am failing one of their test cases, and cannot figure out why. I have no access to the test case.
I have posted below the full problem description as well as my attempted solution... | stackexchange/codereview |
I have some very illogical jQuery code and I want to see if someone finds a better way to do the exact same thing:
jQuery:
$(".col-md-3 img").hover(function() {
$(this).parent().children(".search").show();
$(this).parent().children(".photo").css("opacity","0.4");
}, function(){
$(this).parent().children(".sear... | stackexchange/codereview |
Below is an example of a simple converter. In the first example temperature I have used a function within a function. In the second example milli I have used a more direct approach. Which would you consider is the better method to handling calculations in functions and why? Also feedback on my approach and examples of ... | stackexchange/codereview |
I want to have a object where I can reference another object's properties dynamically while they are still considered properties. If I try to do a simple setattr I'll only get the current state when I read it and it won't act like I'm getting the property.
I can't setattr with property(<target_obj>.__class__.<property>... | stackexchange/codereview |
The problem I am trying to solve is this. Apples fall at various offsets relative to an apple tree at position a, and oranges fall at various given offsets relative to an orange tree at position b. How many of each kind of fruit lie between positions s and t?
I pass 8 from the 11 test cases, I fail 3 tests due to tim... | stackexchange/codereview |
I'm pretty new to C# and was just wondering if there is a better way I can write this calculator that I made:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnthonyCalculator
{
... | stackexchange/codereview |
I am porting the C-style socket to design a simple wrapper around the telnet client in CPP. The telnet protocol is accomplished by using libtelnet in C. The C-style code for this wrapper is reviewed here and here as well.
I want to follow standard practices in my CPP code, such as using smart pointers in CPP instead of... | stackexchange/codereview |
Just a slug generator. I'm wondering if this can be simplified any further.
Many thanks.
<?php
function slug($string) {
// Replace all non letters, numbers, spaces or hypens
$string = preg_replace('/[^\-\sa-zA-Z0-9]+/', '', mb_strtolower($string));
// Replace spaces and duplicate hyphens with a single hyp... | stackexchange/codereview |
public static long sumOfPrimes(long max){
long sum = 0;
long primes[] = new long[((int)max/2)+1];
int index = 0;
for(long counter = 2; counter <= max; counter++){
if(isPrime(counter, primes)){
sum += counter;
primes[index++] = counter;
}
}
return sum;
}
p... | stackexchange/codereview |
For a game implementation, I have a very large overview map with multiple layers (namely base-map / units / highlight & info / fov-shading) of which the first is CPU-intensive to generate. I have implemented a caching mechanism in which the base layer is drawn once and held in system memory, then drawn on demand by th... | stackexchange/codereview |
I implemented quicksort using iterators. I am will be grateful, if someone can review my piece of code. BTW, I am just selecting the last element as the pivot (which I plan to randomize later) I am mainly looking for the following:
1) Correctness of the Implementation
2) Correct usage of iterators
3) Basic coding styl... | stackexchange/codereview |
I developed three methods that have only some similarities, and the three must remain separate. However, it seems there is a significant amount of duplicate code. They basically seek the same list and set a BasicDBObject with a few different attributes.
How can I solve it? Or is acceptable as is? These stretches of dup... | stackexchange/codereview |
I'm basically trying to write a helper function that reads a whole file and returns the data and the number of bytes read.
Can you tell me if is correctly written and used?
#include <iostream>
static char * ReadAllBytes(const char * filename, int * read)
{
ifstream ifs(filename, ios::binary|ios::ate);
ifstream... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.