Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- codereview-0001/environment/Dockerfile +0 -5
- codereview-0001/instruction.md +0 -2
- codereview-0005/environment/Dockerfile +0 -5
- codereview-0005/instruction.md +0 -13
- codereview-0006/environment/Dockerfile +0 -5
- codereview-0006/instruction.md +0 -2
- codereview-0013/environment/Dockerfile +0 -5
- codereview-0013/instruction.md +0 -2
- codereview-0022/environment/Dockerfile +0 -5
- codereview-0022/instruction.md +0 -13
- codereview-0025/environment/Dockerfile +0 -5
- codereview-0025/instruction.md +0 -2
- codereview-0026/environment/Dockerfile +0 -5
- codereview-0026/instruction.md +0 -13
- codereview-0033/environment/Dockerfile +0 -5
- codereview-0033/instruction.md +0 -13
- codereview-0034/environment/Dockerfile +0 -5
- codereview-0034/instruction.md +0 -2
- codereview-0039/environment/Dockerfile +0 -5
- codereview-0039/instruction.md +0 -13
- codereview-0042/environment/Dockerfile +0 -5
- codereview-0042/instruction.md +0 -2
- codereview-0047/environment/Dockerfile +0 -5
- codereview-0047/instruction.md +0 -2
- codereview-0053/environment/Dockerfile +0 -5
- codereview-0053/instruction.md +0 -13
- codereview-0057/environment/Dockerfile +0 -5
- codereview-0057/instruction.md +0 -2
- codereview-0067/environment/Dockerfile +0 -5
- codereview-0067/instruction.md +0 -13
- codereview-0072/environment/Dockerfile +0 -5
- codereview-0072/instruction.md +0 -2
- codereview-0074/environment/Dockerfile +0 -5
- codereview-0074/instruction.md +0 -13
- codereview-0077/environment/Dockerfile +0 -5
- codereview-0077/instruction.md +0 -13
- codereview-0080/environment/Dockerfile +0 -5
- codereview-0080/instruction.md +0 -2
- codereview-0087/environment/Dockerfile +0 -5
- codereview-0087/instruction.md +0 -2
- codereview-0093/environment/Dockerfile +0 -5
- codereview-0093/instruction.md +0 -13
- codereview-0097/environment/Dockerfile +0 -5
- codereview-0097/instruction.md +0 -13
- codereview-0098/environment/Dockerfile +0 -5
- codereview-0098/instruction.md +0 -13
- codereview-0099/environment/Dockerfile +0 -5
- codereview-0099/instruction.md +0 -13
- codereview-0100/environment/Dockerfile +0 -5
- codereview-0100/instruction.md +0 -13
codereview-0001/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0001/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I'd like suggestions for optimizing this brute force solution to problem 1 . The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to isMultiple as possible: ''' If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. ''' end = 1000 def Solution01(): ''' Solved by brute force #OPTIMIZE ''' sum = 0 for i in range(3, end): if isMultiple(i): sum += i print(sum) def isMultiple(i): return (i % 3 == 0) or (i % 5 == 0)
|
|
|
|
|
|
|
|
|
codereview-0005/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0005/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
CodeIgniter Active Record Subqueries
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I use CodeIgniter at work, and one of our model files had a lot of subqueries in it. I originally had to manually write each subquery, and wondered if I could use active records instead. So, to make my life easier, I made a subquery library for CodeIgniter. I put it on the CodeIgniter Wiki , but I never really had any one look over it. So, can you tell me if there is anything I should improve in this, or anything I really shouldn't be doing? P.S. Feel free to use this if you wish. P.P.S. join_range is a helper method for use with the answer to this question . P.P.P.S. The latest version can be found here . class Subquery{ var $CI; var $db; var $statement; var $join_type; var $join_on; function __construct(){ $this->CI =& get_instance(); $this->db = array(); $this->statement = array(); $this->join_type = array(); $this->join_on = array(); } /** * start_subquery - Creates a new database object to be used for the subquery * * @param $statement - SQL statement to put subquery into (select, from, join, etc.) * @param $join_type - JOIN type (only for join statements) * @param $join_on - JOIN ON clause (only for join statements) * * @return A new database object to use for subqueries */ function start_subquery($statement, $join_type='', $join_on=1){ $db = $this->CI->load->database('', true); $this->db[] = $db; $this->statement[] = $statement; if(strtolower($statement) == 'join'){ $this->join_type[] = $join_type; $this->join_on[] = $join_on; } return $db; } /** * end_subquery - Closes the database object and writes the subquery * * @param $alias - Alias to use in query * * @return none */ function end_subquery($alias=''){ $db = array_pop($this->db); $sql = "({$db->_compile_select()})"; $alias = $alias!='' ? "AS $alias" : $alias; $statement = array_pop($this->statement); $database = (count($this->db) == 0) ? $this->CI->db: $this->db[count($this->db)-1]; if(strtolower($statement) == 'join'){ $join_type = array_pop($this->join_type); $join_on = array_pop($this->join_on); $database->$statement("$sql $alias", $join_on, $join_type); } else{ $database->$statement("$sql $alias"); } } /** * join_range - Helper function to CROSS JOIN a list of numbers * * @param $start - Range start * @param $end - Range end * @param $alias - Alias for number list * @param $table_name - JOINed tables need an alias(Optional) */ function join_range($start, $end, $alias, $table_name='q'){ $range = array(); foreach(range($start, $end) AS $r){ $range[] = "SELECT $r AS $alias"; } $range[0] = substr($range[0], 7); $range = implode(' UNION ALL ', $range); $sub = $this->start_subquery('join', 'inner'); $sub->select($range, false); $this->end_subquery($table_name); } } Example Usage This query: SELECT `word`, (SELECT `number` FROM (`numbers`) WHERE `numberID` = 2) AS number FROM (`words`) WHERE `wordID` = 3 would become: $this->db->select('word')->from('words')->where('wordID', 3); $sub = $this->subquery->start_subquery('select'); $sub->select('number')->from('numbers')->where('numberID', 2); $this->subquery->end_subquery('number');
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|php|mysql|codeigniter|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0006/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0006/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
So I've had a problem where I need to compare data in 2 different tables on two different servers. Now, I know MySQL supports CHECKSUM TABLES , but from my testing and understanding, it's not reliable across server instances and versions. So I created this query: $part = '@CRC := MD5(CONCAT_WS(\'#\', COALESCE(`'. implode('`, "#NULL#"), COALESCE(`', $this->_columns). '`, "#NULL#")))'; $sql1 = "SELECT COUNT(*) AS cnt, SUM(CONV(SUBSTRING({$part}, 1, 4), 16, 10)) as a1, SUM(CONV(SUBSTRING(@CRC, 5, 4), 16, 10)) as a2, SUM(CONV(SUBSTRING(@CRC, 9, 4), 16, 10)) as a3, SUM(CONV(SUBSTRING(@CRC, 13, 4), 16, 10)) as a4, SUM(CONV(SUBSTRING(@CRC, 17, 4), 16, 10)) as a5, SUM(CONV(SUBSTRING(@CRC, 21, 4), 16, 10)) as a6, SUM(CONV(SUBSTRING(@CRC, 25, 4), 16, 10)) as a7, SUM(CONV(SUBSTRING(@CRC, 29, 4), 16, 10)) as a8 FROM `dbname`.`tablename` WHERE `id` >= $min AND `id` So basically, it's concatenating each row together (all the columns of each row more specifically) and then MD5ing them. Then it walks 4 hexbits at a time through that MD5 and sums them across all rows (4 hexbits to allow me to do huge tables without needing to worry about overflowing). Then, I just compare the result of this query on both tables to see if everything is the same. By using this binary search, I am able to rather quickly narrow down where the changes are so that I can port them. It's actually reasonably efficient, so I'm not too concerned about that. What I am concerned about is if this is even necessary. It's screaming to me "You're doing it wrong", but I can't figure out any cleaner method around it... What are your thoughts?
|
|
|
|
|
|
|
|
|
codereview-0013/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0013/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order: ' from frmGuessGame.frm Private Sub Swap(ByRef Value1 As Variant, ByRef Value2 As Variant) Dim Temporary As Variant Temporary = Value1 Value1 = Value2 Value2 = Temporary End Sub Private Sub ShuffleList() Dim LoopCtr As Integer, SwapWith As Integer For LoopCtr = LBound(InnerPlaylist) To UBound(InnerPlaylist) SwapWith = (Rnd * (UBound(InnerPlaylist) - LBound(InnerPlaylist))) + LBound(InnerPlaylist) Swap InnerPlaylist(LoopCtr), InnerPlaylist(SwapWith) Next End Sub My initialization function does include the Randomize statement, so it should be a good, even shuffle. ' from mdiMain.frm Private Sub MDIForm_Load() 'initialize pseudo-random number generator Randomize frmMusiguess.Show frmSplash.Show End Sub I'm not sure, however, that this is the best way to do it. Am I on the right track?
|
|
|
|
|
|
|
|
|
codereview-0022/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0022/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Fetching tweets
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I have written this (truncated) code to fetch some tweets: dispatch_async(dispatch_get_global_queue(0, 0), ^{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; NSString *JSONStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://search.twitter.com/search.json?q=haak&lang=nl&rpp=100"] encoding:NSUTF8StringEncoding error:nil]; if (!JSONStr) { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; return; } /*... PARSING ETC ...*/ dispatch_sync(dispatch_get_main_queue(), ^{ [delegate didReceiveTweets:foundTweets]; }); [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; }); Note the lines from dispatch_sync(dispatch_get_main_queue(), ^{ to }); . This will update the UI. Is this the good way to do it, or are there better ways than using dispatch_sync within a dispatch_async ? Or should I not do this at all? Should I also send setNetworkActivityIndicatorVisible: from within the main thread? The reason I'm not using NSURLConnection is because this code comes from a class method, so I need to create an object containing the delegate for the NSURLConnection , which seems overkill to me.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|multithreading|objective-c|twitter|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0025/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0025/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
Inspired by this question , but hopefully not a duplicate. I understand that the Law of Demeter is very useful in case of services interacting with other services, for example it's much easier to mock the other services in unit tests. What about services interacting with data models, though? Let's say I have a hierarchy of immutable classes: public final class Document { private final List pages; // Constructor, getter, ... } public final class Page { private final List paragraphs; // Constructor, getter, ... } public final class Paragraph { private final List lines; // Constructor, getter, ... } Let's say I want to do something with certain lines in a document doc : public void doSomething(Document doc) { for (Page page : doc.getPages()) { for (Paragraph para : page.getParagraphs()) { for (Line line : para.getLines()) { if (someCondition(line)) { someAction(line); } } } } Now, as far as I understand, the above code doesn't obey the Law of Demeter. However, I don't want to force the law at all cost and clutter the model (here, the Document class) with tens of methods like: public List filterWrtSomeCondition(); public List filterWrtSomeOtherCondition(); Or maybe there's a third way? I suspect that the Law of Demeter applies primarily to services interacting with other services. Is it a valid interpretation?
|
|
|
|
|
|
|
|
|
codereview-0026/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0026/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Is this a sufficient way to prevent script injections and other bad stuff in strings
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
Would this function be sufficient enough to remove all malicious code and foreign characters from a string? //Clean the string $out = ltrim($do); $out = rtrim($out); $out = preg_replace('/[^(\x20-\x7F)]*/','', strip_tags($out)); This data is not going into a SQL database, so I dont have to worry about sql injection attempts. Is there any way to improve my code and make it more efficient? This function would clean any user inputted data (forms, and ?), and then save it do a database. This would be used in a global sanitizing function.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|php|strings|security|regex|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0033/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0033/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Instantiating objects with many attributes
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I have a class with quite a few attributes, most of which are known when I create an instance of the object. So I pass all the values in the constructor: $op = new OpenIdProvider($imgPath . $name . $ext, 'openid_highlight', 0, 0, 108, 68, 6, $info[0], $info[1], $name); I'm finding that having this many parameters makes it confusing both when writing and reading the code, as it's not easy to determine which attribute each value corresponds to. Also, this has a bit of a code smell to it - seems like there should be a better way. Any suggestions?
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|php|constructor|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0034/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0034/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I installed settingslogic and in the configuration file I put the regex for the email as follows: #config/settings.yml defaults: &defaults email_regex: /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i development: That I load in devise configuration in this way: #config/initializers/devise.rb # Regex to use to validate the email address # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i config.email_regexp = eval Settings.email_regex It works, but what do you think about that eval ? Is it the correct way to convert a string to a regex?
|
|
|
|
|
|
|
|
|
codereview-0039/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0039/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Update grid from source hierarchy
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
In this question I answered with this Linq. While it does what I was looking for, I am not sure how easy the linq queries are for others to follow. So I am looking for feedback on formating, what comments would be helpful and other alternative approaches to moving through the children records. private void UpdateGridFromSourceHierarchy(int depth, IEnumerable list) { //Get the initial set of sourcefiles var sourceFiles = list .SelectMany(current => current.getInvocations() .Select(invocation => new {current = (SourceFile) null, invocation})) .ToList() //This ensures that getInvocations is only called once for each sourcefile .GroupBy(x => x.current, x => x.invocation); for (var currentDepth = 0; currentDepth current.Select(invocation => invocation)) //Get all of the invocations paired with the new current level of source files .SelectMany(newCurrent => newCurrent.getInvocations() .Select(invocation => new { newCurrent, invocation })) //Group them so that we can loop through each set of invocations seperately .ToList().GroupBy(x => x.newCurrent, x => x.invocation); } }
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|c#|linq|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0042/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0042/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
Imagine that I need a color palette for my Winforms application to have a consistent look. What I did was create a static helper class and helper methods that I can call from anywhere in my code, and invoke what I need from the App.settings file. Here for example, I am getting the school name from the App.config file, so I can sell this application to other schools with minimal changes on my part. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; namespace Uboldi.Helpers { public static class CustomizationHelper { public static string GetSchoolName() { return ConfigurationManager.AppSettings["schoolName"]; } } } Usage: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Uboldi.Helpers; namespace Uboldi { public partial class MainForm : Form { public MainForm() { InitializeComponent(); LoadFormTitle(); } private void LoadFormTitle() { var schoolName = CustomizationHelper.GetSchoolName(); this.Text = String.Format("Sistema {0} - Pagina Principal", schoolName); } } } Are there any glaring mistakes I'm making by choosing this type of architecture?
|
|
|
|
|
|
|
|
|
codereview-0047/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0047/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I found that in PHP (or I probably can't find it) a proper is_numeric_array($array) function is missing. So I created one. The problem is that I don't think it's great and I don't know how to improve it. Any suggestion? My first function function is_numeric_array($array) { $i = 0; foreach ($array as $a => $b) { if (is_int($a)) { ++$i; } } if (count($array) === $i) { return true; } else { return false; } } is_numeric_array(array(0,0,0,0,0)); // true is_numeric_array(array('str' => 1, 'str2' => 2, 'str3' => 3)); // false Example As asked, I provide an example on how this could be any useful. function is_numeric_array($array) { # Code below } function someFunction($array) { if (is_numeric_array($array)) { $query = $array[0]; $param = $array[1]; $fetch = $array[2]; } else { $query = $array['query']; $param = $array['param']; $fetch = $array['fetch']; } # Do your sql/pdo stuff here } # This use is the same of ... someFunction(array( 'PDO SQL STATEMENT', array('param1' => 1, 'param2' => 2, 'param3' => 3), true )); # ... this one. someFunction(array( 'query' => 'PDO SQL STATEMENT', 'param' => array('param1' => 1, 'param2' => 2, 'param3' => 3), 'fetch' => true )); # To choose one form instead of the other is coder's decision # Also I know it is useless but I was just wondering why anybody actually looked forward this function
|
|
|
|
|
|
|
|
|
codereview-0053/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0053/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Thread-Safe and Lock-Free - Queue Implementation
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently. Would you please review it, and suggest any improvements/issues you find? ( Cross-post from StackOverflow ) import java.util.concurrent.atomic.AtomicReference; public class LockFreeQueue { private static class Node { final E value; volatile Node next; Node(E value) { this.value = value; } } private AtomicReference > head, tail; public LockFreeQueue() { // have both head and tail point to a dummy node Node dummyNode = new Node (null); head = new AtomicReference >(dummyNode); tail = new AtomicReference >(dummyNode); } /** * Puts an object at the end of the queue. */ public void putObject(T value) { Node newNode = new Node (value); Node prevTailNode = tail.getAndSet(newNode); prevTailNode.next = newNode; } /** * Gets an object from the beginning of the queue. The object is removed * from the queue. If there are no objects in the queue, returns null. */ public T getObject() { Node headNode, valueNode; // move head node to the next node using atomic semantics // as long as next node is not null do { headNode = head.get(); valueNode = headNode.next; // try until the whole loop executes pseudo-atomically // (i.e. unaffected by modifications done by other threads) } while (valueNode != null && !head.compareAndSet(headNode, valueNode)); T value = (valueNode != null ? valueNode.value : null); // release the value pointed to by head, keeping the head node dummy if (valueNode != null) valueNode.value = null; return value; } }
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|java|multithreading|thread-safety|locking|lock-free|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0057/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0057/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I'm trying to design a well defined yet simple interface for the unit of work and repository patterns. My UoW's are exposed to services and services then "get repositories" that it needs to query. I know returning IQueryable for repositories is a religious war. Because repositories are only exposed to the service, all queries are performed inside the service and therefore I can test the queries. Is there anything I should change for these interfaces? All criticisms are greatly appreciated! public interface IUnitOfWork : IDisposable { bool IsActive { get; } bool WasCommitted { get; } /// /// Commits all changes made on the unit of work. /// void Commit(); bool WasRolledBack { get; } /// /// Rolls back all changes made on the unit of work. /// void Rollback(); /// /// Returns an instance of an entity with the specified key that is attached to the unit of work without /// loading the entity from a repository. /// /// /// T Load (int id) where T : class; void Attach (T entity) where T : class, IIdentifiable; void Detach (T entity) where T : class; IRepository GetRepository () where T : class; } public interface IRepository where T : class { IUnitOfWork UnitOfWork { get; } void Add(T entity); void Remove(T entity); /// /// Returns an instance of an entity with the specified key that is attached to the unit of work by loading /// the entity from the repository. /// /// /// T Get(int id); IQueryable All(); }
|
|
|
|
|
|
|
|
|
codereview-0067/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0067/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Javascript Object Placement / String Parsing Method
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
This JS function is intended to retrieve or place a value into an object with the nested keys as a string. For example var obj = {a: {b: [4]}}; parse_obj_key(obj, "a.b.0") should equal 4. parse_obj_key(obj, "a.c", 2) should add another element to "a" named "c" with value 2. The method works, but I'd like to clean it up if possible (or a more polished implementation which is publicly available). I'd also love to know of any edge-case failures which can be found. function parse_obj_key(obj, loc, val){ var _o = obj; while (true){ var pos = loc.indexOf('.'); if (!_o || typeof _o != 'object'){ $.log("Invalid obj path: " + loc + "\n" + JSON.stringify(obj)); return null; } if (pos === -1){ if (val){ _o[loc] = val; return obj; } else { if (!isNaN(parseInt(loc))) loc = parseInt(loc); return _o[loc]; } } var part = loc.substring(0, pos); var loc = loc.substring(pos + 1); if (!isNaN(parseInt(part))) part = parseInt(part); if (!(part in _o)){ if (val) _o[part] = new object; else return null; } _o = _o[part]; } }
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|javascript|parsing|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0072/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0072/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
I'm new to Hibernate so I need some advice/direction on doing Transactions. I have a DAO like public class MyDao extends HibernateDaoSupport implements IMyDao { @Override public Foo getFoo(int id) { return (Foo)getHibernateTemplate().load(Foo.class, id); } } With this setup (using HibernateDaoSupport), will Hibernate/Spring handle transactions for me? Some of the examples I see say yes, others show using Transaction tx = getHibernateTemplate().getSessionFactory().getCurrentSession().beginTransaction(); to get a Transaction in every DAO method. Right now I'm assuming my minimal DAO is correct but I want to do a "larger" transaction that includes a couple of Hibernate calls in one method. Would I use the manual Transaction method there? Do I have to use it everywhere? Thanks.
|
|
|
|
|
|
|
|
|
codereview-0074/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0074/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
"Do you owe the government?" classes
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
Should my class pass parameters internally or reference class level scoped variables? I'm not sure on the best approach or style for procedure calls that have parameters. Should I go with the class level scoped variables? public class YouOweTheGovernment { public float AmountToPay { get; private set; } public float ArbitraryTaxRate { get; private set; } public float Salary { get; private set; } public YouOweTheGovernment(float taxRate, float salary) { this.ArbitraryTaxRate = taxRate; this.Salary = salary; CalculateAmount(); } private void CalculateAmount() { this.AmountToPay = (this.Salary * (this.ArbitraryTaxRate / 100)); } } Or explicitly pass parameters into a procedure? public class YouOweTheGovernment { public float AmountToPay { get; private set; } public float ArbitraryTaxRate { get; private set; } public float Salary { get; private set; } public YouOweTheGovernment(float taxRate, float salary) { this.ArbitraryTaxRate = taxRate; this.Salary = salary; CalculateAmount(this.Salary, this.ArbitraryTaxRate); } private void CalculateAmount(float salary, float taxRate) { this.AmountToPay = (salary * (taxRate / 100)); } } In my contrived example I think the first is clearer, but as a class grows in size and complexity it would make it harder to track what is coming from where.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|c#|comparative-review|classes|finance|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0077/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0077/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Simple Tic-Tac-Toe PHP/Pure HTML
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I've been doing a simple Tic-Tac-Toe with PHP, generating only HTML code. A few notes: I didn't bother yet to give an AI to the opponents (the Os), and it is intentional. There is no CSS style to it, I intend to append it with a css file. tictactoe.php is naturally the name of the script itself, so each links are refering to the page itself. Now I don't know if I did everything correctly, here are my concern: If I want to expand the functionalities of the game in the future (adding javascript, opponent AIs, new game features), I fear that the structure of the code is not adapted for it. Should I change my code so it is Object Oriented? EDIT I have in mind to add new feature to the game, like powers who would change the state of the board, like rewind to a previous state and; some css and javascript in a non-intrusive way and add some way to check if options are disabled (like javascript/flash), or check for the version of the browser for html5/css3 features. As for now, it is easy to "cheat" and directly introduce the wished board state. I would like to prevent that, and if possible without using javascript, as I want the game to be playable also without it. ';} echo ' '; //representation of the player token, depending on the ID if($values[$i]==1){ echo 'X'; }else if($values[$i]==-1){ echo 'O'; }else{ //If noone put a token on this, and if noone won, make a link to allow player X to //put its token here. Otherwise, empty space. if($winstate==0){ $values_link = $values; $values_link[$i]=1; echo ' '; }else{ echo ' '; } } echo ' '; //end of a row if(fmod($i,3)==2){echo ' ';} } ?> Player '.(($winstate==1)?'X':'O').' won! '; } ?>
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|php|game|tic-tac-toe|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0080/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0080/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
Goal: To create a countdown to our next available live stream. Details: We live stream six times a week all (PST). 1. Sunday at 8:00 a.m. 2. Sunday at 10:00 a.m. 3. Sunday at 12:00 p.m. 4. Sunday at 6:30 p.m. 5. Wednesday at 7:00 p.m. 6. Saturday at 10:00 a.m. My approach: I check what day it is and what time it is then create the countdown to the next stream. I'm sure what I have done can be cleaned up and improved, so tell me how. modify("+$addDay day"); } $date = strtotime($date->format("Y-m-d G:i:s")); $now = strtotime("now"); $count = $date - $now; ?> var myTime = ; $('#countdown').countdown({ until: myTime});
|
|
|
|
|
|
|
|
|
codereview-0087/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0087/instruction.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
This system has to manage students, teachers, staff and grading. This is for production and is not a school assignment. As such, please let me know if I can improve on any aspect. :) My main concern is automation. I'd like my software to be able to run regardless if I still exist. I'm using SQLite as the database: create table User ( ID integer primary key autoincrement, Username string, Password string ); create table Area ( ID integer primary key autoincrement, Name string ); create table Subject ( ID integer primary key autoincrement, Name string, Abbreviation string, IDArea integer references Area(ID) ); create table Level ( ID integer primary key autoincrement, Name string, Principle string ); create table Grade ( ID integer primary key autoincrement, Name string, IDLevel integer references Level(ID), Observation string ); create table StaffType ( ID integer primary key autoincrement, Name string ); create table Staff ( ID integer primary key autoincrement, IDStaffType integer references StaffType(ID), Name string, LastNameFather string, LastNameMother string, DateOfBirth string, PlaceOfBirth string, Sex string, Carnet string, Telephone string, MobilePhone string, Address string, FatherName string, MotherName string, FatherContact string, MotherContact string, FatherPlaceOfWork string, MotherPlaceOfWork string, DateOfHiring string, YearsOfService string, Formation string, Specialty string, Category string, Salary string ); create table GradeParalelo ( ID integer primary key autoincrement, IDGrade integer references Grade(ID), IDStaff integer references Staff(ID), Name string ); create table Student ( ID integer primary key autoincrement, IDGradeParalelo integer references GradeParalelo(ID), Rude string, Name string, LastNameFather string, LastNameMother string, DateOfBirth string, PlaceOfBirth string, Sex string, Carnet string, Telephone string, MobilePhone string, Address string, FatherName string, MotherName string, FatherMobilePhone string, MotherMobilePhone string, FatherProfession string, MotherProfession string, FatherPlaceOfWork string, MotherPlaceOfWork string, Observations string ); create table Attendance ( ID integer primary key autoincrement, IDStudent integer references Student(ID), Attended string, Date string ); create table SubjectGrade ( ID integer primary key autoincrement, IDGrade integer references Grade(ID), IDSubject integer references Subject(ID) ); create table ScoreRecord ( ID integer primary key autoincrement, IDSubject integer references Subject(ID), IDStudent integer references Student(ID), FirstTrimester integer, SecondTrimester integer, ThirdTrimester integer, FinalGrade integer, Year string ); Any glaring room for improvement?
|
|
|
|
|
|
|
|
|
codereview-0093/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0093/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Calculating totals of a transaction
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I am working on a project where I have to calculate the totals of a transaction. Unfortunately, coupons have proven to be quite an issue. There are four types of coupons: transaction percentage, transaction dollar amounts, item percentage and item dollar amounts. I ended-up with this beast of a method, and was wondering if it is clear why I'm doing each part in the way I am. Are my comments are detailed enough? Is my code is more-or-less readable? Is there a way to simplify any of it? private static Totals CalculateTotals(List items, List coupons, List payments) { // Local vars, totals gets returned. Totals totals = new Totals(); decimal subtotal = 0; decimal workingSubtotal = 0; decimal discounts = 0; decimal tax = 0; decimal paid = 0; decimal taxRate = (Initialization.Location.TaxRate ?? 0); // Get the subtotal before any discounts. items.ForEach(i => subtotal += (i.Price ?? 0)); // An ItemCoupon takes a whole amount or percentage off of a single Item. // It can take it off of the most expensive, or least. Nothing in the middle. foreach (var coupon in coupons.OfType ()) { // new Item to hold the item to be discounted. Item item; // Find which item to discount. if (coupon.DiscountMostExpensive) { item = items.OrderByDescending(i => i.Price).FirstOrDefault(); } else // Otherwise, Discount LEAST Expensive. { item = items.OrderByDescending(i => i.Price).LastOrDefault(); } // Remove it from the list, before editing the price. items.Remove(item); // Set new price of item based on the type of coupon. (Percent, or whole dollar.) if (coupon.PercentageCoupon) { item.Price = Utils.CalculatePercentage(item.Price, coupon.DiscountPercentage); } else { item.Price = (item.Price ?? 0) - (coupon.DiscountAmount ?? 0); } // Add the item back to the list, with the new price. items.Add(item); } // Now that the single items have been discounted, let's get a wroking subtotal. items.ForEach(i => workingSubtotal += (i.Price ?? 0)); // A TransactionCoupon takes a whole amount or percentage off of the entire transaction. // To simplfy tax caculation--and because some items are non-taxable, // oh and, because we don't want any one item going below zero--we // split the discount over all the items, evenly. foreach (var coupon in coupons.OfType ()) { if (coupon.PercentageCoupon) { // If it is a Percentage Coupon, simply take said percentage of off each item. items.ForEach(i => i.Price = Utils.CalculatePercentage(i.Price, coupon.DiscountPercentage)); } else { // If it is a whole amount, get each items percent of the of the subtotal, and discount them equally. // This would look way too confusing using lambda. foreach (var item in items) { decimal discount = (item.Price ?? 0) * ((coupon.DiscountAmount ?? 0) / workingSubtotal); item.Price = item.Price - discount; } } } // Let's get the new-new-new subtotal. workingSubtotal = 0; items.ForEach(i => workingSubtotal += (i.Price ?? 0)); // Calculate the total discounts. discounts += (subtotal - workingSubtotal); // Set tax for order. (This must be done after ALL discounts have been applied) foreach (var item in items.Where(i => i.Taxable)) { tax += ((item.Price ?? 0) * taxRate); } // Get the total amount paid. payments.ForEach(p => paid += p.Amount); // Add all the results to the Totals struct. totals.Subtotal = subtotal; // Never return the workingSubtotal; totals.Discounts = discounts; totals.Tax = tax; totals.Paid = paid; totals.Total = ((workingSubtotal + tax) - paid); return totals; }
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|c#|linq|finance|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0097/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0097/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Simple MVC in PHP
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I have a very simple PHP MVC library for my auto-didactic pedagogical purposes. I'm having a little trouble figuring out how to add in the observer patterns as show in this UML diagram from Wikipedia . model is simply contains an array and acts as a key-value store. contrlr accepts input, ostensibly from $_POST , to update a model. So then the observation relationships between the three are where my understanding breaks down. I have contrlr implementing SplOberserver and SplSubject , but how exactly should I handle communication between them? Concatenate strings to strHtml ? Please note that I want to have these classes conform to the UML diagram linked from Wikipedia above. class model { private $arrValues = array(); public function __get($var) { return $this->arrValues[$var]; } public function __set($var, $val) { $this->arrValues[$var] = $val; } } class contrlr implements SplOberver, SplSubject { private $objModel; public function __construct( model $objModel ) { $this->objModel = $objModel; } public function parsePost( array $arrPost ) { foreach ( $arrPost as $key => $value ) { $this->objModel->$key = $value; } } public function update() { } public function attach() { } public function detach() { } } class view implements SplObserver { private $strHtml; public function getHtml() { return $this->strHtml; } }
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|php|mvc|spl|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0098/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0098/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Need a feedback on my Javascript code and app implementation idea
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I'm new into Javascript, and I'm not sure that is a good approach. The code works, and does what I need it to do but I'm sure I didn't do the things the right way. Can you give me feedback about the implementation idea and code? So, let's say that in index.html I have the following code into body section. The content of the main.js file is the following: document.write(' '); function loaded() { } loaded(); document.write(' '); I know that using document.write it is not a smart thing at all. I'm sure that other things are faulty, but I'm newbie and I'm looking for your feedback.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|javascript|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0099/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0099/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Arguments in constructors matching fields
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
What is your opinion in arguments in constructors matching members as in the following example public Join(final int parent, final TIntHashSet children) { this.parent = parent; this.children = children; } I find this annoying since I have to use this. and also some code review applications generate warnings.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|java|constructor|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0100/environment/Dockerfile
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
FROM ubuntu:24.04
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codereview-0100/instruction.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# Code Review Request
|
| 2 |
-
|
| 3 |
-
## Title
|
| 4 |
-
Usage of the ternary "?:" operator with functions listening to click events
|
| 5 |
-
|
| 6 |
-
## Question
|
| 7 |
-
I've recently been doing some mods to some old code I've been maintaining for a couple of years now. As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I have a function that listens to click events on 3 buttons in a given panel set: addFooListeners = function (panelType) { YAHOO.util.Event.addListener("show" + panelType, "click", showFoo, eval(ns + ".panel_" + panelType), true); YAHOO.util.Event.addListener("hide" + panelType, "click", hideFoo, eval(ns + ".panel_" + panelType), true); YAHOO.util.Event.addListener("commit" + panelType, "click", commitFoo, eval(ns + ".panel_" + panelType), true); } This code is the result of a number of panels/dialogs having near identical behaviour. For this round of development I've needed to add the ability to do things a little differently from time to time, so I added an object, overrides which allows me to point the show , hide and commit actions elsewhere. I came up with the following: addFooListeners = function (panelType, overrides) { var handlers = { show: ( overrides != null ? ( overrides.show != null ? overrides.show : showFoo ) : showFoo ), hide: ( overrides != null ? ( overrides.hide != null ? overrides.hide : hideFoo ) : hideFoo ), commit: ( overrides != null ? ( overrides.commit != null ? overrides.commit : commitFoo ) : commitFoo ) } YAHOO.util.Event.addListener("show" + panelType, "click", handlers.show, eval(ns + ".panel_" + panelType), true); YAHOO.util.Event.addListener("hide" + panelType, "click", handlers.hide, eval(ns + ".panel_" + panelType), true); YAHOO.util.Event.addListener("commit" + panelType, "click", handlers.commit, eval(ns + ".panel_" + panelType), true); } As you can see I'm enforcing default behaviour unless an appropriate attribute in the overrides object is set with another function (named or anonymous). Is there a cleaner / more readable way to concisely setup the handlers object? The nested ternary seems to my eyes to be cluttering things a bit but other approaches like if ( overrides != null ) { ... } seem just as messy.
|
| 8 |
-
|
| 9 |
-
## Tags
|
| 10 |
-
|javascript|
|
| 11 |
-
|
| 12 |
-
## Task
|
| 13 |
-
Please review the code provided in the question above and provide constructive feedback, suggestions for improvement, and best practices recommendations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|