instruction
stringlengths
71
71.9k
I'm building the above mentioned parser. It reads a string of assembler instructions. I want to become a better coder, so I wanted to get a code review to start learning to do things property. As we know instruction is a string with an instruction mnemonic like "mov","lea","add" followed by 0 to 3 operands, separated ...
EDIT: The code i provide includes a asynchron task in each interation, therefor i need the recursive function, my question is how to beautify the code and apply the proper use. I want to: Remove the processTask(); function call and let it call itself instead. Choose the best function declaration. connection.query(quer...
This is my first 'proper' script since learning python and I'd love it if I could get some feedback on things I've done wrong / things I can improve on. The script takes clipboard data from after effects, containing information on position, rotation and scale. It then gets out the numbers, converts them to keyframe d...
Design a class TIME which stores hour, minute and second. The class should have the methods to support the following: User may give the time value in 24-hour format. User may give the time value in AM/PM format Display the time in 24-hour format. Display the time in AM/PM format. User may like to add minute with a ...
I am working on a node.js sails.js app that handles a number of API calls and uses Bluebird for promises. The API calls have been reliable but I would like to build in handling for if they do not respond. I'm wondering if there is a good standard practice for handling timeouts (or a different approach) if the API servi...
I recently create a function to combine some arrays of associative arrays in a single array in response to a stackoverflow question, where you can found more details about this. The function works as expected, but I think their description is very obscure. In addition, i choose constant T_OBJECT_CAST as option to conve...
I am creating a game with destructive terrain. Before I used a flat array to store the blocks, in chunks of 32^3. As I am aiming for detail and long view distance I would of course need some sort of LOD. Therefore I decided to use a octree instead. Memory usage is significantly less than the flat array, but accessing n...
I'm looking for some feedback on some code, designed to allow me to strongly-type parameters, which get passed to functions. I'm only really looking for comments on making my parameters more strongly typed, as well as the existence of the factory method. The implementation of the FindUser method is not relevant. At the...
I have this Quicksort implementation that sorts arrays of int (not Integer). It has comparable performance to Java's DualPivotQuicksort, especially when the size of the range is below one million elements or so. IntegerQuicksort.java package net.coderodde.util; import java.util.Arrays; import java.util.Random; public...
I have this project that should respond to events. Can my code can be refactored and become shorter? Am I using actionListener properly? public class DifferentShapes extends JPanel implements Shapes{ protected JMenuBar menuBar = new JMenuBar(); protected JRadioButton small = new JRadioButton("small"); protected JRadio...
Since I'm a big politics nerd, I wanted to write a little script that would analyze the frequency and content of political fundraising emails. I signed up for the e-mails of 6 campaigns, donated a dollar to each so I'd get hit up for more money often, and let it sit. Unfortunately you won't be able to run the script ...
I have tried my hands at "functionalising" a toy problem I had: find the expected number of throws of a six sided die until all sides have been seen (the answer is 14.7) My starting point is my imperative solution import scala.collection.mutable.SortedSet import scala.util.Random def dice(nsim:Int) : Double = { va...
This code is for a magic 8 ball in Python. What do you think? import random import time choices=[ "Definitely", "Yes", "Probably", "Mabye", "Probably Not", "No", "Definitely Not", "I don't know", "Ask Later", "I'm too tired" ] while True: input("Ask the mighty 8-Ball a question\nOo") for i in range(0,3): ...
I'm giving a presentation in a few days. I'm preparing my material in LaTeX; however, I am relatively new to it. How can I make my LaTeX code more concise and less repetitive? Here is a reduced version of my presentation, which contains the following features that I'm seeking to improve and tighten up: Code samples ...
I wrote a test program (and first "real" Haskell program!) that receives a zmq request on 1 socket, and forwards part of that message to another socket. There are a 2 things I specifically don't like: I couldn't figure out a way to build a protobuf message without specifying every field. This is especially annoying f...
I am trying to find a phrase or a string in file and count the number of occurrences of that string: private static HashMap<String, Integer> bruteForceSearch( String stringToLookFor, List<File> list) throws IOException { HashMap<String, Integer> result = new HashMap<String, Integer>(); for (File file : ...
Let's assume I have 2 objects Product and Volume. 1 Product must have at least 1 Volume which means: Product ----> 1...* Volume. I want to keep the consistence of Product at its creation, in other words, I want to block the user to create products without any volumes. I have a ready working code, but nonetheless I want...
I've written an interrupted bubble sort, which prints the intermediate result after some specified number of iterations of bubble sort. But I seem to have an speed issue. Could anyone help me spot some places that need to be optimized or are just plain wrong? #include <iostream> #include <fstream> #include <string> #in...
I have a stack of numbers ranging from 1 to 1 million representing a pile of numbered DVDs. Given the stack in random order I am to sort the stack by only taking an element from the stack and push it to the top and then calculate the minimum of such pushes necessary. My code is way too inefficient when dealing with lar...
I wrote this, which I'm not sure if it's of any use yet but at least it saves me some time when writing atomics to a file or raw memory. What I was thinking is that the conditional in the write()/read() methods isn't very good and maybe I should add methods like calcwrite()/calcread() for calculating the space required...
I wrote a minimal implementation of a hashtable in python as an exercise. from copy import copy def init_nested_array(size): arr = [] for i in range(size): arr.append([]) return arr class hashtable: def __init__(self): self.mod = 3 self.num_items = 0 self.arr = init_nested_array(self.mod) ...
I am relatively new to Angular and need to put together an application to update / save / display values. The code is working, but I wanted your input the make sure that I am doing this 'the angular way'. JavaScript var app = angular.module('store', []); app.controller('TableController', ['$scope', '$log',function($sc...
This is just a simple little drum machine. Since it loads sounds files, I can't just put it on JSFiddle. I tried Github pages too, but am not sure how to get the sound files working. However, you can clone the repo, run a server with python -m SimpleHTTPServer 8000 (it won't work if opened with the file:// protocol), a...
I was interested in finding some of the weirdest question/protection combinations, basically out of curiosity. I heuristically defined this as: Low view counts Not a moderator/SE employee From users who protect multiple questions I'm... let's just say not an expert in SQL. Though this query works, it feels super inef...
I just started learning Erlang. Here is my crack at the Seive, based on (https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf): -module(seive). -export([seive/1]). seive(N) -> L = lists:seq(1,N), {Megass, Ss, Micros} = erlang:timestamp(), S = doseive(L, 2), {Megase, Se, Microe} = erlang:timestamp(), ...
I have implemented a LRU cache using ConcurrentLinkedHashMap. In the same map, I am purging events if my map reaches a particular limit as shown below. I have a MAX_SIZE variable which is equivalent to 3.7 GB and as soon as my map reaches that limit, I am purging events from my map. Below is my code: import java.util.c...
I am a nurse and I'm learning to code. I have coded this simple tool that helps me doing some common nursing formulas for medication. It works, however I think it is too bulky/redundant. Can you help me with some ideas for refactoring it? class NursingFormulas def initialize puts "What do you want to do?" put...
I made a simple JavaFX calculator. It does basic calculations, and works to the best of my knowledge. However, I'm a novice at both Java and JavaFX, so I seriously doubt this is as efficient and clean as possible. I personally think it could be more modular, maybe put those huge loops in functions or something. package...
I built an application class that should be runnable as a Thread and it would be nice to hear opinions of Java developers to improve my coding style. Main class. package com.ozankurt; public class Main { public static void main(String[] args) { Application application = new Application(); applic...
I have to swap the characters in a string before sending said string to a device to show the information sent through a LCD, the method I developed is as follows: private string StringSwap(string stringToSwap) { if ((stringToSwap.Length % 2).Equals(1)) { stringToSwap += " "; } char[] array = st...
I am a self-taught programmer and would love any advice / suggestions. I wanted to implement some sort of n-tier Architecture, but not sure how to move all my code around. My program will take movies from my hard drive and eventually allow me to view the results in a nice Netflix like UI. The code below is just the beg...
I am a relatively new Rails developer and doctor doing research. In my Rails based research projects I often have questionnaires for which I provide a "% complete" parameter. Here is an example. You can see that each of the score attributes is given a value and then I can create a %. It looks awful and very un-Ruby-li...
I have a Ruby programming task. My code passes all the rspec requirements, but I am not sure if I've done it in the right way. And I'm not quite sure why I need :entries there... Here is the rspec test: # # Topics # # * Hash # * Array # * instance variables # * regular expressions require '11_dictionary' describe Dic...
I am working on a simple mouseout and mouseover functions. Basically, I have color boxes (or swatches) and I have to get the color of the specific box when hovered and when selected. You can see how it works in the fiddle. So I came out with a working script. But I am not sure how I can optimize or shorten the script s...
template<class Compare, class Iterator> void merge_sort(Iterator start, Iterator fin, int sort_type) { Compare comp; typedef typename iterator_traits<Iterator>::value_type _value_type; //black type magic to infer data type if (distance(start, fin) > 1) { vector<_value_type> left (start, start+di...
Is there a better way to write this? $query = $db->getConnection()->prepare("INSERT INTO `users` (first_name, last_name, email, username, password, unique_id, date_joined) VALUES(:fname, :lname, :email, :username, :pass, :uniqueid, :date_joined)"); $query->bindParam(':fname', $first_name, PDO::PARAM_STR); $query->bindP...
This method allows the user to choose a start and end date in human readable form, then convert it to epoch. The method will return a array of longs composed by the epoch start date and the epoch end date. I handle some exception so if the user types anything else than the date it will end the iteration and start agai...
For no particular reason, I wanted to create a function that would take a string and "encrypt" it via Caesar cipher. This function takes a string and shifts the letters left or right (in the alphabet) depending on the input. Shift right(2) for instance would be - ABCDEFGHIJKLMNOPQRSTUVWXYZ CDEFGHIJKLMNOPQRSTUVWXYZAB T...
I'm currently working in a Windows.Forms project where its very common that I need to show a responsive feedback form while a task runs. These tasks take typically around 5 to 10 seconds to complete and the user can't do anything else until the task has successfully finished or failed. To keep the UI responsive I've co...
Every week I've got to send a report to a clerk. I also have to add his deputy in case the clerk isn't available. For not to forget the second recipient and the attachment I've wrote myself this VBA-Macro. Perhaps one could enhance it in a way that it works with more then two recipients? Any comments and suggestions...
I'm using the Jquery date time picker link here In the four methods below I am initializing the DT pickers but they are all pretty similar except for the ID in the onChangeDateTime. Is there a way I can reduce the duplicate code? $('.jqDatetimeDateOne').datetimepicker({ defaultTime: '07:00', lang: 'en', cla...
I am currently trying out code for timing efficiency (how fast it runs, basically). The general consensus is that code with ActiveCell,.Select,Selection and so forth are basicly rejected for being slow and buggy, whereas code that uses variables and not ActiveCell,.Select,Selection are considered quicker and less buggy...
I am doing Project Euler problem 67 which involves finding the heaviest path through a triangle of integers like this one (this is a smaller version from an earlier problem) 75 95 64 17 47 82 18 35 87 10 20 04 82 47 65 19 01 23 75 03 34 88 02 77 73 07 63 67 99 65 04 28 06 16 70 92 41 41 26 56 83 40 80 70 33 41 48 72 33...
As an exercise in learning, I'm creating a bugs/issues tracking and "aggregator" web application. A simple app consisting of products, issues, reviews and links related to it. The links will be urls pointing to issues/reviews already created on external sites (bugzillas, stackoverflow, etc). Here is my initial effort t...
The required behaviour is : The yellow span must be positioned relatively to viewport (position:fixed;) when it is inside the pink div. The height of yellow span must always be the same as viewport height minus 100px. It has a fixed width in px. The yellow span must be verticaly centered in the viewport (this rule is ...
I am experimenting with ES6 using BabelJS in a codepen project you can find here. I am confused as to why my code breaks when I decide to use let instead of var in the following function: function getUnits(country) { const imperialCountries = ['US', 'BS', 'BZ', 'KY', 'PW']; if (imperialCountries.indexOf(country) === -...
Considering that: the passed parameters are all numbers the passed date is a valid date It should return: true if the date is 18 or more years old false otherwise function isDate18orMoreYearsOld(day, month, year) { var maxBirthDate = new Date(); maxBirthDate = new Date(maxBirthDate.setYear(maxBirthDate.get...
The program shows three phones with prices, and you need to select one of them. The program will then calculate the price based on the payment type you selected. I'm very new to the world of OOP, and because I'm studying OOP on my own (I actually go to school and we have a computer subject, but I'm taking advance lesso...
I'am writing on a spatial clustering algorithm using pandas and scipy's kdtree. I profiled the code and the .loc part takes most time for bigger datasets. I wonder if its possible to speed up the points.loc[idx, 'cluster'] = clusterNr somehow. import numpy as np import pandas as pd from sklearn.neighbors import Nearest...
I've been working on improving my C coding. I wanted to write two string algorithms: to trim white space from the beginning and end of a string to compact a string I have a few problems with this code that I was hoping to get some advice on: The casts from const char * to char *. Is there a clean and idiomatic way o...
Assume I created an image in NumPy: image = imread(...) And the image is RGB: assert len(image.shape) == 3 and image.shape[2] == 3 I want to check (i.e. get a boolean mask) which pixels are (R=255, G=127, B=63) in a cleaner and efficient way: mask = (img[:, :, 0] == 255) & (img[:, :, 1] == 127) & (img[:, :, 2] == 63)...
I have a list of non-unique values. I want to output a list of the same length where each value corresponds to how many times that value has appeared so far. The code I have written to do this seems over-complicated, so I think there has to be a better way. x = [1,1,2,3,1,3] def times_so_far(ls): out = [0]*len(x...
I did a maze thing ages ago that could support any number of dimensions, but it was very slow to generate. To get an idea of how it generally works with the multiplier and stuff, here's a gif of something I made with it: One thing that always bugged me was I couldn't figure out pathfinding, and I thought there'd be so...
After reading LYAH and using RWH as a reference, I've been doing the exercises from CIS194, which is often suggested to beginners on irc://freenode.net/#haskell and by this author. I've just completed Homework 12, which goes with Lesson 12 and focuses on Monads, using the template provided here. You can find the comple...
I am in the process of creating a program that allows a user to input known parts of a right triangle and the calculates all of the unknown parts if it is possible. I am using a class that I wrote in order to do the calculations. I wanted to know if there is a more efficient solution to this problem or if my code is go...
I'm putting together some RESTful services using ASP.NET Web API. This is the first time I have done this, so I'm looking for general feedback on this controller to make sure I'm not doing anything that doesn't make sense or that will be confusing to future maintainers of the code. The factory is brought in using MEF, ...
We are working on an assignment where we have to generate code that will play player one in the game Cows and Bulls. I am working on a function that generates the code based on the values for codeSize and codeChars. CodeSize being the size of the code, CodeChars being alpha or numeric, depending on what is selected by ...
Several times we need to be able to revert the data the user is inserting to a previous state (cancel data update). In order to keep DRY and for the sake of separation of concerns I thought about a way of just allowing that. public class RevertableObject<T> : ViewModelBase //implements INotifyPropertyChanged where ...
I'm developing a simple application that crawls web pages to obtain some information. For this I used and tested some libraries, like crawler4j, jsoup, jaunt and htmlunit. I change the crawler APIs several times because sometimes perceived that one served me better in a certain feature than the one I was using. I may h...
I put together this simple query to calculate the percentage of downvotes each user is responsible for and displaying them in order of downvote percentage. It's generating the desired results, but I am uncertain about style and best practices. WITH DownVoteCount AS ( SELECT DownVoteCount = CAST(SUM(DownVotes) AS float)...
I wrote a basic JavaScript plugin that allows you to specify what specific JavaScript files and CSS files to be loaded in, and in addition specify attributes for each file. To specify where to load in scripts, you just have to add a data-script-loader attribute to an element, and all scripts will be inserted after that...
I've gotten a solution for Project Euler #7 in C (find the 10,001st prime). I came up with the very simple algorithm myself (from what I can tell it's similar, if not identical, to the Sieve of Eratosthenes). #include <stdio.h> #include <stdlib.h> long prime_finder(int amount_of_primes); int main(void) { int amount_...
I've made an attempt at writing a skip list in Python. I'm using NumPy to generate geometric random variables, but since that's a bit of a heavy dependency to drag around I could easily implement that myself. I based my implementation on the basic (none of the improvements such as capping node height etc.) algorithm he...
Following this linked question and the feedback it generated, I put together a new query which utilizes a JOIN. WITH UpvotedComments AS ( SELECT PostId, Score, Text, --Comments.UserDisplayName doesn't return users' current display names Commenter = ( SELECT DisplayName FROM Users ...
I'm coding a "encryption" algorithm for learning and and don't know how good is it or how could I make it better: private static byte[] encrypt(byte[] data, int session_id, byte[] password) { int session_key = (session_id & 0xFF); if (session_key == 0) session_key = (session_id << 4); byte[]...
Please review the following in-place implementation of Heapsort in Python: def heapsort(l): def plunge(l, i, n): lchild = 2 * i + 1 while lchild < n: rchild = lchild + 1 if rchild < n and l[lchild] < l[rchild]: child = rchild else: ...
I have written a BST using one class. Is my code okey or something could be better? /** * BST using one class * @author Mateusz Stankiewicz */ public class Node { private Comparable data; private Node left; private Node right; private static Node root; /** * Tree constructor */ public Node() { root = null; } ...
I have this small function for reading the TSC (time-stamp counter) in *nix. Using it seems to report my CPU frequency more or less correctly. #include <stdint.h> #include <stdio.h> #include <unistd.h> uint64_t read_time_stamp_counter() { uint32_t my_edx; uint32_t my_eax; asm ("cpuid\n\t" /* Discourag...
I have written this file in PHP using MySQL. However, I have a lot of code that looks like it could be simplified. Can someone suggest a way to make this more efficient? i.e. I want to follow the D.R.Y method. <?php require_once('database.php'); try{ $result = $conn->query('SELECT id FROM documentaries'); }...
The code looks for the specified .tgz file, if it's not present, it creates it. It looks for files ending in .txt in the cwd and adds them to a list. It decompresses the gzip, checks for the .txt files in the tar, adds the missing files to the tar and then recreates the compressed gzip with the new files in it. It then...
I am writing a brute-force method to search for a word. Please review my code and tell me how I can improve it. public class Searcher { private static String filepath = null; private static final String defaultPath = "//sample_text"; private Searcher() { this.filepath = defaultPath; } private Searcher(...
I made an implementation of the Bridge Pattern to handle ever-changing in crawler APIs that I'm using in my APP. public interface CrawlerApi { // common constants to serveral implementations. String CHARSET = "ISO8859_1"; int TIMEOUT = 20000; /** * Visit an url and return contents in String format...
A few weeks ago, I asked for another DIC review, but didn't get any response (but only for one about my error handling). So I tried to rework my DIC without any outside insight on it, and the first thing that came to my mind is that my DIC wasn't really ergonomic. So I tried making one with dynamic setters/getters. The...
I'm putting together a simple application container for learning purposes, and I would like to hear how you see this code. The application is the main class that will contain services, configuration and other related stuff. I have identified 3 position where I can't decide on the design: Each application should be sup...
I was hoping for a bit of advice on cleaning a couple of areas of this code up. In particular, the hex-to-binary section, the checksum is in hex, and the rest is in ASCII. I tried for a good day to do it with tables etc, but in frustration I ended up going with this. Is there a better way of handling the "Store individ...
This is code from my android client which communicates over wifi to a small server program (not coded in java). This is my first time playing around with sockets, so I'm sure there are lots of little gotchas to worry about. For this project I am limited to Java 7. The protocol for sending a message is 4 Bytes for an ...
For a game I am playing, OGame, I am trying to calculate the fastest strategy to reach a certain state in the game, relevant parts of the game for this question are: You can build different types of buildings. Buildings take time to be built. In particular the Metal Mine, Crystal Mine and Deuterium Synthesizer buildin...
I just want to know if my code can be weak. Can anyone also spot a mistake in my code? Encrypt public static String byte2hex(byte[] b) { //we know exactly how long the resulting string should be so pass that information along to minimize allocations StringBuilder hs = new StringBuilder(b.length*2); for (int...
When writing an answer to another question here, I came across the problem of producing lists of integers having a certain total and only consisting of a certain number and an optional rest. So for total 21 and number 5 you would get List(5, 5, 5, 5, 1). Solving the problem is obviously not hard. However, I have the fe...
I'm a beginner at coding and the past days I tried to write the famous "Conway's Game of Life" in Angular.js. Right now I'm done with the code and the game works. But if the size of the playground grid gets too big (e.g. 100x100 cells), my program is kind of slow. I wanted to ask you where I could improve my code to ma...
I made two functions: one to get process id and the other to get a handle with all access to that process using the process id. I'm looking for help with making these easy to use on all types of projects. The only thing I know is maybe letting the person chose the open process properties. DWORD getProcID(const std::wst...
This code is a Parser that parses numbers according to R5RS. #b1001 - binary #o2127 - octal #h02d - hexadecimal #d1231 - decimal 3923 - decimal It is working at the moment, the only problem is the parseNumberBase. I am really new to haskell, but it does not look very good to me. How could I improve it? (readabil...
I'm new to parsing, and there's only one way to learn anything, and that's to do it yourself. So I did. I wrote what is essentially a calculator. But instead you will send it a string and it will be evaluated. It's syntax is as follows: 5 + 5 2 * sin(45 * 2) 2 * sin 90 2*sin(90) 2*sin90 As you can see, it does not hav...
I'm playing around with database designs to use for a new system. This system at its core revolves around various types of items (users, accounts, images), their meta (names, titles, file sizes), and item's relation to each other (users mapped to accounts, images mapped to users). Comments I created the uid solution ...
I wrote the below function which successfully creates pairs of dates in the format I need. However, I'm fairly new to Python and feel there must be a way to make this easier to read. Can this code be improved? def getNextTenDays(): dates = [] arrive = datetime.datetime.now() for n in range(1, 11): a...
Is my implementation of AVL tree correct? It is my second Python program and I am not sure if do code properly. ''' Created on 30 sty 2016 AVL tree - my second python program :) @author: stanek ''' class Node: def __init__(self, data, left = None, right = None, height = 0): self.data = data self...
Earlier today I tried to implement an example of the bridge design pattern, but I ended up misinterpreting it. I made a lot of changes: public interface VisitorAPI { String visit (String url); } public class JsoupVisitorAPI implements VisitorAPI { @Override public String visit(String url) { try {...
I wrote a script to change a static image by hovering over navigation links. It works great, however, the script is very long and I'm guessing there is a much more efficient way to write this code. Can anyone give me tips on a better way to do this? HTML <ul id="navigation"> <li><a id="1" href="#">Link 1</a></li> <...
I am taking input from a text file, performing matrix multiplication, then outputting to another text file. I just want to be a better programmer, so please be a detailed as you want. Comments, naming, formatting, etc. import java.io.*; import java.util.*; import java.util.stream.*; public class MartixMain { ...
import java.io.IOException; import java.util.Scanner; public class Main { private static int random = (int) (Math.random() * 100 + 1); private static int data; private static int go; private static int attempt = 10; public static void Start() throws IOException { Scanner scanInput = new ...
I made a tool set to facilitate bit manipulation as follows. Any comments are welcome, be it about the interface design, the implementation, or even the naming. Also, I want to make sure that the tool set is not lacking something for use-cases I failed to catch :-) Original code and unit tests can be found here and her...
I recently started up again on a 2D game engine I have been working on over the last couple of years. I managed to implement a version of the a* algorithm that seems to work fine for my game, but it seems to be having a dramatic impact on my games performance when I have multiple enemies using it. Currently I am callin...
import random import operator import pickle classname = "" while True: classpick = input("Enter class name (\"A,B,C\") ").upper() try: if classpick in ["A","B","C"]: classname = "class"+classpick+".txt" break else: raise ValueError except ValueError: ...
(See the previous iteration.) I have incorporated some points made by ChrisWue and refactored my Fibonacci heap implementation: fibonacci_heap.h #ifndef FIBONACCI_HEAP_H #define FIBONACCI_HEAP_H #include <stdbool.h> #include <stdlib.h> #ifdef __cplusplus extern "C" { #endif typedef struct fibonacci_heap fibonac...
I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for Swift 3.0. That is, C-style for loops will no longer be available in Swift as of 3.0, so I want to completely discontinue...
Here is my issue.I have two classes: public class Role { public string RoleTitle { get; set; } public string Office { get; set; } public string Department { get; set; } } And public class Employe { public string Name { get; set; } public List<Role> Roles { get; set; } } As you can see, class Employee contai...
I have written this function that returns the common divisors of two integers. When called recursively 10 times with big integers ranging in 100000000, it takes over 5 seconds. How can I improve it so that it is faster (less than 5 seconds)? commonDivisors :: Int -> Int -> [Int] commonDivisors x y = if x > y then divis...
Can you say, is this a bad code for registration in Django? Do I need to fix something or use a pip instead? (I am learning) def register(request): error_messages = {} if request.POST: form = UserCreationForm(request.POST) if form.is_valid(): new_user = form.save() us...
Just wrote a program to check if a string is Palindrome. If that's true, return 1. Else, return 0. How can I improve it? #include <stdio.h> #include <string.h> #include <ctype.h> int palindrome(char *s) { int i = 0, length = strlen(s) - 1, n = length; int boolean = 0; for (; i <= length && n >= 0; i++, n-...
I'm working my way through some basic OpenGL tutorials and have decided to offload the shader loading/compiling/linking to a separate object that I'll use for the remainder of the tutorial material. Ideally, I'd also like it to be useful later, when I get on with working my own OpenGL projects. And, who knows, maybe so...