instruction stringlengths 71 71.9k |
|---|
I made a Morse code translator in Java in which a user inputs a word/words into a text field and the program converts it to Morse code and beeps the Morse code. I have a feeling that my code could be much better, and that it is not efficient enough. Please tell me if there is anything wrong with my code, including effi... |
I have a function that will try to find a bitmap within another bitmap.
If it successfully finds it, then it will return the center point of bitmap #1.
I've only seen negativity towards goto which is what this function relies on.
I would like some help optimizing my function and possibly having it work without the need... |
I'm working on a simple async TCP client server application, i'd like my network code to be reviewed. I really feel that I'm doing something wrong, especially in receiving code.
Interface for client:
public delegate void ConnectedHandler(IAsyncClient a);
public delegate void ClientMessageReceivedHandler(IAsyncClient a... |
I've been working through the fifth edition of Lajoie's C++ Primer and decided to write a CSV reader/writer as my first project. Its main features are:
Able to explicitly call for:
Individual/multiple rows by index and range
Individual/multiple columns by name and index
Able to write new rows using a map<string,st... |
This program implements spell checking by loading a given dictionary file into a trie structure and comparing against a given text file: Usage: speller [dictionary] text. When run, each misspelled word is printed along with benchmarks:
This was part of a problem set with a given mess of skeleton code (speller.c), whic... |
I'm experimenting in canvas and trying to create pan effect. I've managed to pan succesfully, but I'm curious if I'm doing it correctly. Since I've come up with the following code myself, I don't know if there is a better way to accomplish the task.
JSFiddle
var canvas = document.getElementById("canvas");
var cont... |
In the Firemonkey framework of Delphi, there's a feature called Float Animations, which allows you to control real-time "animation" of float values. However, in the VCL framework, this feature is not there.
So I wrote this component as an alternative, called TSmoothMove. I know there's room for improvements, but before... |
This is my first implementation the binary search algorithm. I have tested it and so far it is okay. But I need an experienced eye to review the code and recommend best practices.
bool search(int value, int values[], int n) {
bool x = false;
int *max;
int *min;
int *mid;
min = values;
max = min + n - 1;
m... |
I've written code that will take any basic math sum input as a string (for instance, 2*3+4/4) and solve it. The way I achieve this is by splitting the string into sub-strings, with multiplication and division being done first (based on the regular order of operations). So in our example sum we would be left with 2*3 an... |
This has a couple of twists which I personally found rather awkward... All code can be downloaded in a read-to-run format from here
The problem
Consider a classic interview question: "Find given pairs with a specific difference in a given array"
Here I impose the unique conditions:
The array is non-decreasing
Consider... |
The recurrence function is defined as follows:
\$f(0) = 1\$
\$f(1) = 1\$
\$f(2n) = f(n)\$
\$f(2n+1) = f(n) + f(n-1)\$
I was tasked to calculate the recurrence of a very large number, \$n = 66666666666666\$, using C++. As you can clearly see, the 3rd line applies for even inputs, and the 4th line for odd inputs. If th... |
I've made this validation class in PHP that would take inputs, on initialization sanitize them and validate them specific to the type. It works fine, but I would like to know if there's some bad practice involved and how I can improve it.
I would also love to hear if there's anything that makes the code awful or hard t... |
My friend was asked to implement a hashtable with a binary search tree. I tried practicing it myself, and it turned out to be very verbose. I need suggestions to clean this up!
public class HashMapBst<K extends Comparable, V> {
private class Entry<K extends Comparable, V> implements Comparable<Entry> {
priv... |
Consider we have to pay the usage of a machine with the following hourly cost:
00:00 - 01:00 --> $4 per hour
01:00 - 05:00 --> $1 per hour
05:00 - 22:00 --> $2 per hour
22:00 - 24:00 --> $3 per hour
If we use that machine from a date of x to another date of y with the given weighted time interval w,
var w = new List<... |
I'm writing a tiny networking library for learning purposes and personal use and I'm not sure if my approach to handling reading and writing exceptions and synchronization is correct. Feel free to criticize my code harshly as I want to learn as much as possible.
Reading packets:
@Override
public Packet readPacket() thr... |
The exercise is part of a React course in which I'm currently enrolled.
Description:
The way it shall look on desktop-screen:
How it shall look on mobile:
Here's my solution:
HTML
<div id="display"></div>
JSX
// Manager bundles the single components together.
var React = require('react');
var ReactDOM = require('r... |
I'm writing a parser and I need to iterate through text vertically (down to bottom) and horizontally (left to right).
This alone would be easy but some text parts need to be rescanned by another parser and for this I need to reiterate over random lines or a text range.
I wrote two enumerators.
One for enumerating all l... |
I made a simple web server in C, and I would like to have your opinion on my code quality. This would help me to improve.
#include "signal.h"
#include "string.h"
#include "sys/types.h"
#include "unistd.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "arpa/inet.h"
#include "netdb.h"
#include "stdlib.h"
#incl... |
I need help cleaning up this monstrosity. Basically this is a user helper method that generates an array of cumulative user sign ups per week (start of week == Wednesday) starting 2016-06-15.
So something like this:
[ 1, 5, 9, 22, 34 ]
Where sign ups each week were 1, 4, 4, 13, 12.
In production, this is taking 5 secon... |
I have a list of \$n\$ words, and a corresponding \$m \space x \space n\$ frequency matrix (as a NumPy array). I would like to return a list/array of strings of length \$m\$ where the \$m\$th string is comprised of each word repeated according to the frequencies in the \$m\$th row of the frequency matrix. I have manage... |
I just finished building a simple random Tic Tac Toe generator. The program will display 3 rows of a random numbers 0-1 and will print a message when 3 of the same numbers align. The program works perfectly, to my knowledge.
I am posting this code here in hopes that I can gain some advice/tips in regards to optimizatio... |
I'm trying to make a model for checking combo presses in a game. Given a list of Button (enum) presses, it returns the list of possible combos completed. I tried using a suffix tree, but I'm not sure if this is the best solution. It's also my first time writing a suffix tree, and I don't know if this is the correct usa... |
This is a simple version from the function strstr. It returns the address of the first occurrence of the substring s2 in s1. I want to know possible problems in the code, and how to improve it, in general.
#include <stdio.h>
/* Version of strstr, which returns the adress of
the first occurrence of s2 in s1, else, N... |
Say I'm using Parse Server and utilising the PFObject class from the iOS SDK. Say I want to have a Chat class.
To use inheritance code (design 1):
import Foundation
import Parse
class ChatInheritance: PFObject, PFSubclassing {
init(parseObject: PFObject, chatStatus: ParseChatStatus? = nil) {
self.parseOb... |
This program starts with initial balance and the individual book balances which must match the initial balance to proceed. The user then enters the selections for the day along with stake, odds etc., then the program calculates the new balance with the new book balances.
def main():
def balances(msg):
while... |
I started this project after reading Chapter 3 of Python 3 Object-Oriented Programming by Dusty Phillips. At first I just wanted to create RPG-based objects to practice inheritance, but now I am more interested with seeing how far I can take this RPG project. Just for reference, I'll say that I am a beginner programmin... |
Suppose we have stock price history, and we are allowed to buy only once and sell only once. The problem is to find the maximum profit we can make. Here is my code that I tested for basic test cases. I'm wondering if there are possible improvements for logic correctness.
My major idea is to keep record of in history mi... |
Got bored writing a review on an HTML parser and decided I wanted to try.
So I threw this together to see I could parse an Amazon page.
curl -A 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080313 Firefox' https://www.amazon.com | parser
Look what I found on amazons home page:
Comment: ... |
I am currently using an implementation of the A* algorithm described here.
Currently, when I run my algorithm, my IDE lags horribly and the .exe generated also lags terribly. Using the CPU analyzer, I narrowed down the culprit using around 95% of the available CPU to my PathFind method. I'm not entirely sure where to... |
I just completed BNR's bronze challenge for disallowing alphabetic characters, and would love some feedback on what I did right and wrong, and how I can improve my code for reusability and maintainability.
Here's a snippet of instruction from their book, iOS Programming: The Big Nerd Ranch Guide (5th Edition) (Big Nerd... |
I've recently started working on making my own programming language and I just wrapped up its lexer. I'm too young to take any official training in C, compiler construction, or computer science so I'm having mixed feelings in the quality of my code. It seems rather sluggish when printing but I haven't really found out ... |
Does this code fine for database reusability?
<?php
/**
* Database
*
* Class for handling database connections
*
*
* @category Global Class
* @copyright ---
* @license ---
* @version 1.0
* @link ---
* @since File available since Release 1.0
* @created ---
* @modified ... |
I'm writing a todo app as a test. Having never done Ionic nor Angular apps before, I am not sure if I am following best practices here.
What I have done is try to keep my controllers thin by placing all persistant logic in the model (service?). And instead of hard coding links in the view, I am calling a function in th... |
This is supposed to be efficient code, but it's taking much longer than what a normal insertion sort would take. I can't identify what's the problem with this insertion sort. Is there an implementation problem?
// function to sort a singly linked list using insertion sort
void insertionSort(element_t **head_ref)
{
... |
I created a simple app with Backbone and Marionette. In a view I created an onRender function.
I created a page that displays a Report with a date filter, using a select tag and affect to an input when the select tag is chosen.
I made that with Backbone and JQuery. And for date I'm using Moment.js and Pikaday.... |
I am writing automated tests for a web app and at one point I need to make sure that a user can only engage in activities allowed by a set permission. I have written all the standalone methods that perform the required tests and now I need to group all of them together and test. I came up with something that looks like... |
Problem Statement
Given a list of items each having a type associated with it, group them by the below mentioned rule
The list should not contain consecutive items that violate the Group setting. For example. An item of "Type1" can have a group setting of 3. This means that there cannot be more than 3 consecutive item... |
I'm writing up a game server on which thread-safety is very important, basically for this approach I've decided to move my entire server in a single brain loop which handles everything in a single thread, connections are ran separately in their own separate thread, whenever a packet is received, the brain loop is signa... |
I have a class which will add or edit a child. So whenever I click on "save," I need to check the child image. If it's an image, then I need to upload to the image server. Once that's done only, I need to save all other data to the data server. Here, I am looking for better names for methods save() and updateChild().
... |
As part of my VBA Sync Tool project, I need to partially decode files describing Microsoft Office Forms (file format description on MSDN). The file format has lots of structures following a template similar to this one:
Where
cbForm specifies the combinaed size of PropMask, DataBlock, and ExtraDataBlock
PropMask is a... |
I was searching for a implementation of a Linked List with the same power as a native List.
I wanted functionality closer to a List. The System.Collections.Generic.LinkedList misses some methods I'm used to work with, like Add Sort or access by index mylist[0]
I didn't find one so I made one of my own:
I added the sa... |
I have written a helper class to manage callbacks from Firebase's asynchronous calls. Can this be implemented in a better way?
public class FirebaseHelper {
private static String TAG = FirebaseHelper.class.getSimpleName();
private static FirebaseHelper mFirebaseHelper;
private DatabaseReference mDatabase;
... |
I just implement Dijkstra's algorithm in C99. Can you review my code please? I'm looking for any mistake, performance improvement or coding style errors.
main.c
#include "src/map.h"
#include "src/pathfinder.h"
int main() {
map *map = init(createTuple_2(11, 11));
addBegin(map, createTuple_2(1, 1));
addEnd(map, cr... |
The puzzle consists from something like this:
You will receive an array of integer with values, then you will receive X numbers. Each number (call it x) represents an index of a 1-indexed array. Look up the value in the array (call it y), then subtract 1 from all the values in the array in the range [x-y, x+y]. The min... |
I'm an Android newbie. I have this function in my code:
private boolean isLoginNeeded() {
final CookieManager cm = new CookieManager(this.getSharedPreferences(shared_prefs_file,
Context.MODE_PRIVATE));
try {
cm.getCookie("recordar");
} catch (Exception e) {
//Remember me cookies... |
I lately got interested into betting systems, dice strategies and algorithms. I took some time to think about it and eventually ended up with an algorithm of my own.
Considering that I don't have unlimited money that would allow me to test it on a real dice betting site (duh), I have coded a simulation that allows me ... |
I have been messing around with practicing some c++ making a little console game, and I would like to receive some advice and tips on how to improve my code.
Some of the code is not done, meaning that some of the functions are not done and some are not called but I have tested it and it does all works.
Some of my conce... |
I implemented two versions of a Fibonacci heap one using a unordered map (mapping keys to their nodes) so that the client can call decrease in \$O(1)\$ average and amortized time. The other one with a dynamic array of nodes and a maximum size for the same reason but in \$O(1)\$ amortize only. Both seem to be working fi... |
I am using the AES class (which I think I got from another post on Stack Overflow) for encrypting strings to a database. How robust and secure (would it be easy to break) is this class? Is there any way I can improve it as it is storing usernames and passwords?
Please be gentle as I have to be honest although I have sp... |
Currently I'm pushing multiple inputs to a array but this is a lot of repeating code, how can I improve this?
var tickets = [];
$('.js-ticket').each(function(){
var ticket = [];
ticket.push($("input[name='ticket_naam\\[\\]']").map(function(){return $(this).val();}).get());
ticket.push($("input[na... |
Working on a problem, for a given input sequence to a stack, check whether it could produce (using stack push/pop operations) the output sequence.
For example if input is [1,2,3,4,5], possible output is [4,5,3,2,1] (push 1, push 2, push 3, push 4, pop 4, push 5, pop 5, pop 3, pop 2, pop 1), but [4,3,5,1,2] is not a fea... |
I recently found out how to use joblib for parallelization. I want to iterate through this string seq in steps of 1 and count the number that word is seen. I thought this would be really fast but for larger files it still takes long.
How could I make this word counter faster?
def iterSlice(seq, start_idx, end_idx):... |
I've created the beginnings of a Twitch IRC bot. As of current, it only has one command (!echo), though the infrastructure is (hopefully) there to library this code and build an actual bot on top of this base code.
This is my first time making a system with this much threaded and i/o operations in it, so I'd especiall... |
I've been working on this task (see screenshot).
Here's my answer to it so far:
var sum_pairs=function(ints, s){
//your code here
var ptr_1 = 0,
ptr_2 = 0,
i = 0,
j = 0,
len = ints.length,
j_min = len,
arr_sum = [];
for (i; i < len-1; i++){
for (j = i+1; j < len; j++){
... |
Input given is an int array, which may or may not contain positive, negative or zero values. Write a
program to find out the two numbers which gives the highest product.
(Both numbers should be positive or negative.)
Below is my code whose time complexity is O(n2), I believe. Is there any improvement I can make t... |
I'm watching Uncle Bob to improve code maintainability and readability.
I've built a system in which can upload various file formats. Bellow I've posted the pdf one.
The below code works perfect but I need help if there is a way to improve code design and quality.
Any suggestion is welcome.
I use an abstract class File... |
In this program, I have to check the range of a given age and then print a message as per the age. I want to optimize the if else logic.
/* Sample code to read in test cases:*/
import java.io.*;
public class Main {
public static void main (String[] args) throws IOException {
File file = new File(args[0]);
Bu... |
I just made a Rock, Paper, Scissors game and I have read some of the previous threads about them. Just wondering if there was any advice to optimize or just suggestions for naming or doing something better for my code. I have learned Java for only about 2 weeks so bear with me if I don't understand some of the function... |
I want to convert my_long_variable to myLongVariable in sed.
This works:
echo "my_long_variable" | sed -r 's/(^|_)([a-z])/\U\2/g' | sed -r 's/^(.)/\l\1/g'
Is there a more elegant way to do that with sed?
|
Our Project architecture is AngularJS + MVC + WebAPI. Angular JS would call MVC action and MVC action further calls API methods. Below are some of the action methods we used for calling api methods.
Note that our project is in its final stage, and as such we cannot modify the existing architecture. We have to use Ang... |
Based on the feedback I have got from the guys reviewing the code as posted in my previous question.
Create database connection and run the insert, delete, update queries class
I have used interfaces and wrote the following code
/* */
namespace SampleInterfaceT1
{
public interface IDbConSetup
{
DbConnection Open... |
Often when running exprimental code to empirically investigate an algorithm, you tweak a parameter, then rerun the code, and generate a bunch of saved models for various parameters.
To make sure I don't loose what the parameters were set to I defined a macro that saves there values.
module Util
using JLD
export @param... |
I'm looking for ways to speed up the process of adding entries to a zip-archive, in a web app, using DotNetZip.
The problem currently is that the response times out before all files has been added to the archive. There can potentially be between 200 - 500 entries in each archive, each entry between 1 - 4 meg in size. I... |
For few days I'm thinking about making my code faster and using less CPU. This code is a statusbar that runs in a loop. I'm asking because there's a lot of perl and I'm wondering if it could be done better.
date=$( date +"%F %R" )
battery=$(acpi -b | perl -n -e '/(\S+),\s+([0-9]+\%),\s(\S*)\s/ && print $1," ",$2," [ "... |
I am creating a simple app to find vowels, digits, whitespaces and consonants. the basic idea is to practice multi-threading and writing readable code.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.scene.control.TextField;
import javafx.application.Platform;
import ja... |
I've been working on refactoring a project of mine and need some help. I'm looking to apply some design principles and patterns to make the code cleaner and easier to maintain. It looks like I'm clearly violating the DRY principle as there seems to be quite a bit of repetition. Also, I think there is a design pattern ... |
I have written this piece of code to check if a string contains a set of characters, regardless of the order.
Eg: 'ruby is best' / 'bysbe' => true
Code:
def find_chars(s1,s2)
s1.chars.sort.join =~ Regexp.new(s2.chars.sort.join(".*")) ? true : false
end
I need to optimize it to reduce executing time. How? What is slowi... |
Since the last post, I have ported it to WPF (semi-MVVM) and added support for Excel and PowerPoint files, and custom fields and scripts.
The conversion is done by interop with office. Apparently consistency is too much to ask for from Microsoft, and the libraries for Excel, PowerPoint, and Word are all slightly differ... |
I'm trying to find out if it is possible to simplify my framework a little bit more. The current solution works, but it does cause some code duplication for me and some other issues that might come down the road.
public class Browsers {
private String Browser;
private String Windows;
private String Ver;
prote... |
This is a simple script that moves files to S3 if they are > 14 days old. It ignores files that are < 14 days old. If the file is successfully synced to AWS S3 then we can remove it from the server. If not, we leave the file where it is. The echo commands in the script are for debugging. I am aware that this could be a... |
So I was coding Prim's algorithm for practice and this is what I wrote. It works for finding the weight of the minimum spanning tree (MST) but I'm wondering if the loop I am doing to add the the edges in the frontier to the minheap is optimal.
import heapq
from collections import defaultdict
g = defaultdict(list)
weigh... |
I have two lists that I need to intersect. This is what I'm doing.
var dfuDevices = _dfuMonitor.GetDevices();
// new devices
dfuDevices.Except(Devices).AsParallel().ForAll(device => {
if (device.GetType() == typeof(DFUDeviceModel)) {
OnDfuDeviceDetected(device);
}
});
/... |
The game is designed to be a sort of foundation for any other projects I make.
#main --- This is line zero
import sys
import time
import areas
import items
def menu():
while alive:
print("\n")
menu_input = input("> ")
if menu_input == "inspect":
if position == areas.east_sword... |
Did this challenge for an employer (not under an NDA or anything) for a junior python-related position and wasn't selected. Unfortunately they couldn't offer feedback, and as this was my first stab at doing something in python, I really have no idea if maybe I missed something and it's not totally correct, or maybe it ... |
f-strings is a new feature in the upcoming python release which basically lets you do this:
>>> s = 'qwerty'
>>> f'{s} {1+2}'
'qwerty 3'
Not pleased at having to wait until f-strings are widely supported, I came up with the following function, which should work for any Python version starting with 2.6.
def f(s):
r... |
I've been experimenting with different ways of reusing (and naming) the expressions I use in Entity Framework. I've tried static fields with Expressions and extension methods but neither are perfect. In my latest attempt to solve this problem, I'm attempting to implement the specification pattern!
Firstly, I created a ... |
This is a follow on to Part 1
In order to use my new Specifications within expression trees so I can use them in projections/navigation collections I had to write an ExpressionVisitor to find Specifications and replace them with their Expression.
In order to convert an IQueryable into one that supports the specificatio... |
I have it running well and would just like any suggestions.
Note: Yes I am using global variables and would like to keep it that way, at least for now. The reason is, that I am using The Great Courses to learn computer-science concepts, and the instructor insisted on using Global Variables...since we haven't learned ab... |
What I am essentially doing is writing a snake game that everybody could play on the internet, broadcast their game if they like and so on. Now it looks like this, just websocket-based snake, no user authentication or everything. Pure and simple as possible.
Well, does my code follows best practices of coding both on s... |
This script is part of the Cameleonica project, which aims at creating a versatile filesystem. This script measures performance characteristics of a disk: how long are seeks on average, and so on.
I would appreciate if reviewers would also upload their output to gist, if convenient. I only have access to 2 hard disks ... |
Let's say I have following action:
export function signIn(data) {
return {
type: USER_SIGN_IN,
promise: api.post('/sign_in', data)
}
}
and the following middleware:
export default function promiseMiddleware() {
return next => action => {
const { promise, type, ...rest } = action
if (!promise) {
... |
I was wondering is it OK to change implementation of parent class with child class data. I have situation of creating a child class (form) which extends the parent class (other form with same elements). If I don't change implementation of parent class some HTML Elements will have the same id and both forms are on same ... |
Here's some code which, given a list of \$N\$ movie lengths, checks if there are two movies that equal the exact length of a flight. This solution runs in \$\mathcal{O}(N)\$ time since I used a hash table.
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
const int L... |
I just wrote this function for personal use only while working on a specific data project. I would be grateful for any feedback!
get.coef1 <- function(x) {
x <- as.character(x)
m.names <- paste("fit", x, letters[1:3], sep="")
models3 <- matrix(numeric(12L), 3, 4)
for (i in 1:3) {
models3[i, ] <- summary(get... |
I am new to programming and I would like some feedback. This is my first ruby program that simply adds a + b. I know it's probably more complicated than it needs to be, but I wanted to implement ideas that I was learning. Is there anything that I should do that I didn't or did that I shouldn't?
puts "<<<-----ADDITI... |
I recently answered a question that had me wondering if I could simplify this below code without creating an extra function:
for object in objects {
if let type = object["type"] where !type.isEmpty, let name = object["name"] {
print(pokemonTypeDefenseChart[type])
for weakness in pokemonTypeDefenseC... |
Given a list of time intervals, I want to return the intervals with the most overlaps (i.e. most people free). My solution runs in \$O(n \log n)\$, but I made a bunch of "tracker" variables. How can I avoid creating all these variables?
Interval class:
public class Interval {
int start;
int finish;
public ... |
This is the application for small school, which will store students' info in Firebase and also retrieve data from Firebase. I am using JSON Parser to parse the data and save the same in Access tables.
I am using this function in MS Access to connect to the Firebase. Please tell me if I am doing anything in an inefficie... |
Here is my code to print tree in a level by level way. It needs to print an empty node as well to keep tree structure like full binary tree for elegancy reasons.
I'm wondering if anything you think could improve, including the efficiency and not sure if any bugs (I did testing, not found bugs). I'm especially wondering... |
I have multiple services with a lot of methods. Every method returns an int as a result code. All methods have 2 types of signatures:
Only with IN params
n of IN params and m OUT params in the end (in most cases 1 OUT param)
Up until now I came up with this solution:
#region Decorators
#region [Getters]
#region [Vo... |
I am working on an angular application. I have written a controller for a page which gets 10 objects from an api. On clicking the next button, it gets the next 10 objects and so on. I have also added a search box in the same controller which also gets 10 results of the searched term and on clicking the next button it g... |
I've been learning about unit testing with pytest recently, trying to figure out what is and isn't a valuable thing to test. I'm very new to it, so I thought a review would be a good way to learn about holes I'm leaving and mistakes I'm making.
So, I'm primarily interested in the test functions being reviewed, though I... |
I've decided to write a common Makefile for Google benchmark library. You could say I could have taken generated Makefile, but it's not appropriate solution (or maybe I'm wrong?).
TARGET = libbenchmark.a
CXXFLAGS = -std=c++11 -Wall -Wextra -Wshadow -Werror -pedantic \
-pedantic-errors -Wfloat-equal \
... |
I'm writing a sub-routine in AppleScript to get text from a file and insert that text in a list of lists forming a dictionary.
Text File:
a:b
c:d
e:f
Expected list:
{{"a", "b"}, {"c", "d"}, {"e", "f"}}
Here's my code:
on getDictionary(filePath)
set dictionary to {}
set dictionaryFile to paragraphs of (read P... |
So I have created this function that will add a disk if needed and it takes a disk and a size as inputs. The idea is that I need to update data.disks with a few properties. Disk is called from an external request and it follows the pattern of "disk1", "disk2" and so on. Looking at it there are a few hard-coded values a... |
I have some basic code which registers functions, with given variables, to be executed after a certain time has elapsed. I will roll this code into my software project when it is ready. If it works it works but since I've never done this before I am the Padawan and one of you out there, who's written code like this bef... |
Any idea to write this code more smarter and shorter? I also expect your advice about general organisation of the code.
Object of the Game
In your version of Mastermind, the computer will be the codemaker and one player will be the codebreaker. The computer picks a sequence of 4 pegs, each one being one of any of size... |
I was trying out my hand at solving problems and came across this HackerRank problem. I have written a solution which passes for a few test cases but times out for most others (time limit - 3 seconds). I'd like to know the best way possible to achieve the same.
Any pointers as to how the code may be optimized, any appr... |
Given:
def rights[A, B](xs: Seq[Either[A, B]]): Seq[B] =
xs.flatMap {
case Right(x) => List(x)
case Left(_) => List.empty
}
def lefts[A, B](xs: Seq[Either[A, B]]): Seq[A] =
xs.flatMap {
case Right(_) => List.empty
case Left(x) => List(x)
}
def combine[A, B](xs: Seq[A], ... |
I have a MEAN Stack app in which I have been using mongoose routes to update my data. Some of those routes have a lot of back and forth in terms of updating data across multiple users and collections. So I used the standard mongoose callbacks to handle them. It all worked perfectly but it turned into Callback Hell! So ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.