instruction stringlengths 71 71.9k |
|---|
Situation
So I have made a list of PictureBoxes on my form that looks as follows:
All images have a panel behind them that is 4px lager (2xp all around the picture box). The images are named x1, x2, xn.. respectively. The panels behind the images are named y1, y2, yn.. respectively.
I want this to happen smoothly when... |
The new version of the code can be reviewed in Simple multi-dimensional Array class in C++11 - follow-up.
The following code implements a simple multi-dimensional array class (hyper_array::array).
I modeled most (if not all) the feature on the orca_array.hpp header by Pramod Gupta after watching his talk at this year'... |
I just started learning Java about a month ago. I'm wondering, what would an experienced developer do differently in the code below? As I learn to code, what direction should I be pushing myself?
I wanted this program to output large versions of digits that the user enters. Any characters entered that are not digits sh... |
I'm trying to write terse Perl code to calculate the average of each column in a file. The file can have >= 1 columns.
use strict;
use warnings;
use List::Util qw/sum/;
my @aoc = ();
while (<DATA>) {
my $c = 0;
push @{ $aoc[$c++] }, $_ foreach (split);
}
print join (" ", map { sum(@$_)/@$_ } @aoc), $/;
#output: 2... |
This code seems to be working. I am allocating matrices on the stack and passing them to functions to modify in place. Is this a standard practice, or am I doing it wrong?
Header:
#ifndef _MATRIX_H
#define _MATRIX_H
typedef enum {MT_OK, MT_INVAL} MT_RESULT;
typedef float mat4[4][4];
typedef float vec4[4];
MT_RESULT ... |
This is an interpreter that takes in a slightly altered Befunge-93 (no input from the user, no limits on size and division by zero defaults to zero).
I'm currently looking at the state monad and how it could be integrated into what I wrote. It seems to change quite a bit in the way I have to think about my interpreter ... |
Using my previous function as a base I've come up the following:
create function dbo.Totp (
@key varbinary(8000)
, @timeStep int = 90
)
returns table
with schemabinding as
return (
select [Pin].s as Pin
from dbo.GetUnixTime() UnixEpoch
cross apply dbo.Hmac(@key, Cast(Floor(1. * UnixEpoch.n / @timeStep... |
This is the function I coded, obviously used to get the system name:
const char* os(){
OSVERSIONINFO os;
ZeroMemory(&os, sizeof(OSVERSIONINFO));
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&os);
std::string ret = "Windows ";
if (os.dwMajorVersion == 10)
... |
I'm trying to convert a string (here after called input) into a vector of key-value pairs, all in C++03 (cannot use C++11, cannot use Boost libs).
The string in question can contain whitespaces. A comma (,) delimits key-value pairs and the equals sign (=) separates the key from the value.
A sample string (also in the c... |
I took the basic layout manipulation from a jQuery plugin called flexImages. The idea is to use the directive tag and encapsulate a piece of code that will be transcluded to make up the container cells of each row. Unlike the jQuery plugin I didn't want to force defining the initial width and height of the container ce... |
I was fiddling with the source code of Quake-2 today and at some point wanted to extract files from the .pak archives used by the game. Since I couldn't find any tool to do that on my Operating System, I coded this quick-'n-dirty command line extractor for Quake-2 PAKs:
#include <stdio.h>
#include <stdlib.h>
#include <... |
The Knuth–Morris–Pratt string search algorithm is described in the paper Fast Pattern Matching in Strings (SIAM J. Computing vol. 6 no. 2, June 1977). The initial step of the algorithm is to compute the next table, defined as follows:
The pattern-matching process will run efficiently if we have an auxiliary table that... |
I wanted to make sure that my code is properly converting between the two endians.
Here is the code where I read in an integer:
System.out.println("Please enter the integer:");
int number = input.nextInt();
System.out.println("At what word address would you like to store the da... |
I have upgraded my code. In the old code I had two functions: display_maker_success() and display_maker_fail():
function display_maker_success($link, $userid){
$status="closed";
$result="completed";
$html = '';
$sql = "select start, name from wuuk where tasker_id ='$userid' and status ='$status' and re... |
My friend and I are making a node.js game, and we have been testing CPU. After profiling, it was determined that this process called zlib is sucking most of the CPU/RAM.
3 clients connected to a game is fine, but when 12~13 players are connected it uses 58% where zlib is using about 30% of this CPU.
inclusive sel... |
I have an assignment to write a knights tour backtracking program in Java where the professor says to:
Eliminate backtracking time by:
Find the knights with the least possible moves
Sort those moves from knight with least moves to greatest moves
Backtrack if that path fails
I have done that with and attempted some ot... |
I'm kinda new to javascript and have question about it. Now my practical project is growing a bit bigger. I got the following if else statement. Is it possible to refactor this ? Should i use an use case or are there other options or will this decrease the loading speed of the application.
(function () {
'use stric... |
I'm happy to hear thoughts and ideas on structure/performance/testing/whatever and multi-threading, which I haven't gotten into yet with Python.
Full code here. Assignment file and a test file included in the folder.
Excerpt:
import unittest
import sys
def Merge_and_CountSplitInv(A,start_index,len_1st,len_2nd):
""... |
I've written a little (imperative) java program that basically prints out all french written numbers from 1 to 1000. (I'm learning how to write them)
Based on the first numbers (1-16) and the tens and hundreds, It chains the words of the next number together and writes them into an one dimensional array.
The French c... |
On click on a div, a form replace this div. When the user clicks outside the form, the form is hidden and the div is re-show. For this, I implemented this process and I want your feedback, please.
function showForm(){
hide the div
show the form, and set value of a form textarea
textarea.focus();
}
function... |
I decided to write an ATM program in my favourite programming language, C#.
Tested with a few numbers and I am confident it will give correct output for any valid input:
class Program
{
const int MIN_WITHDRAW = 20;
const int MAX_WITHDRAW = 1000;
const int INVALID_WITHDRAW = 30;
const int TWENTIES = 0;
... |
I need to build a bar graph that illustrate a distribution of pseudorandom numbers that determined by linear congruential method
$$X_n+1 = (a X_n + c) \mod m$$
$$U = X/m$$
on the interval [0,1]
For example:
Interval Frequency
[0;0,1] 0,05
[0,1;0,2] 0,15
[0,2;0,3] 0,1
[0,3;0,... |
I have programmed this simple Stock Control System using JavaFX for GUI and PostgreSQL for a database.
Please go through my code and point out flaws, inefficiencies, and better ways of doing things. I'd also like to be made aware of best practices which I am not following. The last two files are external links because ... |
Led by the recently read premise "Lean controllers and fat models" I've come to the conclusion that my controller might be too fat at the moment.
Basically, what I'm trying to achieve is simple Edit (POST) function where I'm trying to update heavily nested entities. What can be found here is a ViewModel (VM in the cod... |
I'm working on a project where I pull data (JSON) from an API. I would like to manipulate this data and store this as useful information in my DB (MySQL). My code is working if I would like to make, for example 2000 requests.
My script step by step:
Get IDS from DB, store them in array urls.
Take a chunk
Set and exe... |
As I mentioned at the end of my Round 2 answer, I've needed to expand my code in order to produce faithfully the data needed for Figure 1 of this paper.
Unfortunately, the updates have made my script extremely slow, to the point that it doesn't finish within an amount of time I'm willing to wait.
Why is the script so s... |
I made a simple application to test your own website security for DDoSes in Python. Any suggestion is welcome.
import random
import socket
import threading
import time
userAgents = ["Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36",
"Mozill... |
I'm making a game in Java 7, and I have this block of logic when handling an update from the server.
public void handleNewPlayer(Player newPlayer, Player[] otherPlayers) {
boolean done = false;
for (Player otherPlayer : otherPlayers) {
if (newPlayer.id == otherPlayer.id) {
updatePlayer(other... |
Simple Playlist Modifier
This program is a search and replace program for text based files. The main goal of the program is to replace directory paths to music files.
The idea is to have the program read files from input and then validate the given parameters (a file path in this case).
The Source M3U Contains -- creat... |
I have developed some Python code which revolves around two custom classes - a 'Library' class (Lib) which contains a Python list of several objects based on a 'Cas' class. I've not posted the code for either of these classes here, but all you really need to know to understand my question is that the 'Library' object c... |
I am looking for general feedback on this small, simple program I wrote. It works perfectly, but I am striving for readable, clean code.
I also have specific questions:
Is the switch statement the most efficient/logical way to write this class?
Is my main method too large? Should I break it into smaller methods? Ho... |
(Here is the follow up question)
I had another go at trying to speed up my program described in my previous question.
JS1's answer was particulary helpful and now my code is only about 20% slower than the fastest program in the programming challange (it runs in 0,13 s and my code runs in 0,16 s). I ran the code with d... |
The script below should open a file, read and reverse every line, then overwrite the source file.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
// reverses the order of characters in every line of SRC file
void validate_cmdline_args(int argc, c... |
I wrote my first script for google apps, but I am just learning how this all works. The script works fine, but I am sure there are things that are not done properly. Any advice is appreciated.
The code creates awards from a Google Sheet where a column of names (last name, first name) is separated and text is replaced... |
NaryHeap as a generalization of binary heap. Each node has up to N children. A template specialization for N = 2 (BinaryHeap) is given too. Though apparently not standard, I've also defined removing a node other than the root, and removing a node by value.
#include <iostream>
#include <functional>
#include <algori... |
High Level Explanation of Code's Purpose
I wrote a class to create sectioned reports, where each section has a subtotal. It allows these reports to be nested within each other, to create multiple levels of subtotals. An example will help clarify the idea before getting to the real code....
Consider this sample data:
... |
I have this code for reading Twitter users from a text file represented by integers in the format "int (space) int", where the first int is the ID of
the user doing the following and the second int is the user being followed. It works for small files but takes a really long time with larger files. What can I do to make... |
Well, it really isn't a big pain: but I fear of security risks (if that is even possible).
Background:
I decided to (sort of) abandon my Sudoku project (because I accidentally deleted it from disk), and was given the idea of a JavaFX Helper Library. I started with the LoginPane, as I find I use login popups quite often... |
Inspired by reading "How-to write a password-safe class?", I tried some clever (or dumb-fool) hack to create a widely-useable secure string using the std::basic_string-template, which does not need to be explicitly securely erased itself.
At least gcc and clang seem not to choke on it (coliru):
#include <string>
namesp... |
I tried implementing visitor patter and have questions about my usage of is and as keywords. Is there a big performance hit when using them?
class Program
{
static void Main(string[] args)
{
List<IVisitor> visitors = new List<IVisitor>();
visitors.AddRange(new List<IVisitor>()
{
... |
I'm having a lot of trouble in my Database program with trying to implement an effective DataGrid filtering method. After taking advice from a previous code review I'm trying to implement a DataModel method of coding. My previous method of searching my DataGrid was this;
SearchGrid (PREVIOUS)
private void SearchGrid(ob... |
I'm serializing multiple elements using this code:
public IEnumerable<Customer> GetCustomers(xmlString)
{
var xml = XElement.Parse(xmlString);
var customers = xml.Elements("Customer");
var serializer = new XmlSerializer(typeof(Customer));
return customers.Select(c =>
{
using (var reader = c.CreateReader()... |
I am new to programming and I have just written my first program. It takes files from an SD card and copies then into a new named folder and has the option to name the files themselves or simply move them into the named folder.
As I am new I am unsure of the correct convention in terms of layout or structure of a progr... |
I am asking your preference between two similar solutions.
First way :
public function test($myvar) {
switch ($myvar) {
case 'test1': return [
'value' => 'Value of test1',
'short' => 'Val 1'
];
break;
}
}
$this->test... |
I log records in external memory. Every record takes \$2\$ bytes. Now I need to read \$N\$ last records in chunks of \$18\$ bytes, so I did something like this.
uint32_t chank = 18; //DELTA_SIZE * AVAILABLE_BUF_SIZE;
uint32_t last_log_addr = (logNum * DELTA_SIZE) + START_LOG_ADRESS;
uint32_t packet_size;
uint32_t curr... |
I am working with an object that needs to run an ExecuteEffect() method. Sometimes, the ExecuteEffect() only needs to run once, while in other cases, the ExecuteEffect() needs to keep running once / frame until some criteria is met (in my example, a real-time delay).
To solve this, I used an IEnumerator:
public overrid... |
This builds a BinaryTree from given Inorder and Preorder lists.
class TreeNode(object):
"""Node of a Binary tree."""
def __init__(self, key, left=None, right=None):
self.key = key
self.left = left
self.right = right
def __str__(self):
return "{0}".format(self.key)
def __repr__(self):
... |
I made a data entry form that writes each category into a text file. As an example I used Regular, Premium and Diesel categories. They each have open, delivery, total, sales and close numbers for that day. How can I can improve my code? Also I tried to implement the login form but I couldn't get it to work.
import tki... |
I've created a search page on a rather large Audit table (populated by triggers on every database). There are 4 fields you can search by (and I put each textbox next to each other): User ID, Table ID, Date, Record ID. This is for programmer's use and high level managers who would know what these fields mean. Record ID ... |
As a first step to making a PacMan clone, I wrote a Breadth-First Search demonstration that updates itself live as you draw walls and drag around the start and end points. It was inspired by the site that I learned the algorithm through, which has similar demonstrations.
A sample of it:
To use it, use the mouse to dra... |
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
system("cls");
system("color 5");
float a;
float b;
float c;
float Sector1Arithmetic;
float S... |
Objective: Given a set of sequences ( eg: step1->step2->step3, step1->step3->step5) ) arranged in an array of lists, count the number of times every contiguous sub-lists occur
Where I need your help:
The code below works, but is very slow on my original dataset (100M sequences, with 100 unique steps). Can you help me ... |
I was asked to implement this in an interview a while back. I didn't pass the interview, mostly likely because it took me far too long to do. However, I'm interested to know how well implemented the actual code is.
The task was to:
Add one to a positive number represented as an array of integers.
The question is the ... |
This is one of my first Python scripts and I was wondering if it meets the correct conventions. Also are there things that you would write different? I am looking for some good comments so I can start to improve my Python code from the start. (I was not supposed to use imports here)
Here's my implementation of Simplifi... |
So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them now. I thought I would go ahead and post the working code though.
How can I improve on this? What can I do better to do m... |
Here's my custom formatter which I want to use for "application/x.product" content type:
public class ProductFormatter : MediaTypeFormatter
{
public ProductFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/x.product"));
}
public override bool Can... |
Right now I have no knowledge of templates, but I just finished learning about inheritance, and wanted to apply it to a Vector3 class that I had already created. My thoughts were that vectors of different dimensions share some common operations, and so it should be possible to apply an inheritance hierarchy to this.
Ul... |
This is a follow up on my previous question.
JS1's answer suggested that I should use a precomputed table containing all permutations of the lowest valid number for each number between 1 and MAX. It was well described how to implement the precomputed table but somewhere I seem to have miserably failed since the code ru... |
We typically do our saves and deletes for our asp.net pages (SQL Server as back-end) in the code behind. I've seen some reference the idea of creating a stored procedure for this purpose. Is this the best approach or is what I'm doing practical enough? Any suggestions? Here's an example of the delete button function (f... |
I've written a small bit of JavaScript which parses some HTML and generate a table of contents based on the various heading tags. The table of contents needs to be nested (E.g. H2 tags appear under H1).
My code is currently working well but I'm not sure the my method of storing all the headings is the best (it's been a... |
I have written code that reads in a CSV file and creates a tuple from all the items in a group. The group ID is in column 1 of the table and the item name is in column 2. The actual datafile is ~500M rows.
Is there any way to make this code more efficient?
Input file:
"CustID"|"Event"
1|Alpha
1|Beta
1|AlphaWord
1|Delt... |
I'm looking for some performance suggestions. The purpose is to toggle a data attribute value indicating when an element is either in view or out of view. You can also assign callbacks to be called when the element comes in and out of view. Secondarily, it indicates the direction of the scroll by adding a data attribut... |
One of the most important parts at the core of rubberduck is the IdentifierReferenceResolver class, which is responsible for resolving each declaration as the parse tree is being walked and function, member and variable calls are being encountered.
Proper scoping is the single most important concept here: when we meet ... |
I am taking a class on ruby and our assignment is to take user input and print out a polynomial. Wondering if I can get any feedback to how to improve my code.
class PolynomialElements
attr_accessor :element, :size
def printElement
if size.to_i == 0
num = "#{@element}"
elsif size.to_i == 1
if e... |
I recently gave a test on HackerRank:
Given a string, return the most concise string that can be formed from it.
For example:
string = 'watson Represents|watson represents|Watson represents a first step into cognitive systems, a new era of computing.|first step into Cognitive|Cognitive Systems; a new era|what does w... |
About 2 weeks ago I made a Java game of Tic-Tac-Toe. It turned out great and it worked but it needed lots of help before it became a decent program. Since then, I have worked out lots of the kinks and errors. I would love to know what you think of my improved program.
public class ADitionalPractice {
public static boo... |
I've recently been learning Python and decided to write an IRC bot as a good first project. Before now I've only really written scripts.
I am using the Python IRC library.
The IRC bot joins an IRC server and multiple channels, logs the channels and makes announcements by listening for messages on a port.
I've gotten t... |
Problem statement
Given a node check whether the sub-tree rooted at given node is full binary tree or not.
Definition
A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node other than the leaves has two children.
Solution
class TreeNode(object):
"""Node of a Binary tree."""
def ... |
I have a table which has tasks with several statuses, user can use filter check-boxes to show and hide rows based on these status filters.
function toggleRows(checkBox, img) {
var show = $("#" + checkBox).prop("checked");
var rows = $('tr img[src="../_layouts/15/images/' + img + '.png"]').closest('tr')
if... |
I am currently working on a Redis project and I would love to know where I am likely to run into Unhandled Exceptions in the following code.
A General Review would be great, don't hold back.
This is code for Intercepting using proxies, and uses a considerable amount of Reflection to resolve unknown types.
I am posting ... |
They've always annoyed me, and as a matter of principle, would like to leave my HTML/CSS intact and have the various file upload plugins work with consistent behavior with any styled element.
The following script places a transparent file input over a selected input. Note that solutions such as triggering an upload sc... |
Is there any better way of doing this?
function getRandomColor() {
var chars = '0123456789ABCDEF'.split('');
var hex = '#';
for (var i = 0; i < 6; i++) {
hex += chars[Math.floor(Math.random() * 16)];
}
return hex;
}
|
I am developing an application to validate the interaction between activities through intents.
I created 5 ImageButtons with an image for each. Each button is a movie and if you click any of them, it's directed to a new activity with a synopsis of the film. In the activity with the synopsis, there is an "up navigation"... |
I have a method like this:
public boolean wasUserInactive() {
boolean result = userInactive;
userInactive = false;
return result;
}
This works, but is there a “smarter” way to code this?
|
Due to various business and technical circumstances, I have to create an internet-facing .NET 4.5 WCF web service which should be called only by a certain party while not using native authentication schemes (mainly because I don't have an SSL certificate available, which precludes X.509 and user/password authentication... |
This is a simple implementation of vector in C++. Please offer your reviews to improve the code.
#ifndef VECTOR_HPP
#define VECTOR_HPP
template <typename T> class vector{
int size;//size allocated on the memory
int index;//current number of elements
T* arr;
void resize(){
T* temp = new T[size];... |
I created a Sudoku game with varied difficulty level.
The Sudoku board creation process consist three stages:
Creation of an empty board
Filling the board with numbers
Making holes in the filled game board
The assigned numbers fulfill all Sudoku game conditions, and every puzzle has a unique solution (verified in the... |
In this project I'm working on, I need to extract articles text from their original HTML document. This class, HtmlConnection, receives the URL of the article, and eventually it needs to produce a collection of the paragraphs inside the article. I'm using HTML agility pack and XPath to extract only relevent text from t... |
I have to create a table that will allow users to upload different documents for each of the entry in the table. To be more exact, each row will contain a unique ID on first column, followed by 3 inputs (upload) for video, text and image, and a save button (each on next column of the row).
The problem is that I have a ... |
This detects the difference between two objects (or revisions):
var A = {A: 10, B: 20, C: 30, D: 90, BB: 5, CC: 4, AA: 2};
var B = { B: 22, C: 30, L: 4, KK: 444, A:15};
var difference = diff(A, B);
console.log(difference);
document.write("<pre>"+JSON.stringify(difference, 0, 3)+"</pre>");
function diff(a, b) {
... |
I have this code that creates unique passwords using the first letter of each word from the file. Before each password is created (written to a file) it is compared to all passwords that are currently in the file, so if the file has 50,000 passwords before a another is written it has to scan through all 50k.
A user ca... |
This is my own implementation of an hashtable. I would like to receive some reviews or some feedbacks.
public class HashTableEntry<K,V> {
private K key;
private V value;
private HashTableEntry<K,V> next;
public HashTableEntry(K key, V value) {
this.key = key;
th... |
I have the following if statement:
if ($scope.current < $scope.questions.length) {
$scope.current += 1;
}
if ($scope.current == $scope.questions.length &&
$scope.chapter < $scope.all.length - 1) {
$scope.current = 0;
$scope.chapter += 1;
}
if ($scope.current == $scope.questions.length &&... |
I wrote this class which reads an SSH config file and checks whether an IP exists. If the IP does not exist, the class adds a block for that IP address.
Header file:
class SSHConfigFile : public QObject
{
Q_OBJECT
public:
explicit SSHConfigFile(QObject *parent = 0);
signals:
public slots:
void registerIP... |
I have code that is identical minus two changes that would happen each time, which I can use variable for, but I don't want to use a bunch of if statements.
C = 1
fnd = Sheet1.Cells(C, 8)
While InStr(fnd, "Customer Name:") <= 0 And C <= 300
C = C + 1
fnd = Sheet1.Cells(C, 8)
Wend
If C >= 300 Then
Sheet2.Cells(r, 2) = "... |
I'm working on a hobby kernel, with graphics and rendering fonts. The font format is BDF. Some of them (like for Ubuntu Mono) I used was ttf2bdf. Then I use a program called bdf2c which converts it to a .c file. From there, I can use the data in my program.
First, let me start off by showing you code that won't change,... |
I am trying to implement a function that merges two ordered lists into a third (ordered) one, but duplicates have to be discarded (basically the last step of a mergesort).
I think that this code can be generalized to an arbitrary number or lists, by keeping a list of indices, rather than 2 explicit ones.
def merge_no_... |
I've made a python program to convert DuckyScript code to Arduino code for Leonardo boards. Below you can find both the project files and a sample script.
compiler.py (the program base):
#!/usr/bin/env python3
"""
Usage: {} <input> <output>
<input> should be a DuckieScript file and <output> will be an Arduino sketc... |
Are there any possible speed improvements I can make to the following method. It takes a JDBC ResultSet and breaks it into several CSV files:
public static void convertToCSV(final ResultSet rs) throws SQLException, IOException {
final DateFormat format = new SimpleDateFormat("yyyyMMdd,HH:mm:ss");
format.setTime... |
I recently developed a simple treap data structure in C#. In the future, I may have the class extend IDictionary. For now, I only expose a public accessor and a delete method.
public TValue this[TKey key]
{
get { return Get(root, key).Value; }
set { root = Set(root, new Node(key, value)); }
... |
Write a program reads two integers representing a month and day and prints the season for that month and day. Assume that months are specified as an integer between 1 and 12 (1 for January, 2 for February, and so on) and that the day of the month is a number between 1 and 31.
If the date falls between 12/16 and 3/15, ... |
I have a dictionary which I use to lookup my binary and ASCII values (from A - P). It works, but my ascii2bin function just doesn't really feel right (and beautiful). Is there is a better way to write it?
The ascii2bin function splits a 2-letter string (i.e. 'LA') and looks up the keys in the dictionary. Then concaten... |
Given two int values, print whichever value is larger. However if the two values have the same remainder when divided by 5, then the print the smaller value. However, in all cases, if the two values are the same, print 0.
This is what I have so far:
public static void main(String[] args)
{
Scanner scan = new Scanne... |
I have two implementations of a function that prints out a basic board for Tic-Tac-Toe.
Which of these should I include and why?
def display_board(board)
for i in 0...9
print " #{ board[i] }"
if (i+1)%3 != 0
print " |"
elsif i != 9
print " \n#{'-'*11}\n"
end
end
end
def display_board(... |
I want to show users what package they are, based on how many items they have in their cart. The code works, but I'm wondering if anything can be improved.
function new_thing (){
//decleare variables
global $x_subs;
$lim01 = get_option(woomps_limit01);
$lim02 = get_option(woomps_limit02);
$lim03 = get_option(woomps_l... |
Here is my attempt at implementing the Acyclic visitor pattern from here in C++11.
The aim is to obtain an implementation which is easy to use and avoids all the boilerplate as much as possible. I would also like to keep the use of macros to a minimum, to keep the code readable.
To use it, one makes the visitable base ... |
Write a function lucky_sevens?(numbers), which takes in an array of
integers and returns true if any three consecutive elements sum to 7.
lucky_sevens?([2,1,5,1,0]) == true # => 1 + 5 + 1 == 7
lucky_sevens?([0,-2,1,8]) == true # => -2 + 1 + 8 == 7
lucky_sevens?([7,7,7,7]) == false
lucky_sevens?([3,4,3,4]) == false
... |
I recently got interviewed in a company for Senior level position. They asked me to develop auto-complete component (2 hours time limit) using plain JavaScript similar to this.
I wrote below code, which works as expected, but they responded saying that the solution doesn't match expectations. Please help me figure out ... |
I wrote a program that should check a dictionary that contains about 50000 other dictionaries. In those dictionaries, one of the keys has a list of words as value. Now, I iterate over those words, finding the words most similar to a queried input. However, it takes quite a while for it to finish. How can I speed up thi... |
The aim is to duplicate and append each .grid__item into the .gallery element. The following code was my first instinct, and works fine, but can't help wonder if there is a more efficient way to write this. My concern is when the element count gets up to a high amount, that there will be some delay.
Generate Dummy Elem... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.