instruction stringlengths 71 71.9k |
|---|
I'm writing a myVector class for a class I'm taking. I don't believe I'm "strong" with smart pointers right now, so that's my question. This is just an excerpt from a much larger class that I've completed.
Is there a way to use the shared pointer and dynamically allocate the size, so that I can use the [] notation wi... |
I'm using Automapper to do some mapping from XSD-generated serialization object to more sane POCO's.
I'm having an issue with a particular type of mapping.
public class SourceOuterObject
{
public SourceSet SourceSet { get; set; }
}
public class SourceSet
{
public List<SourceObject> SourceList{ get; set; }
}
I wa... |
My project uses Zend Framework 2.
I'm trying to determine if I am doing too much in my controller as a rule for my development. I have built my controllers like this for a while and haven't run into many problems but I wanted to get some feedback from this community.
This specific action handles a video management for... |
This is a working Neighbours method. Is there any way to make this simpler and concise?
public int Neighbours(int xCoordinate, int yCoordinate)
{
xCoordinate = xCoordinate -1;
yCoordinate = yCoordinate -1;
int NeighbourCounter =0;
int incrementer = 0;
... |
I'm writing C++ for the first time and wanted to implement a BST. I come from writing C, so I tend to write code in that way. I'm trying to wrap my head around smart pointers, but can't seem to get them to work properly. This version of the code is without any smart pointers. Any suggestions?
The C++ file:
#include <io... |
I'm dealing with a damn scary function which I would wish to refactor so I could unit test it properly and improve the design. I will try to explain what it does and how it works in detail (with comments in the code) and with approaches I've been considering to tackle the issues:
public Result RegisterJustCustomerConta... |
I have a bunch of .csv files which I have to read and look for data. The .csv file is of the format:
A row of data I will ignore
State,County,City
WA,king,seattle
WA,pierce,tacoma
In every csv file, the order of columns is not consistent. For example in csv1 the order can be State,County,City, in csv2 it can be City... |
This basically manages a set of snippets, saving and loading it.
snippets.cpp
#include "Features/snippets.h"
#include <iostream>
Snippets::Snippets(QObject* parent)
: QObject(parent)
, m_Snippets(nullptr)
{
bool success;
LoadSnippets(success);
}
void Snippets::LoadSnippets(bool& success)
{
success... |
I just picked up C++ today and I wonder if this is c++-like. I have a bit of experience with Java.
This is a program that takes a number as input and outputs its prime factorization in no particular order.
Specific questions:
Am I using std::vector correctly? With all the insert, maybe there is a better way? Similarly... |
I'm creating a program to determine whether or not a given year is a leap year. I just wanted to get anyone's feedback on it. I am aware of the calendar module in Python. I just wanted to try it from scratch.
year=int(raw_input("Input year:"))
if (year%4==0 and year%100==0 and year%400==0)or (year%4==0 and year%100 !=... |
The problem statement
Summary:
The rules of a lottery are defined by two integers (choices and blanks) and two boolean variables (sorted and unique). choices represents the highest valid number that you may use on your lottery ticket, blanks represents the number of spots on your ticket where numbers can be written. E... |
In my app I have a BaseCtrl, which is attached to the body element and is available everywhere.
In the mentioned controller I have the following code for opening modal:
$scope.addFolder = function($event) {
$event.preventDefault();
// Opens an add folder modal
var modal = ModalService.custo... |
I wrote super redundant VBA code and it works and solve my problem. I am trying to simplify it but don't know where to start due to my limited knowledge in VBA.
Basically, this code works as a vlookup function and return all required data from other sheets in the same workbook. I have multiple columns to be filled so I... |
I'm making my first steps in Java EE. This is a simple guestbook made using Java EE 7 technologies (JSF, CDI, EJB, JPA).
Does the code follows the standard best practices? Is there a possibility for improvement?
Guestbook entry entity
package learning.guestbook2;
import java.io.Serializable;
import java.time.OffsetDa... |
I'm a beginner in jQuery and am wondering how I could write the following code shorter, since I'm repeating a lot.
Working example
//-----------Fullscreen overlay menu click events -----//
$('#overlay-menu').bind("click", function() {
$(".overlay").addClass('overlay-open');
$("#overlay-menu").fadeOut(800);
}... |
I have made a Point2D.Double wrapper so I can add my own functionality (like a dominate method) and alter some (like toString) and control some (like not having public access to x and y).
Point class:
public class Point implements Serializable {
private final Point2D.Double point2D;
public Point(double x, dou... |
I wrote some code that resizes an image to fit in a given box. I think that some parts of the code are not needed (for example if it's a box image). Is there a more efficient way to do this? Is there something wrong with my code (from the results it looks ok)? Is there a "shorter" version to do this?
Bitmap original, r... |
I am creating a zoo. In my zoo I want to have 3 types of animal: Mammal, Bird and Fish. I want to keep them in cages.
My implementation of animals is (classes for Mammal and Fish looks almost the same as Bird, only TypeEnum is different):
public class Bird implements Animal {
private AnimalDetails animalDet... |
This is the batch file I have created which zips the particular month logs and deletes those logs from the source folder after successful zipping. If it does not find the zip file, then it again starts to zip the logs.
Please suggest any changes to be done.
@echo off
set zip="C:\Program Files\7-Zip\7z.exe"
rem Findout... |
I want to compute, as quickly as possible,
$$ \dfrac{(x+y)!}{x!y!} \mod m $$
with \$x,y \le 10^6\$ and a prime \$m=10^9+7\$ (called mod in my code).
My current approach, computing
$$ \left(\mathtt{Prod}(y+1, y+x) \mod m\right) \cdot \left(\mathtt{InverseMod}(\mathtt{factMod}(x) \mod m)\right) $$
is too slow. Here is t... |
Previous question:
Tic-Tac-Toe in C++11 - follow-up
Is there any way to improve this code?
#include <iostream>
#include <cctype>
#include <algorithm>
#include <functional>
#include <array>
enum struct Player : char
{
none = '-',
first = 'X',
second = 'O'
};
std::ostream& operator<<(std::ostream& os,... |
I am making an application in which the user has the ability to add, remove, and edit JSON data through DOM interaction. I have created a working JavaScript-only prototype that accepts certain variables to manipulate certain elements of the JSON data, although it is rather messy and seems rather impossible for me to im... |
I just started learning Java, and wrote up a linked list. I'm coming from just having learned Haskell, so I've been out of the mindset of stateful computations for awhile.
I'd like to know how it could be improved in any way. Please be critical. Mainly though, I'd like suggestions on readability, and safe practices.
It... |
I'm trying to condense some of my code to make it more maintainable and to learn a few new tricks.
Below is a Python 2.7 / Django 1.6 function which is designed to assign users to one of three surveys in my application. I require a total of 30 responses in total, 10 each. Each user is to be assigned at random to one of... |
I have a class Edge which looks something like this:
class Edge {
Edge previous;
Edge Next;
}
I have edges in an ArrayList. They have to form a loop, as in the last one is connected to the first one.
This is what I have:
Edge previous, current, next;
previous = edges.get(edges.size()-1);
for (i... |
Below are the get_context_data method and the done method of a SesionWizardView. A SessionWizardView is designed to split a form over multiple pages. The get_context_data method is used to provide updated 'context' data to the individual form pages, in this case images selected from a list at random.
Python 2.7.3 | Dj... |
In this specific situation there is a table with trackdata and a form to add rows. For the sake of clarity I won't include the view-related code here. The added rows are added to a LinkedList when appropriate.
public class TrackDAO {
private List<Track> tracks;
private Connection con;
public TrackDAO() {
tracks =... |
I have a program which is supposed to convert standard time to traditional time. (e.g: 15:24:31 = 3:25PM [rounded seconds])
I would like for someone to error check my code for me as well as give me ideas on how to condense it.
I'm not sure if I'm allowed to post a program here because of safety issues but here is the e... |
iteritems on a dict can useful.
Occasionally iteritems is useful for a slice of a list and this effect can be (crudely) implemented as follows:
class List(list):
def iteritems(self, slice=None):
if slice is None: return enumerate(self)
else: return itertools.izip(range(*slice.indices(len(self))), self[slice])... |
This class is helping to manipulate by output streams stderr, stdout, and file. Are there any cons and errors in this code?
class OutSplitter(object):
""" splitter """
def __init__(self, out_splitter):
self.__pipes=None
if isinstance(out_splitter, OutSplitter):
self.__pipes = Set(out_splitter.pipes... |
I like the pattern of the jQuery Deferred object.
I like how you can call Resolve any number of times, but the listening objects will only be notified once. I also like how you can attach a listening object after Resolve has already been called, and the listening object will still get the notification. If you're progra... |
I'm actually building some kind of framework to promote code reuse without over-reusing it. Besides, sometimes as it occurs with generic types, one expects type parameters to be constrained for the purpose.
In MVP, those constraints translate well enough.
Presenter
public abstract class Presenter<V, M> where V : IView<... |
I have a Factory Girl factory that needs to generate a unique name using Faker. Unfortunately, Factory Girl generates duplicates relatively frequently, which causes intermittent test errors. I previously added a random integer after the Faker name, but I am now checking the database to make sure that a potential name f... |
I have this huge chunk of code. Is there any better to write this code, or am I too paranoid that I check every MongoDB query for error?
The logic is here:
Bookcollection = collection of books
Book = book info
Query book collection of the user, if found find the book info for each of the user book collection
Create a ... |
I'm writing code to do line printing to a template -- counting characters to box A, then to box B, etc. -- and as such, it's not very modular. There are a lot of (long) variable names and each statement, which adds to the string to be printed, is pretty long.
So I've been breaking up the statements across multiple line... |
I'm new to Python and I just wrote my first program with OOP. The program works just fine and gives me what I want. Is the code clear? Can you review the style or anything else?
import numpy as np
import time, os, sys
import datetime as dt
class TemplateGenerator(object):
"""This is a general class to generate all of ... |
We were asked to implement a program that calculates the number of Fermat witnesses and liars for odd numbers greater 1. This involves Fermat’s little theorem.
Fermat’s little is used to identify whether a possible prime number is composite. It’ll find a number/numbers called Fermat witness then. The other numbers are ... |
I am attempting to speed up the processing of 5000 rows received from the database, which I then render as a crystal report, export to a byte stream and save in a database table.
Currently I am using parallel.ForEach on a datatable. This uses 40 parallel processes that then sequentially iterates 125 (i.e 5000/40) recor... |
I have wrote the following algorithm to print out the Nth twin prime numbers:
def isprime(x):
for i in range(2, (x + 2) / 2):
if x % i == 0:
return False
return True
inputIndex = int(raw_input())
tempIndex = 1
n=2
while True:
if isprime(n) & isprime(n + 2):
if inputIndex... |
I have a data access layer method to cancel an order. This operation should have an associated "operation history" entry.
My first (naïve) implementation looks like this:
public void CancelOrder(int orderMastId, string reason)
{
string order_id = orderMastId.ToString();
var order = this.db.Commandes.Where(c => ... |
I recently developed an interest in AI and thought I would develop this little chat bot. Are there any recommendations/modifications?
import java.io.*;
import java.util.*;
import java.lang.*;
public class Conversate{
private static String name;
public Conversate(String name){
this.name=name;
}
... |
I have made a Skyline query solver which for now can solve the query with two different algorithms.
The first is Block-nested loop (BNL) and the second is Sort filter skyline (SFS). The two are extremely similar. I will explain the basic things that are needed to review the part I am interested in so I won't bore you w... |
I've written a lightweight (I think) class that acts as a messenger service between classes for both notifications (fire and forget updates to other classes) and requests (a notification sent out that expects a returned value).
I'm looking for a general review here on style, usability, best practices, etc.
Here's the c... |
From pretty much any book I've read it always said to code on interfaces/superclasses and rarely on implementations, today though that advice made a bit confused about how I should format my code.
Questions:
Should I be using Point2DAdvanced or Point2D.Double in the the methods of MedianPoint (like JavaRDD<>, the 2 pr... |
This code is written in a SSIS Script Component that basically accomplishes what I previously had as a T-SQL script, that was reviewed here.
I need to split a 80 character string that contains 20 buckets of 4 characters each, without any delimiter, and generate a new row for each bucket. I'm using a script component to... |
I'm looking at my code and it doesn't look very efficient. I'm simply trying to catch exceptions or prevent them from being thrown in the first place. Can you please take a look and tell me if there is a way to make my working code more efficient?
public static void GetMoveCoordinates(ref int XCoordinate, ref int YCoor... |
In a bigger project of mine I'm using angular to create a dropdown menu dynamically and then toggling a dropdown menu for some of the menu items. This is why I got a function that toggles the dropdown menus for only the items that should actually have one. However, I feel like I should try to DRY this out a bit since I... |
I wrote this function in scala that uses tail recursion to remove nested blocks from a text.
Usage examples:
removeBlocks("123{456}789", "{", "}") yields "123789"
removeBlocks("123{a{b{c}b}a}789", "{", "}") yields "123789"
removeBlocks("123<div>456</div>789", "<div>", "</... |
I have written a program in Python 3x to determine all the prime, palindrome string integers in the range of two given numbers.
from math import sqrt
def check_prime(n):
if n<2:
return False
for i in range(2,int(sqrt(n))+1):
if n%i == 0:
return False
else:
return True
f... |
Reads from a flat file of three columns, delimited by at least one tab character. Filters the three columns based on input; returns list of corresponding emails. Arguments passed like key=value or key= for blank.
#!/bin/perl
use warnings;
use strict;
sub get_list {
my $cols = {'list'=>0, 'email'=>1, 'sub... |
My programming skill has gotten rusty, so I would like to elicit constructive criticism that can make me write code better. I know the standard design is to use templates, and even obtain the hash function, allocator, etc through it, but I wanted to experiment with patterns, so I'm pretty sure my design here blows. but... |
I'm building a hybrid sort, and for that I need a fast and adaptive sort ideal for small sizes (< 65 elements).
Insertion sort immediately comes to mind, and I've been tinkering with different implementations of it. My requirement is that it takes in iterators as per C++ standard.
Linear insertion sort
template <typena... |
I'm currently trying to create a travel blog using Django whereby users will be able to create a travel plan with the following features:
Each user can create a travel event based on the start date and end date for specific locations, with some meaningful description
He/She can also upload images for associated with s... |
quux (['0'..9'] ++ ['A'..F']) 2 generates hexademical numbers of length 2 (with leading zeros), but it's obviously possible to generate any base and any length.
quux digits length = iterate foo return !! length $ [] where
foo bb aa = map (: aa) digits >>= bb
Can this code be simplified, while retaining the idea ... |
I wrote this program to just get some practice in C, but I have a question:
Do you see anything that I am doing that will create bad habits in my future programming?
#include <stdio.h>
char password[]="ps"; // set the password that user must match
char input[20]; // user input buffer
char filename[32];
FIL... |
The code I have wrote works fine, this inquiry being purely for educational purposes. I want to know how others would do this better and cleaner. I especially hate the way I add the list items to another list before they are joined. There has to be a more efficient way.
I realize an easy way to make this simple would b... |
Previous question:
Tic-Tac-Toe in C++11 - follow-up 2
Here, AI is being implemented.
#include <iostream>
#include <cctype>
#include <algorithm>
#include <functional>
#include <array>
#include <ctime>
template <typename T>
T getRandom(T min, T max)
{
return (rand() % (max + 1 - min) + min);
}
enum struct Player : ... |
I have to run a script against 40 million objects in my database:
I wrote the script and I want 10 instance of it so I process my objects faster.
The goal is to find all the neighborhood for each property.
A little bit of context: Multiple properties can have the same
lat/lon.
A Location is a city.
I stored all th... |
I have a server communicating over network interface. This server should run on a background thread, so that it does not block the ui thread. The ui thread starts and stops the server. Even starting and stopping should be done from a background thread.
Currently I wrap all public methods of the server class in a thread... |
Doing IO in Java is a big pain. It got better with Guava and Java 7 and now about everything is there, but I never know exactly where.
Most of the time I need to slurp a file. Nearly as often I need to write a file, while making sure, I don't end up with some garbage in case of an IO error (atomicity). Leaving .tmp fil... |
My implementation works, but it looks very ugly. Curious to see how it's better implemented.
The zipWith function takes a list of lists (List[List[A]]), or a row with columns if you like. It will then transform this into a column with rows and applies a function List[A]=>B to obtain a List[B]. Hopefully the unit test b... |
So the idea is to read metadata recursively in a chosen directory, load their metadata and display it into a table.
Here is the simplified example of what I am doing.
public class AudioMetadataExtractorTest {
public static void main(String[] args) {
String audioFiles = "C:\\Music";
File dir = new F... |
Which approach is better and why?
First approach (inner class for wrapping):
public class OOP {
private SomeService someService;
private final class OrganizationPrimaryKeyString implements Serializable {
private static final long serialVersionUID = -256615521081939636L;
private final String pkS... |
I am making an application to save a layout of user control into an .xps document. But, the export doesn't seem completed if the data is too many. I've tried to encapsulate each part with DispatcherPriority.Loaded but it seems the data binding is horrifyingly take too long to be finished (I honestly don't know what is ... |
I am developing a plugin for a system, the plugin catches some events in that system, wraps them and pushes out to another system for analysis. The overhead generated by the plugin must be as low as possible, because the main system will be blocked until the plugin finishes work. So what I have so far is that I catch t... |
I have written a jQuery function which accepts an elementId and an integer. The function then generates a counter which increments at the average speed of searches made (per month) since you initialised the function.
The elementId is where the counter is placed on the page.
The integer is the number of monthly searc... |
The following is my second attempt at a basic CSV parser in Ruby. I've addressed suggestions that I've got for my previous version here.
I have omitted all test cases - the code listing would be too long otherwise. You can look at the full code-base at GitHub if you want to.
As opposed to the last version, the current ... |
I have written a typetoken library in C++11 and I want to know if it is indeed typesafe, threadsafe and complete.
The purpose of this library is to give an unique ID to every requested typename during runtime.
The code I used is the following:
/*
* typetoken.hpp
* Created on: 27.11.2014
* Author: WorldSEnder
... |
I wrote the following code for the question I asked here. Are there any catastrophic mistakes? (actually it did not really work with perltex and I am in doubt about having syntax mistake(s))
Also, I read it about lists, hashs (still list vs hash is a huge question mark in my mind) and forearch to improve my script. I a... |
I'm working on a Virtual Texturing library for mobile devices based on OpenGL-ES.
This is the PageIndirectionTable, one of the library components I would like to have some feedback on:
vt_page_indirection_table.hpp:
#ifndef VTLIB_VT_PAGE_INDIRECTION_TABLE_HPP
#define VTLIB_VT_PAGE_INDIRECTION_TABLE_HPP
namespace vt
{
... |
I have written a function which takes the year in question and words as a data which is a dictionary that maps words to the list of year/count. Now I am wondering how I can improve the code that I have or how to make it more simpler or make it better performance-wise.
def avgWordLen(year, words):
totLen = 0
tot... |
I'm currently studying C and I'm trying to just print the contents of a string array. I'm using pNames to point to the first char pointer and iterating from there.
A more proper approach would use this pointer, get a char* each time and use printf("%s", pNames[i]) to print a whole string. However, I thought I would try... |
A friend of mine recently started learning R, and she complained to me that R is very slow. She was working on Project Euler Problem 7, which asks for the value of the 10001st prime number. For comparison, I decided to write the exact same program in C++ (which I use most frequently), R (which I do not use regularly, b... |
Previous question:
Tic-Tac-Toe in C++11 - follow-up 3
I've been told to use <random>. However, it seems a bit more complicated than it looks to generate random numbers. I have implemented it but I'm not quite sure whether I implemented it correctly or not.
What's the best practice for using <random> in this code partic... |
Earlier this academic year I had an assignment to take a project I had written outside the context of University and apply a number of refactorings to it.
I chose a program I had written a while ago that saves periodic 24-bit lossless bitmap screenshots of a user-specified target window.
BMPTimer Class:
// Header for B... |
I am currently learning C++, using this book: C++ Primer, 5th Edition. I made this program to help me understand the usage of vectors in C++. I have prior programming experience (mainly Python), and this just seems way too messy to be the right way of doing things. If I'm doing this incorrectly, or inefficiently, then ... |
I am currently working on Shopify webhooks which posts XML to the Colorado timber line API. But due to the order protocol of the Colorado timber line API, it is required to modify the XML posted by Shopify webhook to be restuctured.
Here's how I did the restucturing:
$doc = new DOMDocument;
$doc->load('timber.xml');
$... |
I have 2 Truncate string methods.
First:
public static string Truncate(string source, int length)
{
if (source.Length > length)
{
source = source.Substring(0, length);
}
return source;
}
Second:
public static string Truncate2(string source, int length)
{
return source.PadRight(l... |
I have a html form with some text input fields and three file upload fields. two of them should be images and one should be a file (pdf). My code is working well but I feel this is not the proper OO way to do this I feel I am repeating my self. So if someone can guide me through a proper way It will be a big help.
Th... |
I'm a Python beginner (more used to code in R) and I'd like to optimize a function.
2 arrays ares filled by integers from 0 to 100. A number can't appear twice in a row and they're stored in an ascending order.
Array1: nrow = 100 000; ncol = 5
Array2: nrow = 50 000; ncol = 5
For each row of Array1 and each row of A... |
I've been playing with an idea for simplifying management of event listeners on custom Swing components.
Swing provides the EventListenerList class for maintaining events, and every JComponent has a protected EventListenerList listenerList = new EventListenerList(); available for use by subclasses.
The thing is, I thin... |
Is there any way to write is C function better so the procedure could spend less time to calculate the results?
Assume that the array size is 1.000.000 and all the numbers are greater than 0.
The function read the array backwards, saves the first number to maximum, then check the next number, a, and if it's greater th... |
I'm doing an easy problem in codechef. Here's the problem statement for maxcount:
Given an array A of length N, your task is to find the element which
repeats in A maximum number of times as well as the corresponding
count. In case of ties, choose the smaller element first.
OK, I cheated. I used std:map because I... |
I am implementing a multi-phase collision detection system whose final collision check is checking the triangles of one shape against those of another. As the number of triangle-triangle comparisons can get high I have implemented the spatial hash described at Optimized Spatial Hashing For Collision Detection of Deform... |
I have decided to code an IDE for C using Python with Tkinter. I tried to use my best functional style and keep functions small. This programme works perfectly in Linux with Python 2.7, but it should be compatible with both Windows and Python 3.x.
# -*- coding: utf-8 -*-
import sys
from subprocess import Popen, PIPE, S... |
I'm using jQueryUI's Autocomplete widget for a product search. The data is in a database, so as the souce I passed it an AJAX request. My problem is, that I need some data about the currently focused option, so in the autocomplete's focus method, I'm calling another AJAX request to the same PHP file, to get some other ... |
I am trying to implement producer/consumer pattern with multiple or parallel consumers.
I did an implementation but I would like to know how good it is. Can somebody do better? Can any of you spot any errors?
Unfortunately I can not use TPL dataflow, because we are at the end of our project and to put in an extra libra... |
I want a 4-bit resource to share status between processes and to retain status after shutdown and reboot. If the system were a microprocessor, I'd use a 4-bit register in non-volatile memory.
Process interaction with the shared resource is typically minutes to hours between interactions, however processes may attempt ... |
I am implementing the spatial hashing algorithm described in Optimized Spatial Hashing for Collision Detection of Deformable Objects with a few adjustments, the largest one being that each bucket in the hash table stores an array of pointers to a linked list of Triangles. Each of the elements in the array has a pointer... |
I'm trying to implement Dijkstra's algorithm to find the shortest path from a starting node to the last node of a 250px by 200px raw image file (e.g. starting node = [0][0], ending node = [250][200]). The raw file acts like a topographical map in that each byte represents an elevation and the distance cost from one nod... |
First time writing C in a long time and would like some code review to try and improve my code. I have some specific questions, but first an introduction to the code.
The application is a simple command line application for converting markdown to pdf.
The source code can be found in the repository on Github.
The main l... |
Any time that a row ID (oddly placed in column 8, i.e. row[7]) is repeated after the first instance, I want to write those rows into a second file. The code I'm using is extremely slow -- it's a 40-column CSV with about a million rows. This is what I have:
def in_out_gorbsplit(inf, outf1, outf2):
outf1 = csv.writ... |
Our Rubberduck open-source VBE add-in project is coming along nicely. One of the main features we're going to be implementing in the next release, is code inspections.
I started by defining an abstraction:
namespace Rubberduck.Inspections
{
[ComVisible(false)]
public enum CodeInspectionSeverity
{
D... |
I'm a first traveler coding in WinApi, Hooks, COM objects. Then, I made a dll to inject (EasyHook) this in the target SIEMENS Step7 process and modify the software code at runtime:
Maybe I want some opinion about this kind of practices, hooking, injection, file system driver, kernel hook, modify .exe vtable before init... |
This question is for Laravel 4 only, as the relevant parts are completely refactored in the upcoming Laravel 5.
I have written an helper function for validation, so I only have to put this in controllers:
public function postAdd()
{
validate([
'foo' => 'required',
'bar' => 'required',
]);
/... |
I wanted to step up my JS game, and move on from mostly closure based scripting, so I decided to write an application in node. I don't have much experience with prototype based programming, and I guess it's a little too early for ES6 (well, maybe with traceur).
During planning of my app I saw that often I'll need conta... |
Here's the problem statement for Minimum Scalar Product
You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnyn.
Suppose you are allowed to permute the coordinates of each vector as you wish. Choose two permutations s... |
I need to write a program which will find a prime number, greater than the given n.
Can it be done simpler?
#include <stdio.h>
int isPrime(int n)
{
int i,j=0;
for(i=1; i<=n; i++)
{
if(n%i == 0)
j++;
}
if(j == 2)
return 1;
else if(j > 2)
return 0;
}
int fun(u... |
I wrote this program, to determine if any given number is happy, and would like to know of any improvements that can be made to make it better. I have tested it, but whether or not it works perfectly I have no idea, there might be some numbers that get through, although I doubt it.
import java.util.HashSet;
import java... |
Theme of my course work in institute is simulation of bus route. Could you determine any faults and defects in this code? I will be very grateful if you give me some advice about one global variable, counters or etc. It's a console version. I have one month to do GUI with help of Qt or Visual C++. I don't use either th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.