instruction stringlengths 71 71.9k |
|---|
For this project I'm targeting .NET 4.6 with Prism 6 as a toolkit to implement correct MVVM patterns.
The code below allows me to raise a dialog box with Yes, No, Cancel buttons. If the user clicks 'Yes' the content is saved then the tab item closed. If 'No' the tab item is only closed, and if 'Cancelled' then return, ... |
I would like to know how I can improve this CakePHP 3.0 Component (inside folder controller)
1st: to use external libs (stored on vendor folder) I'm using the require keyword and include the class using use keyword, like this:
require_once(ROOT . DS . 'vendor' . DS . 'CakePHP-ImageTool-Component' . DS . 'ImageTool.php... |
As part of a school project for ICT lessons, our class has been required to write a quiz program following certain criteria that has been set. The first part of this is a program that handles the registration process by asking the user for details such as player name, age, email and gender.
import getpass
import os
imp... |
One of the URL in my application is vulnerable to XSS attack, so I am handling it in the below way.
I created a util class:
import java.util.regex.Pattern;
public class HtmlUtils {
public final static String tagStart = "\\<\\w+((\\s+\\w+(\\s*\\=\\s*(?:\".*?\"|'.*?'|[^'\"\\>\\s]+))?)+\\s*|\\s*)\\>";
public fin... |
I have some questions on how I can improve this "action" (method) in "controller":
My template has a navbar with dynamic content (if the user is logged in a special button appears, his name appears in the navbar among other custumizações) also the integration of modes is dynamic based on whether the user is logged in ... |
This is my implementation of the bell() function to calculate the n-th bell number in C.
Along with it I made the factorial() and binomial() functions.
I have serious doubts about their efficiency, in particular whether my implementation of the factorial() function should be correctly optimized for tail-recursion, and ... |
I wrote this for use internally at work and have never worked with encrypted data before, so can you please critique? It's written in VB.NET which I have decent experience in, just not the encryption portion of it.
I have written a simple internal messaging client. Basically a home grown email program but it uses file ... |
Given a two-dimensional list, say some_list = ["ABCD", "EFGH", "IJ"], I am supposed to encrypt it by reading each column top to bottom, thus:
A B C D
E F G H
I J
Would become:
AEI BFJ CG DH
My initial try had “index out of range” problem so I did this:
def encrypt_list(some_list):
encrpted_list = []
fo... |
I recently created a license manager for my publicly released project and I just wondered how I could improve it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Kiwi.Application.Base.License
{
sealed class LicenseManag... |
I'm getting address (physical address, not digital) input that's obfuscated, and looks like the following:
The plaintext version:
'39 Jerrabomberra Ave. Narrabundah Canberra 2604 Australia'
The obfuscated version:
['39 Jerrabomberra Ave., Narrabundah', 'Canberra', ' ', '2604', ', ', 'Australia', '39 Jerrabomberra Ave... |
Given the following CreditCard object, how would you get a count of unexpired credit cards? What are the pros/cons of using each method? Or is there a better/optimal way?
public class CreditCard
{
public int Year { get; set; }
public int Month { get; set; }
public int Day { get; set; }
}
public class User
{... |
During Jonathan Blow's video where he muses about a games-focused programming language, he presents C++ code that allocates a single big block of memory and has N pointers into that block. The purpose being to avoid heap allocating N blocks of memory for N arrays.
That code looked to me like it could use some genericit... |
Simple tool to save a web page's source. A result of trying to learn and apply an MVC approach. The FXML is generated via Scene Builder, but included for completion.
I welcome any general feedback on how to improve anything but in particular:
There are many exceptions, current impression is that current handling is no... |
I have implemented a Trie-based concurrent key/value store using hashcode similar to HashMap.
It is something like, if your hashcode is 50 (110010) then
create a TRIE with array size of 4 (two binary bits), the first value is 10 which is 2,10- [][][X][] --> 00- [X][][][] --> 11- [][][][X] will be represented.
HERE Th... |
I need a class representing a parsed Range HTTP header value. I've done it like this:
namespace net {
namespace http {
class DataRange {
public:
static const uint64_t UnspecifiedBytePos;
static const DataRange Full;
explicit DataRange(uint64_t firstBytePos, uint64_t lastBytePos);
... |
I want to make a list of the last words on each line of a file that looks like this:
casper@casper-PC ~/scripts -> cat /tmp/foo
update PTMM_ARCHIVE.FASTTRACK_USER set user_name = 'monohajoxx' where user_name = 'monohajo'
update PTMM_ARCHIVE.FASTTRACK_USER set user_name = 'wuemxx' where user_name = 'wuem'
update PTMM_A... |
It took some time to make Conway's Game of Life in HTML, CSS, JavaScript and jQuery. I'd like suggestions, criticisms, and discussions on how it can be done better.
JSFiddle link
/*
* Conway's - Game of Life.
* Any live cell with fewer than two live neighbours dies, as if caused by under-population.
* Any live cell ... |
I was talking to a coworker about over engineering things, which somehow lead to me over engineering the hell out of fizzbuzz. I went for a functional recursive solution in JavaScript. What do you think?
Full disclosure: my knowledge of functional programming begins and ends at "functions are king" and "no side effects... |
This is basically a non-recursive std::tuple_element implementation.
Note
To make this non-recursive, you must replace std::make_index_sequence with a non-recursive implementation. I left it with std::make_index_sequence in order to reduce the amount of unrelated code.
How it works
deduct has a specialization of deduct... |
I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the function).
I originally had it like this (not this in the where clause of an outer query):
skew.CalibrationDate.Date == ... |
(See the previous iteration.)
I have refactored the Range; now it looks like this:
Range.java:
package net.coderodde.util;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Thi... |
I had this idea today, but I don't have any practical usage for it right now. Any feedback or improvements welcome.
Code is found at CodePen, and also presented here as a snippet:
ul {
list-style-type: none;
width: 250px;
border: 2px solid #a9a9a9;
border-radius: 16px;
margin: 0 auto;
}
.item {
margin: 1... |
Can someone tell me how to improve my following python code.
Code:
a = open('/home/Username/1st few programms/names.txt')
for y in a:
c = y.split(",")
c.sort()
dict = {'"':0, "A": 1, "B": 2,"C": 3,"D": 4, "E": 5,"F": 6,"G": 7,"H": 8,"I": 9,"J": 10,"K": 11,"L": 12,"M": 13,"N": 14,"O": 15,"P": 16,"Q": 17,"R": ... |
This is a progression of the script I posted here: Zip the contents of subfolders, conditionally
It does this:
Determines all subfolders recursively
Checks each subfolder for files older than 31 days which aren't .zip
If such files found, creates a new folder within, labelled with the date
Moves the files to the new f... |
(See the next iteration.)
The result looks like
and my code is:
\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\begin{document}
\begin{algorithm}
\SetKw{Nil}{nil}
\SetKw{Is}{is}
\SetKw{Not}{not}
\SetKw{Mapped}{mapped}
\SetKw{In}{in}
... |
Problem:
You are given a randoms string containing only lowercase letters
and you need to find if the string contains ALL the vowels.
Input:
First line contains N , the size of the string.
Second line contains the letters (only lowercase).
Output:
Print "YES" (without the quotes) if all vowels are found in t... |
I've been playing around in C for a few weeks and decided to write a program that somewhat simulates an ATM machine. I'll give you the code at the end of the post in case you're not interested in dealing with the question at all.
Some facts: There are 2 languages in the program, the 2nd is Slovak. The code for it is th... |
I have some questions on how I can improve this "add action" (method) in "controller":
I'm using the add action only if post request. Is it correct?
This action doesn't have views ($this->autoRender = false;). Is it correct?
I set a response .json file to this action but I didn't change on routes to routing .json file... |
We have an exercise to design a simple library, which can calculate some length with different unit, e.g.
2m*2 + 20cm/2 - 5mm
and the result can be any of:
4.095m
409.5cm
4095mm
I want to design it in Object-oriented, and have a solution like this:
public class Length {
private final double value;
private fi... |
I have some questions on how I can improve this "add" action method in a controller.
Using a single form, the user can upload a product to be displayed on the site. A Product is composed of three entities: Product, ProductFeatures and ProductMedias (stored in three database tables).
To prepare data for insertion and u... |
I was asked a weighted probability question in a technical interview a few months ago that went something like this:
Given an input of colors and an integer "weight" value, randomly return a color based on its weight.
The sample input would be something like this:
[("Red", 20), ("Blue", 50), ("Green", 70)]
The proba... |
I recently started following the James M Kernel Dev tutorials and was able to create an operating system in C++.
Here is the source on GitHub.
I have a couple of questions:
Is my coding style ok?
Is it wrong to write bash scripts for building the project?
JOSMake.sh
#
# Build File for JOS
#
# To Build
# bash build... |
I wrote this to scrape album review data from AOTY into a spreadsheet. Check it out and let me know what I could've done better.
Option Explicit
Const classAlbum As String = "listLargeTitle"
Const classScore As String = "listScoreContainer"
Const classRating As String = "listScoreValueContainer"
Const classReview As S... |
I have created a Backbone Movie app as part of a learning exercise, the app is hosted on codepen although I actually have it built on my local but thought this approach would be handier for code review. I have some dummy JSON containing some movies that are stored in a Movie Collection and then another collection to st... |
I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with NULL terminators and the like. Not only that, but it should be efficient.
#include <stdio.h>
#include <stdlib.h>
#include <strin... |
My method searches through an list of accounts which have the property "Name".
class Accounts
{
static internal List<Account> accounts = new List<Account>();
static internal bool findAccount(string name, ref int account)
{
for (int i = 0; i < accounts.Count; i++)
{
if (accounts[... |
The calculator evaluates a mathematical expression with binary operators +, -, *, / and ^ in C. I store numbers and operators into two different arrays and process them according to precedence.
Please review my code and suggest me on changes on approaches to make it scalable to add unary operators and parenthesis.
#i... |
I've just solved this challenge, though I feel that there is a problem with stack growth or something because the 5th testcase has a runtime error
import Control.Monad
import Data.Sequence hiding (replicateM, replicate, take, drop)
import Data.List
main :: IO ()
main = do n <- getLine
input <- getLine
... |
I'm having problems solving this problem within the time limit.
Alternative Thinking
http://codeforces.com/contest/603/problem/A
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represent... |
I recently started "coding" and this is one of my first "projects". It is supposed to be an SI converter where you can type a value, its unit and the unit to which you want it to be converted.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ... |
Input Format
Input starts with an integer n (1 ≤ n ≤ 100) indicating the number of cases. The following n lines each contain a test case of a single even number x (4 ≤ x ≤ 32000).
Output Format
For each test case x, give the number of unique ways that x can be represented as a sum of two primes. Then list the sums (one... |
I have an object that houses only static functions. The functions are stand alone and are not dependent on the state of the object.
I hear that static functions are a nightmare in terms of testing, an anti-pattern if you will. I get it, the state of the object could be impossible to predict.. But these are stateless.
... |
I've written an amd64 assembly routine (in gas syntax using the System V calling convention) to convert three decimal digits to Densely packed decimal because I wasn't satisfied by the performance of the assembly generated by gcc and clang for all implementations of the conversion I could think of. Here is the code:
... |
I created this function to recursively copy an entire directory from an FTP server. It works just fine except that it is about 4 times slower than using FileZilla to do the same operation. It takes approximately 55 seconds to download the directory in FileZilla but it takes 229 seconds with this function. What can I do... |
I wrote a Ruby module to update DNS zones on certain events of the Docker API. Its purpose is to make container reachable by their name over a network. I know this is also possible through /etc/hosts entries, but in my use case I can not use the name resolution of the docker host.
I'm am pretty new to Ruby so I guess t... |
I am working on a speech reorganization project. I have a util class that consists of three methods: check if a microphone exists, check microphone availability, and check text-to-speech availability. Can anyone review my code?
public class MediaUtil {
//returns whether a microphone exists
public boolean getMi... |
I'm writing in VB.NET, using VS Community 2013. I don't know much about this language. I have managed to make my code work, but I suspect it is possible to improve the code a lot.
This code extracts packets from some data I've received using TcpClient.
Private inbuf(10000) As Byte
Private inoff As Integer
Private S... |
I have a helper extension method that I use for path string validation. It looks as below. It's purpose is to work with network paths as well, so in case a network resource is not available, I do not want my applications to freeze, hence the specified timeout etc.
public static bool IsExistingFilePath(this string sourc... |
I tried to write a foolproof function for the first part of the first problem on adventofcode, which asks for the count of ( characters minus the count of ) characters in a string.
The function intentionally ignores any other characters in the input string.
function findEndFloor(floors, upFloorSymbol, downFloorSymbol)... |
I am writing a trivial continuous integration tool using node.js to learn the platform. So far it can download a project from Github, and unzip it into a random folder in a predefined dropfolder. But I'm pretty inexperienced in pure JavaScript and loosely typed languages in general and the code that I write looks very ... |
using System;
namespace Friendly_Bot
{
internal class Program
{
private static string[] Greetings = { "Hello, you have a", "Hey, you have a", "Hi, you have a" };
private static string[] Compliments = { "cool", "fashionable", "stylish" };
private static string[] Garments = { "coat.", "dr... |
As an exercise, I decided to program my own version of the game Pop the Lock for the iPhone. The look and functionality are essentially the same, though the controls are modified for playing on a computer.
I am looking for any feedback or criticism on my program's layout or overall flow. I also kind of hacked togethe... |
I am trying to implement substring in C. How efficient and standard is this code? I have a hard time understanding how C functions are usually meant to work, like how printf() returns an int or size_t.
size_t substring(char *destination, char const *string, int start, int len) {
// writes a substring to the destin... |
I have several very similar subclasses that I (think I) want to be stored in the same database table. Most of the fields are identical, with each subclass adding 1 or 2 custom fields. My code is using the Django ORM, but I think the question is more general than that.
Problem specification
The app is meant to simplify ... |
I'm working on a table component that is able to scroll through millions of lines of data. Not bad for the front end. The way I'm doing this is to only render a small table with 10 rows and then, when the user scrolls, I change the data in that table.
The table itself is not in a scrollable div because the entire html ... |
CodeEval FizzBuzz
Quick Description:
Take 1 command line argument of a file-path. This file will contain
test cases formatted as such 3 space separated numbers per line. For
numbers X, Y and Z you must print out all numbers between 1 and
Z, space separated, replacing all numbers divisible by X with 'F'
and all... |
FizzBuzz in VBA. Takes start and end numbers as arguments. Will handle any pair of integers to +- 2 Billion or so, determine whether the sequence is increasing or decreasing and output numbers to the immediate window.
Public Sub PrintFizzBuzz(ByVal startNum As Long, ByVal endNum As Long)
Dim currentNum As Long
... |
I've written a simple FizzBuzz in TSQL using some IF loops.
Here's a SEDE link to run it in your browser.
DECLARE @i int = 1
DECLARE @str varchar(8) = '';
WHILE @i <= 30 BEGIN
SET @str = ''
IF @i % 3 = 0
BEGIN
SET @str = 'FIZZ'
END
IF @i % 5 = 0
BEGIN
SET @str = @str + 'BUZZ'
... |
Before you close vote:
Yes, Scratch questions are okay.
Link to project on Scratch
For the hundredth fizzbuzz question, I'd thought I'd spruce it up a bit and post something new.
So, first make three variables named i, iterations and string:
And a list named ListOfFBs (FBs = FizzBuzzes)
Here is my main code:
Which... |
This is a simple binary search tree implementation written with C++'s templates feature I wrote to learn C++. What improvements would make this cleaner and better as far as C++ practices go, and are there any problems with implementing the algorithm?
#include <iostream>
#include <string>
using namespace std;
templat... |
I have quite a lengthy method that I know for sure can be optimized, yet I am not sure how to do it. The method is in my User model, and essentially gets the questions assigned to the user in the current week. Questions can be assigned to a variety of intervals, so it's important that for each week we get the right one... |
I am developing a plugin for intellij that basically monitors a log file and displays the data in a tool window within the IDE in real-time. I have managed to get it working but I would like to know the areas where I can improve on. I'm specifically interested in the structure of my code and the log file monitoring met... |
I would like to know an alternative, more elegant way to write the following methods.
I am especially not enthusiastic of the nested if statement or if for validate null values.
Now there are 3 if statement for null validation.
Any method:
private void LoadAlertas()
{
// *** OMITTED ***
... |
My current query:
select `t1`.* from `product_variant_values` as t1
inner join (
select `t1`.* from `product_variant_values` as t1
where (
(t1.`option_id` = 1 and t1.`value_id` = 1) or
(t1.`option_id` = 2 and t1.`value_id` = 4) or
(t1.`option_id` = 3 and t1.`value_id` = 7) )
group by t1.varia... |
I have a model:
class ColumnItsValues
{
public int PropertyID { get; set; }
public string ColumnName { get; set; }
public string ValueOfColumn { get; set; }
}
two collections:
List<ColumnItsValues> listColumns = new List<ColumnItsValues>()
{
new ColumnItsValues() {ColumnName="GUID", PropertyID=0, ValueO... |
I wrote this program to calculate a value from an energy function from a sequence of 1s and -1s. The problem here is to find the lowest possible fitness for a function (note that this is original function; in my implementation I pre calculate power of c c*c and put it in the thread so I avoid calling a method):
double... |
The following is my python solution of project euler 12.
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7
= 28.
The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first sev... |
For some reason, I completely lost my reasoning with this code. I can't hold this simple logic for too long in my head. Actually, I want to improve this code, making it a little concise. The if (so.scan_complete and force) or not so.scan_complete: is just not a KISS thing. Please any suggesion to optimize and concise i... |
Here is my Implementation. It is I think almost like algorithm.
public static uint[] CountingSort(uint[] A ,uint max)
{
uint[] B = new uint[A.Length];
int[] c = new int[max +1 ];
for (int j = 0; j < A.Length; j++)
c[A[j]]++;
for (int i = 1; i < ma... |
I am a new to Eigen, and I implemented a logistic regression model with it. It works but I don't know whether it is implemented in an efficient way.
#include <iostream>
#include <Eigen/Dense>
#include <cmath>
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture;
using namespace s... |
I'm working an open source project written in Python that is a wrapper to the Pushover API called py_pushover.
The main function of this wrapper is the push_message function which allows the user to push a notification. The API has 10 possible parameters with only 3 being required. I've handled those three required... |
How to count the solutions of the equation \$x \cdot y + x \cdot z + y \cdot z = n, (0 \leq n \leq 10^4)\$ with the constraint that \$x \geq y \geq z \geq 0\$ ?
To solve this i've isolated the z value and brute-forced the values of x and y. If the values x,y,z satisfy the constraint and equation than its a valid solut... |
I recently had submitted my bashscript for building an OS for review and got valuable feedback, so I rewrote the entire script for a makefile:
Makefile
# Make File for Bulding Ultron
# Sets up the Assembler
AS := nasm
ASFLAGS := -f elf
ASFILES := $(wildcard kernel/boot/*.s kernel/arch/*.s)
ASOBJECTS := $(ASFILES:.s=.... |
I am using classes for the first time. In this program I want the object to run infinitely so that any change in the MongoDB will trigger the function and do the necessary processing.
I am little confused about the using of the self. Please give me feedback on my code.Thanks!
class first_level:
def __init__(sel... |
I am trying to write a function that will count the occurrences of a pattern in a string without overlap. This is what I have right now.
size_t count(char *string, char *pat) {
size_t patternLength = strlen(pat);
size_t stringLength = strlen(string);
size_t count = 0;
char *compareString = malloc(patter... |
This is a rags-to-riches take on this question, specifically an improvement of my original answer there.
Copying my interpretation of the calculations involved from my answer:
Given a 70-character String for the Keirsey Temperament Sorter test, e.g.
"ABABABaABABABaABABABaABABABaABABABaABABABaABABABaABABABaABABABaABABA... |
I have a method which I use on occasion to convert strings (like enum and property names) to PascalCase for display.
It's fairly simple, so there's probably not much to comment on, but as usual I appreciate any advice on improving it.
/// <summary>
/// Converts a string of dash-separated, or underscore-separated words ... |
Below is the code I have for a RandomForest multiclass-classification model. I am reading from a CSV file and doing various transformations as seen in the code. I am planning to run this in a Spark cluster with lots of data (at least 6 million rows of data with 50 features). I can get sufficient amount of RAM and cores... |
First, I must humbly admit that I've been a developer for many years but I've almost never had to work as a front-end, Web UI developer. I've been given an opportunity to work for an organization as a front-end and back-end web developer and I'm having to learn about the in's-and-out's of HTML/CSS/JS code. This is my... |
I wanted to try and use the Sieve of Eratosthenes to find all prime numbers between some arbitrary bounds 1 <= m <= n. The simple implementation of the sieve does not consider the lower bound at all, it always starts from 1 (or actually from 2). So for a big enough n, simply creating an array would be impossible.
The a... |
I have this:
public void InfoAssignment()
{
//MessageBox.Show(firstName = firstNameBox.Text);
firstName = firstNameBox.Text;
lastName = lastNameBox.Text;
phoneNumber = phoneBox.Text;
address = addressBox.Text;
//Check for text in firstNameBox
if (!String.IsNullOrWhiteSpace(firstName))
... |
How do I make this go faster? It currently takes about 30 seconds on a 3gb file. I am using this to get a checksum from the file to compare it to Microsoft's official checksums. I am wondering if using a buffer would help and if so how should I do that?
public static String GetSHA1Hash(string fileName)
{
... |
I wrote this program for school (first year in college) and it works, but it's too slow. I wondered if anyone could help me optimize this a bit, because I've been trying and trying, but it just won't get better.
If I choose a lower limit of 5000 and an upper limit of 10000 it my program 10 times longer than my professo... |
Background: I'm trying to learn basic OOP with Python. I have this program I wrote to help my son practice math problems. It does addition, subtraction, multiplication, and division. He can choose easy, medium, or hard for each operator.
Here's an excerpt of the code. It's the "easy" addition function. (The "mediu... |
I have a program to read signal data from 120 files in a folder and performing the energy of the signal.
It works correctly, but execution time is more than 20 mins, so there may be a problem with the code. Can someone look into it and suggest possible methods to reduce the execution time?
import java.io.BufferedReade... |
I'm interested in learning how to create shell scripts with bash so here's one of my first exercises, taken from here. It is an extension of the problems Elementary - 4 and 5.
The goal of the program is to sum all multiples or ARG1 or ARG2 below the user's input number.
#!/bin/bash
echo "This program will find all the ... |
I have a MongoDB collection of product IDs/unique products attributes and a second collection of codes that relate to attributes common for products whose IDs are prefixed with those codes.
For example, two product IDs might be aaa17859 and aaa98542 so their code prefix is aaa.
I have several thousand codes, and the co... |
I have an array of objects where each object has two keys: key (k) and value (v). I need to make an object that would take values of k and collect corresponding values of v as a value of this key, an array of them.
So, for example, from an array
[{
k: 'a',
v: 0
}, {
k: 'a',
v: 1
}, {
k: 'b',
v: 2
}]
I need... |
I am writing a module that can access localStorage through a public API which exposes methods that allow string or array returns.
It doesn't feel as though I'm doing this in the most effective way. For example, I feel as though using:
var tudCache = getTud(); to grab the object from getTud() doesn't feel like the most ... |
Self explanatory, and all the functions contain descriptions of their specific problem statements.
Since this is project Euler, I would be particularly interested in any analysis of the functions' computational efficiency.
Option Explicit
Public Function ProjectEuler1() As Long
'/ Problem statement: sum all m... |
Inspired by Hosch250, TopinFrassi, Legato and the recent milestone of having our 100th fizzbuzz question on Code Review I decided to add an ArnoldC FizzBuzz to the collection.
I haven't found any best practices about the language, but I assume the code needs to be VERBOSE. For those unfamiliar with the language, a smal... |
I was given a homework and I have 2 solutions: one that uses this and other one that doesn't.
I tested both solutions on jsPerf but sometimes it says the version with this is faster or sometimes the other one. So I think I cannot really rely on jsPerf. Anyway, should performance be always the top priority?
By the way, ... |
This is my recursive program for the following function:
\$F(x) = G(x) - W(x)\$
\$G(x) = [G(x-1)+G(x-2)]^2\$
\$W(x) = [W(x-1)]^2 + [W(x-2)]^2\$
If x == 0 in either function G or function W, then return 0
If x == 1 in either function G or function W, then return 1
import java.math.BigInteger;
import java.io.PrintWrit... |
I am trying to work out a solution. I have to order the elements in the array a, such that a[0] is greater than a[1], a[1] is less than a[2], a[2] is greater than a[3], and so on...
Basically my method checks if the index is odd or even , and simultaneously makes a decision to swap elements to suit the criteria of th... |
I'm quite new to threading primitives in C# and was hoping you might be able to suggest improvements to this. I need to ensure that the XXX call below happens within the calling thread (XXX is a foreign call into a thread-unsafe library), so I used a queue here. It seems a bit like there should be a better primitive fo... |
Here I implement N-Ary tree in C#.
namespace ConsoleApplication1
{
public class tree {
public int info;
public tree child;
public tree siblings;
public tree(int data)
{
info = data;
}
}
public class NAryTree
{
public tree ROOT;
... |
Since it is quite a hurdle to manage dynamic arrays in C I wrote a simple generic wrapper to handle a pool of pointers. To prevent internal fragmentation when deleting and appending again I store the real indexes in a secondary index array. Do you see any flaws in my code? Would you have any suggestions ?
#ifndef __151... |
I would like to have some feedback on my code, basically because I have been spending a few hours visiting other options before I ended up with this one, so I'm not sure I'm clear enough to value it.
I have an API controller that gets and stores products in a memcached database, they will fall into one of the two categ... |
Is it fine to retry a web service call like this in Python? Would there be any scenarios the exception might not work the way we expect it? I expect it to continue only if it's fine, otherwise just retry, and if that doesn't work, just throw the error out.
def getblob(html):
num_of_retries = 2
time_interval = ... |
I was long a professional in COBOL, but noone ever dared comment my style. As the FizzBuzz seems fashion here, I made one. Verbose, of course, we're speaking about COBOL. I know I could have made in 15 lines, but decided instead to provide the full structure for a production program. Result makes 87 lines.
I'll be happ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.