instruction stringlengths 71 71.9k |
|---|
Given a number \$t\$, (\$1 \leq t \leq 1000\$) that represent
testcases and \$t\$ numbers \$n\$ (\$1 \leq n \leq 10^9\$). Show the
next multiple of \$n\$ that is a perfect square number.
Example of input:
5
5 9 10 12 13
Example of output:
Case #1: 25
Case #2: 9
Case #3: 100
Case #4: 36
Case #5: 169
My solut... |
I've written an implementation for the Sherlock GCD HackerRank Challenge. As the running time of my algorithm is something like \$O(kn^2)\$, I reckon that there's a more efficient algorithm that could be used instead. Are there any improvements that can be made to my implementation to reduce the running time?
Problem s... |
I've written a function (in Python 3) which computes if a line segment (constraint) and a circle (body) collide, and returns the point of intersection (closest point to the centre of the circle):
def constraintCollide(self, constraint):
p1 = constraint.point1 # Sets the first point object of the constraint to p1
... |
As I'm getting to grips with front end development I'm looking to consolidate/improve my below HTML, CSS and JS code in terms of adhering to best practices so any advice is appreciated.
Quick overview:
I'm working on a page which has required me to create a page with a nav bar, a horizontal bar below the nav bar, a ver... |
I built this simple slider with JS, but I am not so experienced with programming and I wonder what can be improved in this code, how to dry it, or how to apply some OOP paradigms to it, what is not good in it, what is bad practice... If you are going to build this simple slider how would you approach it?
JSFIDDLE
HTML... |
I am going through the CodingBat exercises for Java. I have just completed this one:
Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that the remove string is length 1 or more. Remove only non-overla... |
I'm currently faced with a problem in our SQL Server environments. We need to migrate our existing logins, users and roles to a new login, user and role with the same permissions as the old. I've been tasked with writing a stored procedure that will accept 3 parameters:
Database Name
Old Role
New Role
Using these par... |
I need to get folder names with the path for which I need to search the directory in a server with about 6000 folders. I have the following snippet of code to run through the folder and get the folder names with path. It works fine in a local directory but when I run the same code on a server directory it fails after a... |
I was recently given a coding test by an employer. After the test, this was the employer's response:
"I’d say that a lot of his solutions were pretty inefficient and took
a very ‘brute force’ approach to a solution. For example, his solution
for question 1 took 30 lines (give or take for some spacing). This is
... |
Presenting you an implementation of the "shear and transpose" method of rotating a bitmap image. It works.. but it works slow, which is fully understandable. It is understandable due to the evident lack of optimization. Notwithstanding it doesn't interact with the VGA or any library for that matter.
#include <stdio.h>... |
I'm currently enrolled in an introductory C#/.Net 4.5 course and one of the things I want to focus on is the quality of my code.
This is the first assignment our instructor had us do, the ever-popular number guessing game. The requirements our instructor set out for us were:
On startup, the program asks the user to s... |
I think I put too much code in my controller that was supposed to go in the model.
This is a part of my controller, I'm not gonna paste everything since there is a lot of code.
public function ajaxUsers() {
if($_GET["action"] == "listUsers") {
if(!isset($_POST["search"])) {
$this->_data['Reco... |
I recently ran in to a problem with the presentation of data related to a graph. Each series of data has values that define the 'curve'. There can be a lot of these values, and I decided that there was not enough space in the 'legend' to include all the details for the curve. I decided to have a 'details' area, and use... |
I've updated my code according to some tips from a previous post and would like to post the new code for review.
// Calculates and generates a report card of students final grades
#include <iostream>
#include <fstream>
#include <string>
float assignWeight;
float midtermWeight;
float finalWeight;
float participationW... |
I've written a small C program that has ad hoc implementation of cruise control for my Altera DE2 FPGA. It works alright but there are too many global variables. Preferably there should be no global variables. How can I reduce the amount of global variables?
#include <stdio.h>
#include "system.h"
#include "includes.h"
... |
An Entity Component System works by grouping various components around a central ID, aka Entity. Entities and Components do not have any code, they are simply POD containers. Rather, the code lies in a system, which takes in a group of components and does work on them. I've written out an EntityManager class and a temp... |
This is a follow on to : Simplifying asynchronous "executeAsync" method along with "onFailure" callback.
I am using AsyncRestTemplate as my HttpClient to execute my URL and the server will return back a json string as the response. Customer will call this library by passing DataKey object which has userId in it.
Given... |
I've made a small "rover game" similar to this one, except made in C#, using OOP, and prettier menus. Here's how it works:
There is one Rover class which is instantiated into an array containing all rovers. This class contains certain actions that a rover might need like, MoveRover, or RoverDead. There is also a RoverM... |
Recently, I was taking up this challenge and choose my favorite language 'Ruby' to do it.
My following solution got accepted (Gist).
For each test case, I am to reverse two numbers, add them, and print the reverse of the sum. Reversing means taking the base-10 digits of a number in reverse order, stripping any leading... |
The previous iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up 2
Now my code looks like:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define HELP_FLAG "-h"
#define VERSION_FLAG "-v"
#define FLAG_DESC ... |
I am working on a project that involves scheduling real world events for a pool. Example: turn a pump on at 8AM, turn heater on at 9 AM, set heating temperature to 80 degrees, turn the pump off at 10 AM, etc. Events can be inserted into the queue in order by time and be popped off and processed at a later time. I also ... |
The following query returns the latest Odds for each Offer based on the timestamp on the Odds. However, the query takes an average of 1497ms - and I'm sincerely asking for help to optimize it.
SELECT DISTINCT ON ("odds_odds"."offer_id")
"odds_odds"."id", "odds_odds"."o1", "odds_odds"."o2", "odds_odds"."o3", "odds_o... |
Note: the next iteration at Natural merge sort - follow-up
I have compiled natural merge sort algorithm from Java to C++.
Natural merge sort sacrifices at most \$2N\$ amount of work in order to recognize the runs in the input range. A run is a contiguous subsequence which is ascending or strictly descending. Every desc... |
A contestant is said to be a winner if his number is strictly greater than the numbers to his left and his right and a contestant is said to be a loser if his number is strictly less than the numbers to his left and right so the contestant are on a circle and I should calculate the number of winners and losers.
Please ... |
I would like to speed up this piece of code. The macro gets a search variable from the worksheet "RAW_DATA_ARCHIVE" and then it should find it in the worksheet "RAW DATA". When it finds accordance then the value of column A from worksheet "RAW DATA" will be written in the last column of "RAW_DATA_ARCHIVE".
For i = 2 T... |
I am studying JavaEE and I have made my project for the learning experience.
I want to understand how best to write code from the point of view of architecture and use of relevant technologies. I am particularly interested to hear about the implementation of the REST-layer.
The purpose of this is the backend to the An... |
I'm looking for some feedback on my first program. It's a small game you play with matches.
It's a two-player game, where the players take turns picking matches (1, 2 or 3) and cannot pick the same number of matches as the other player: if player one picks 2 matches, player two will have to pick either 1 or 3 matches. ... |
I'm working on some code that has the following pattern of conditionals inside it. It doesn't look great, but it doesn't look terrible.
Please, shed some light on the underlying reason this is not passing my smell test. I'd love to see some alternatives. I'm guessing it's because it's completely ignoring a certain per... |
I'm beginning the long process of refractoring an Android app written entirely in SpaghettiJava™. I've been programming for a relatively short period of time (two years), and have tried refactoring the code base multiple times, but always get hung up on the wrong things and end up making very slow progress.
I've just f... |
I am trying to optimize the following switch statement, but I'm having a brain fart about how to do it. Here's the code:
$('.newsroom-tabs div.pane-content ul li').click(function(){
// get the class name of the clicked link
var className = $(this).attr('class');
// variable so that jQuery isn't traversing the DOM each ... |
I'm a beginner and just finished my first Tic Tac Toe program. I was looking to get some feedback on some of the portions that seem a bit repetitive. Is there a way to make this more dry vs. hard coding?
///////TicTacToe///////////
//////////BOARD ASSIGNMENT////////////
var a = "a";
var b = "b";
var c = "c";
var d = "... |
I am developing a simple macro that enables Python style 'with' in C++.
I have shamelessly prefixed the macro name with BOOST_ - primarily because there's a similarity to BOOST_FOREACH, and because I didn't want to call it plain WITH.
The motivation are familiar bugs like these:
void bug1() {
std::unique_lock<std::... |
I have a short snippet of code that simply computes a weighted average for surrounding elements in a square matrix. The actual implementation that I'm working on is not an average (more complex equation), but I am using this one to figure out how to handle various performance hinderances.
A few notes about my system:
... |
It's a simple version of LZW compression algorithm with 12 bit codes. I want to know what's good and what's bad about this code. Be as picky as you like.
// Compile with gcc 4.7.2 or later, using the following command line:
//
// g++ -std=c++0x lzw.c -o lzw
//
//LZW algorithm implemented using fixed 12 bit codes.
... |
This JavaScript object is part of a mobile application that rolls dice for our D&D games.
Here are some example of possible inputs from the user:
2d4
2d4 + 3d6
2d4 + 3d6 + 12
function DiceRoller() {
this.rollDices = function(input){
var parsedInput = input.split("+");
var totalScore = 0;
... |
This program is supposed to have 3 parts to it. 2 classes and 1 test program which I have created. My code for the program runs and works fine. However, I based my program off a different UML diagram. I had to go back and add more modules based on the UML diagram that my professor gave the class. My program still runs ... |
I've got a class called Movie and within this class I use an AsyncTask to get a Bitmap from a url passed in the constructor.
To store the image I use new DownloadImage().execute(url).get();. However I'm concerned about this blocking the UI Thread as now its a synchronous call. Is there another way I can go about saving... |
I've been working on this day and night and, since I'm a newbie, I can't seem to figure this out. I have a map with 27 states. Each, on click, show the highlighted state and an info box. Also, I have 27 links that, on click, do the same as the above. So, I wrote a huge code and got it to work fine, but I'd like to resu... |
I am trying to find a specific header string from different Maps (LEDES1998Bheaders, LEDES98BIheaders and LEDES98BI_V2headers) in an errorMessage depends on the parcel type and if the errorMessage has the specific header string I need to replace it with the corresponding value.
public class ErrorMessageConverter {
... |
I've been messing around with templates in C++14 and C++1z recently, and since I have somewhat of an obsession with optimization (and since my field of work relates to it) I decided to try to implement an optimized class for evaluating Chebychev polynomials of the first kind.
I eventually want to work this class into a... |
I have the following code to loop through a directory of folders and print all folders names with their paths in a worksheet. This is a follow up question to this one: Excel VBA - Get Folder Names
Looking for code optimization for faster and better performance.
Sub PrintFolders()
Dim wb As Workbook
Dim ws As W... |
The April 2015 Community Challenge requires building a calculator.
Implement a simple calculator
Where the definition of "simple" is whatever you make it - only
supports basic arithmetic operators? Fine. It supports scientific
notation, exponents and trigonometry? Fine! Takes input from the
console? Fine! Toggle... |
The previous iteration at Natural merge sort
Now my code relies on C++14 and looks like:
natural_merge_sort.h:
#ifndef NATURAL_MERGE_SORT_H
#define NATURAL_MERGE_SORT_H
#include <algorithm>
#include <iterator>
/*******************************************************************************
* Implements a simple, arra... |
Continuing working on Natural merge sort, I have parallelized it. Requires \$\Theta(N)\$ space and runs in $$\Omega(N + \frac{N}{P}) \cap \mathcal{O}(N + \frac{N}{P}\log_2\frac{N}{P})$$ time, where \$P\$ is the amount of cores available.
parallel_natural_merge_sort.h:
#ifndef NATURAL_MERGE_SORT_H
#define NATURAL_MERGE_... |
The following code will read a db, show the contents to the user and provide instruments to edit them. This has been tested and works well.
model.php
<?php
class Collega {
private $host="localhost";
private $user="root";
private $pwd="";
private $attiva=false;
public function connetti () {
... |
I am trying to solve a variant of the very popular question in which we find the number of distinct valid paths on a directed graph. The graph's nodes make up a m x n lattice (grid), and the edges only lead down and right. The goal is to find how many distinct paths start at the top left corner of and end in the bottom... |
I need to decode and encode TLV (Tag, Length, Value) data which is a composite part-whole tree structure.
Tag1 Len1 Tag2-Len2-Value2 Tag3-Len3-Value3 ... TagN-LenN-ValueN
------------------------Value1------------------------
Therefore, I've decided to use the Composite pattern for the TLV objects:
typed... |
From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside for-loops...
extension Array {
/// Removes all items that conform to the given closure
mutating func removeAll(cl... |
I am using the ruby sunspot gem to create a search users function on my site.
It works fine and the users controller for the index page where there is a search form is this
def index
if params[:search].nil?
@users = nil
else
@search = User.search do
fulltext params[:search]
end
@users = @search.results.p... |
I've recently read the books Clean Code and Effective Java.
I am a huge fan of Object-Oriented Java.
I am trying to write as professionally as possible. I have been an Android Developer for 20 months now.
Here is a class that I wrote that is supposed to communicate with Google Static Maps API. Is this code Clean, Effec... |
I'm using a doubly linked list container I've written as the working example. The textbook I'm using is from 2001, so feel free to point out where later versions of the C++ standard should be used instead.
Notes:
List::iterator functionality mimics pointer arithmetic.
Unlike most containers, list beginning is marked ... |
I'm developing a big (for me, as a beginner) terminal program "Brainfuck - The Game", in which you have to complete Brainfuck challenges. I would like your review on existing code (and project structuring) before I continue to expand it even more.
main.py
""" Brainfuck - the game. """
def main ():
""" The main fun... |
By N-by-N puzzles I mean f.e. a 3x3 sliding puzzle with one blank space (so a 8-puzzle) or a 4x4 sliding puzzle (so a 15-puzzle). When I try to solve certain puzzles some take no time but others take to much time to the point that I run out of memory. I think it's due to how I calculate the manhattan distance.
Below y... |
I am starting to play with POST request to save in my server the user token so I can send push notifications in Swift (this is the Swift code). This is the PHP file that processes the request (please note that I will improve it using prepare statements to prevent SQL injection):
<?php
error_reporting(E_ALL);
ini_set("... |
For several days I was messing around trying to create a markdown parser. This is the best I could come up without using regex. I was wondering if I'm on the right track.(I only covered the *,** case )
var str = "**f*";
function parser() {
var i;
var string = ' ';
for (i = 0; i < str.length; i++) {
... |
I want to save my users tokens id into my database using POST request in Swift (here PHP code here). I am a bit confused about synchronous and asynchronous request.
Is this code the right way to do it?
would the app crash if there is a connection problem while it is sending the synchronous request
shall I use an api... |
What are the issues/better ways to do this? I was just trying to implement this for practice and learn C++. Can anyone suggest efficient implementations of other functions such as count, size, all, none, etc?
#define NO_OF_BITS (8 * sizeof(unsigned int))
#include <iostream>
#include <assert.h>
template<ssize_t n>
cla... |
I need a second set of eyes to look at my twitter bootstrap 3 header. I would welcome some insight on the code structure and methodology as it relates to bootstrap best practices and efficiency.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edg... |
I needed to create a program which reads in a series of Excel files in folders typically structured something like this.
rootDir
Control
0hr.xls
24hr.xls
48hr.xls
72hr.xls
0.01um
0hr.xls
24hr.xls
48hr.xls
72hr.xls
0.1um
0hr.xls
24hr.xls
48hr.xls
7... |
I've been doing some self-imposed exercises to get accustomed to Python and below is my code.
import random
from random import randint
from random import randrange
from mainlist import legendaryitems
from mainlist import waystodie
from mainlist import powerup
from mainlist import mood
from mainlist import ponder
import... |
I am very interested in inventing the best way possible for rendering bitmaps on-screen using the base drawing functions (putpixel(x, y), lineto(x, y), moveto(x, y), setpen(r, g, b, transp, size) )
You don't need to use graphic library to have them. You can call BIOS interrupt or initialize registers manually to set t... |
I want to create an adjacency list based on data I get from a text file. Could I make this simpler?
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
struct Vertex;
struct Edges;
struct Edges
{
// edges link the vertex
Vertex * linkTo;
// pointer to vertex node
Edges * ne... |
I've made an interpreted language that's like Brainfuck except it has keywords instead of characters. Here's an explanation of the commands, and how to run it.
add_ostream - Add the ASCII value of the current cell to the output stream.
chg_size & [position]; - Change the current position on the stack.
reset_stack; - R... |
Someone asked me
We know that \$12^2 = 144\$ and that \$38^2 = 1444\$. Are there any other perfect squares in the form?
Here is my code:
public class OneFours {
public static void main(String args[]) {
final int power_of_ten = 8;
int num = 14;
for (int i = 0; i <= Math.pow(10, power_of_ten); i++) {
... |
Even though I have asked a question here related to my app using Swing and creating JPanel, I still have other ones about best practice making applications. I'm using Java 8.
I have this class screening which contains Film and Auditorium classes. At the moment the class looks like this:
Screening.java
package cinema.sc... |
There is nothing wrong, but is there a nicer way to re-write this program?
public IEnumerable<Employee> InsertEmployee(dynamic employees)
{
var newEmployeeRecord = new List<Employee>();
foreach (dynamic employee in employees)
{
newEmployeeRecord.Add(
... |
This MVC4 controller method, which uses EF6, is taking a long time to run (over 2 seconds). I've added verbose comments for the purpose of this post only.
public async Task<ActionResult> Index()
{
// Get a list of all the classes I teach.
var myClasses = await CurrentUser.GetClassesAsync(db);
// Get a list of al... |
I have written an attendance calculator that compares a set of rules against an employee's attendance record and determines what level of progressive discipline that employee is at (how much trouble they are in).
Information:
The rules are provided as a JSON object whose information comes from inputs on the page
The ... |
My code first creates a Point object. Then it creates a 25 x 25 array of ASCII in a string where _ marks a miss and the point's symbol (in this case "X") marks a hit. Then, the user can move the point with the arrow keys and it rerenders.
This code is probably really badly written and terrible, but it works. I need som... |
I have written some code for inserting a label at runtime that has its content set to a string array into a datagrid row. All of this will initiate when certain radio buttons are checked. The code is working perfectly fine, but I need to improve this code as I am learning C#, WPF and datagrid. I know there can be a cer... |
The author of my book does not release odd-numbered solutions to students, so I can't check my solutions. I was wondering if there was a better way to solve this problem without simply printing out the square roots.
Here is the question:
(Game: locker puzzle) A school has 100 lockers and 100 students. All
lockers ar... |
I have created the following function in Swift for this library I am writing, which joins two arrays on a key (extracted using given closures), and then groups them by key in a [T:[S]] where S is the result type (also through a given closure).
extension Array {
/// Joins the array with another array on a specific k... |
Where I work, we have 3 forms for leavers: HR, IT and rota. Lots of questions are duplicated across all 3 forms.
So I thought, why not fill ONE form out, remove all duplicate questions, and simply split out the answers into formats that match original forms? I combined the form questions, then wrote a script to get th... |
For a small administrative program, I have to be able to register people and their data. But, files are sometimes created through a phone call "on the fly" and then later certain data is added to the file to complete it.
For this reason I started making my Person class with different constructors and I was chaining the... |
This is a simple Rock - Paper - Scissor game. I'm trying to find a better way to write the algorithm and keeping the scoreboard.
#!/usr/bin/python
#
import random
import os
import json
import pprint
#-------------------------------------------------#
def main():
user, sys = 0, 0
name = os.getlogin()
while T... |
This isn't meant as a scheduler for just any job. The job that I need to schedule here is very specific for an application I'm writing for one of my clients.
The scheduler will run as a console application because it's comparatively lightweight. The application will be started with Windows (startup items in the Registr... |
I have this code that duplicates a byte array 5 times.
class Multiple {
public static void main(String[] args) {
byte[] result = new byte[] {0x41,0x42,0x43,0x44};
int len = result.length;
byte[] multipled = new byte[len*5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j... |
I whipped a reasonably fast brute-force perfect number finding function in Haskell, after seeing a similar thing in mathematica.
It works in under 3 seconds when I search up to 1000, but 10000 is too much.
isDivisor :: Integral a => a -> a -> Bool
isDivisor n a = mod n a == 0
sumDivisors :: Integral a => a -> a
sumDiv... |
I would like to know whether I applied the SOLID principle and the repository pattern the right way.
My code should derive exchange rates from a database and do basic currency conversions.
The database table is very easy. I assume I have a base currency and all exchange rates are against the base currency. So the datab... |
I have some experience with OOP but I'm very new to game programming. For a school assignment, here's my first attempt at making a "real" game containing Entities, a game engine, game loop and the likes. I wanted to know if I used those concepts correctly, and would love to have some tips on things I could've done bet... |
I am using a simple page with 2 pullout functions, one on the left and one on the right side. I would like to simplify or combine the two functions into one and make one pullout close, when I click on the other one, so that only one can be seen at a time.
Here is a Fiddle: http://jsfiddle.net/schakalwal/gwu2gob3/
JavaS... |
based on this answer I modified my code. Is this the correct approach now?
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
var userId = "001" //I just use it as USER number 1
let token = deviceToken.hexString()
var postBody = NS... |
I have two xml files, about 500mb each, an old and a new. I want to find out what items have been added or removed in the new.xml compared with the old.xml.
I had some help on this code and I'm a bit new to C++ but I was wondering if this is the optimal way to approach a problem such as this.
#include <set>
#include <s... |
I require hundreds of equal, small sized buffers in my current project. The bulk of the computation in the program operates on data stored directly in those containers, so high performance is imperative. As the number of the buffers stays constant at runtime, my current approach is to use a std::vector<std::deque<MyObj... |
I am going through the Java CodingBat exercises. Here is the one I have just completed:
Given a string, return the sum of the digits 0-9 that appear in the string, ignoring all other characters. Return 0 if there are no digits in the string.
Here is my code:
public int sumDigits(String str) {
StringBuilder strAp... |
I have this piece of code in my Node.js API and I feel like it could (should) be optimized.
var apiRouter = express.Router();
apiRouter.route('/user/:username')
.put(function(req, res) {
User.findOne({
username: req.params.username
}).exec(function(err, user) {
if (err) {
res.send(err);
... |
Given two arrays of elements:
aaabbccdefaa
zzzccddafgzz
I want to check whether these two arrays are equivalent up to a relabeling.
My strategy is to map them into a canonical form and then check whether they share the same canonical form:
# Convert aaabbccdefaa -> 000112234500
canonical <- function(input){
output ... |
(Game: locker puzzle) A school has 100 lockers and 100 students. All
lockers are closed on the first day of school. As the students enter,
the first student, denoted S1, opens every locker. Then the second
student, S2, begins with the second locker, denoted L2, and closes
every other locker. Student S3 begins ... |
I am going through the Java CodingBat exercises. Here is the one I have just completed:
Given a string, return the longest substring that appears at both the beginning and end of the string without overlapping. For example, sameEnds("abXab") is "ab".]
Here is my code:
public String sameEnds(String string) {
int ... |
Using Python's Beautiful Soup, I analyze a number of html files (internally: soup). They are all a little different and my target comes in four different tags - or not at all. In two cases, my target may not be there but the tags may exists. In this case I find a ↵ .
Here I got a very ugly code to check for them:
#1: i... |
I'm refactoring an old gateway and came across the following method:
def apply_limit_and_offset(options)
limit = options[:limit]
offset = options[:offset]
@result = if offset
@result.drop offset
else
@result
end
@result = if limit
@result.first limit
else
@result
end
@result
end
@... |
I'm solving exercise 3 from lecture 3 of Berkeley's CS 61A (2012):
Fill in the definition of map_tuple. map_tuple takes in a function and a tuple as arguments and applies the function to each element of the tuple.
def map_tuple(func, tup):
"""Applies func to each element of tup and returns a new tuple.
>>> a =... |
I did the exercise below to practice. Can someone help me to shorten or improve the code in a simple way for a beginner?
The exercise is:
Given 2 int values, return whichever value is nearest to the value 10,
or return 0 in the event of a tie.
public int Closer(int a, int b)
{
Console.WriteLine(Closer(8, 1... |
I listen on a port via multi thread async socket. That port receives requests over XDomainRequest. I received the complete data each time till now but I don't trust this code because it may not work in some cases. (network traffic etc.)
Here is my StateObject:
public class StateObject
{
public Socket workSocket = ... |
This is supposed to get a single value from the DB.
What should I consider next? How can I upgrade it?
public static String GetConnectionString()
{
return ConfigurationManager.ConnectionStrings["xxx"].ConnectionString;
}
public static String GetProviderName()
{
r... |
I don't think I am using the MVC concept in Ruby on Rails properly. Model accesses db, controller works on logic and view displays information/data. But in my code, my Model code is empty. Can anyone please help in analyzing on how I can use MVC correctly?
Model:
class Product < ActiveRecord::Base
end
Controller:
clas... |
I am going through the CodingBat exercises for Java. Here is the task I have just completed:
Given a string, return the sum of the numbers appearing in the string, ignoring all other characters. A number is a series of 1 or more digit chars in a row.
And here is my code:
public int sumNumbers(String str){
int tot... |
Please review my Adjacency Matrix class based on this code.
Since I use std::vector to create the matrix, I would like to store as many nodes as possible. Is it OK to use std::size_t all over the code?
Are using 1 for connected and 0 for not connected a bad idea?
class AdjMatrix {
public:
AdjMatrix(const std::si... |
I'm working on something for my school's laptops that will disable videos/games between 8:00 AM and 3:15 PM. Due to the giant time gap, I will not be waiting to see if the code functions properly or not. What I want to know is if my code will function properly, as I'm not good enough at JavaScript to know myself.
funct... |
I would like to greatly reduce verbosity of following code fragment.
What I'd like to do:
Reduce number of occurrences of MaterialRangedParam<Value> and MaterialParam<Value>. C++ has typedef. C# doesn't. Is there keyword for own type of a class?
Remove operator !=, operator ==, GetHashCode and Equals and make compiler... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.