instruction stringlengths 71 95.1k |
|---|
This is short Angular 5 code which works as intended: check boxes behave like radio buttons - only one can be selected at a time.
Both versions of 'toggleCheckbox' works but I am interested is if there is better, more elegant way to set 'checkbox1' and 'checkbox2'?
template-driven-form.component.ts
import {Component, O... |
I am using Java to create an Android app. I have the main activity read a CSV file, create objects, and then save them into a singleton class so the rest of the activities in the app can access them easily.
This is working perfectly fine but I am not sure if there are some other ways to achieve the same result that are... |
This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone numbers for certain names. If the entry exists, print it and its number. If it doesn't, print out "Not found".
Here's my s... |
The following code is my solution to a code challenge I submitted a few days ago. I got rejected straight away with no feedback and I've wondered why.
Here is the full code repo.
Requirements
The application is a simulation of a toy robot moving on a square
tabletop, of dimensions 5 x 5 units. There are no other obs... |
I'm doing some recreational programming in C (after spending some time in C++, but professionally using only PHP/JavaScript).
I wrote a UTF8 to UTF32 converter and just wanted to know if I made some obvious mistakes. (For example, is it a big no-no to malloc inside a function (because of possible memory leaks) – and if... |
So I am working on writing a discord bot with discord.py.
I decided, rather than making a serie of if/elif, to map the messages to the functions in a dictionnary, like so:
my_dict = { "!trigger": func }
I then wanted to parse this dictionnary into an async for loop, but ran into some problems. To face those problems, I... |
A few notes:
There is currently no non exception-based way of knowing whether a key is present in the table or not. This is intentional for my use case.
Unlike the lookup process, the baking process is definitely not appropriate for a real-time application. That's ok as it's meant to be run offline.
Obviously, this is... |
This function word_break(s, dictionary) receives a string s and a set of all valid words dictionary, and must return all possible ways the string s can be split into valid words, if any.
For example, a string catsanddog with dictionary {'cat', 'cats', 'sand', 'and', 'dog'} can be broken in two ways: cats and dog and c... |
This is a very simple ball game in which we have to avoid projectiles falling from the sky. This is my second project and first game. Please review and tell where I can improve.
import time
import random
import pygame
pygame.init()
#colors
black=(0,0,0)
white=(255,255,255)
red=(255,0,0)
green=(0,255,0)
blue=(0,0,255)
... |
This is a school project I've written. It works, but I feel it could be done better.
The program generate an array of 1'000 random numbers, and searches for a number typed into console, and displays the index if found.
int inp, zuf, i, num, trig=0;
const int amount = 1000;
int arr[amount];
cout << "Numbers" << endl <<... |
Its meant to password protect python scripts by using encryption
It should use os.urandom(40)'s output in hex as the salt. The kdf (cryptography.io) is using Scrypt (cryptography.io) password input is using getpass.getpass. It's on my GitHub: Python Script Locker (GitHub), and is required to work with both Python 2 and... |
Here is a class I wrote to provide a user a way to have a callback function executed at some defined frequency:
Task.hpp
#pragma once
#include <memory>
#include <functional>
class Task
{
public:
Task(const double& _hertz, const std::function<void()>& _callback);
~Task();
void SetCallback(const std::funct... |
I wrote a program that, given a string of text, converts it to Title Case based on certain criteria. I would mainly like to know how I could improve readability and expressiveness, make a more clear API, and improve the efficiency of the algorithms, but any other feedback would also be appreciated. Here is an excerpt o... |
I'm writing a simple wrapper for std::unique_ptr, which copies the pointed object when copied.
Unlike this wrapper, it properly copies derived classes if
unique_ptr points to a base class.
Also it supports a feature similar to std::visit, which is described below.
(As noted by @Quuxplusone, deep-copying feature resemb... |
I wrote an algorithm that solves this problem but I would love to get some feedback on it (especially since I'm not so confident in my Big \$O\$ skills).
Do you think this is a good quality algorithm? Is it efficient? What would be your impression if you were an interviewer? I really want to improve as a programmer so ... |
I'm trying to learn Functional Programming and I picked Erlang because I will have to use it eventually. In the meantime, I'm trying to build a simple lexer to stumble upon problems and solve them along the way.
I'm aware that Erlang has leex and yeec but this code is just for illustration purposes and teach me the "FP... |
This is a followup to a previous question of mine on same subject.
Context
I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional contiguous array whose sizes are only known at run time. That immediately means that std::arrays are off (compile time sizes), as a... |
The McCabe code complexity of the following function is 19 as found by pytest --mccabe test.py (from my toy-project mpu). While I agree that this function is length and likely will become longer in future, I don't know how to improve the situation.
What it does
The code mpu.io.write(filepath) is a convenience function ... |
I'm visiting a functional programming course at my university which has a small project for examination. The language we are using is clojure and the contents of the lecture have mostly been about it's syntax, rather than the benefits and paradigms of functional programming. Our lecturer doesn't seem to be too harsh wh... |
As a C programming exercise, I implemented a minimal tac program that prints the input line by line starting from the last line.
I'm looking for feedback on my code. Did I overlook anything? Can the style be improved? Did I miss a major issue?
The code is available here or on GitHub.
/*
** tac [ infd [ outfd ]]
**
** ... |
Simple game where you control space shuttle with mouse click and try to avoid meteors moving in random speed toward you. There are some things I am still developing like rotation and menus, but wanted to get some tips/recommendations on what I have so far.
Thank you in advance!
# Import pygame and random
import pygam... |
I tried to literally convert recursive algorithm taught here to iterative, by simulating the recursive stack exactly as much as possible.
I have tested my code and it passed all test cases.
Please let me know if any more improvements are possible.
Here is my code:
public class Graph
{
private int tv; //total verti... |
I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am now writing a queue data structure using linked list from scratch.
I have tested my class that I wrote and everything seems to be working fine but I want to see if there are any bugs or some areas of t... |
I made a simple Hearthstone fatigue calculator. For those who don't know, Hearthstone is a card game in which every turn you draw a card from your deck. Once you're out of cards, you start taking fatigue damage, getting 1 more damage each turn. The total damage dealt in X turns is known as the Triangular Number Sequenc... |
In my Spring MVC app I have User and Role entities.
User:
public class User {
private Long id;
private Set<Role> roles;
// other fields, getters and setters
}
Role:
public class Role {
private Long id;
// other fields, getters and setters
}
I have a service method with the following signature:
@... |
I am trying to solve a puzzle in a performant way. This is the puzzle.
Simply explained: you have a String and you must reduce it to one character with the given rules. This is the solution to the simple variant.
COLORS = set("RGB")
def triangle(row):
while len(row) > 1:
row = ''.join(a if a == b else (COLO... |
I was told my QT Project file is a hot mess. I'm returning to C++ after many years of doing Java and I'm really new to QT. I would like someone familiar with QT Project files to give my code a once over and provide a critique with suggestions for improvement. I have to use install_name_tool to set @rpath after I build ... |
Write a factorial function that takes a positive integer, N as a parameter and prints the result of N! (N factorial).
Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of 0 .
Here's my solution in C++:
#include <iostream>
int factorial( int n ) {
... |
I wrote an algorithm to solve this challenge but would love some feedback on its efficiency and, if you were an interviewer, what your opinion would be on my solution. I believe my time complexity is \$O(N)\$. Is this correct?
The Task:
Given a sorted array nums, remove the duplicates in-place such that
each element... |
I had written code in C++ to create transformation filters to get input, sort (custom_sorting and existing sorting routine) and write the output to stdin and file. When I presented it to my teacher, he ran it on a considerably huge file and observed that my custom sorting routine took over 5 minutes to complete. He men... |
I created an MVC router based on knowledge of an MVC design pattern.
It will simply take a URL as a string (class/method/params...), then it will instantiate a requested class controller and call its method.
In my class, I call a controller method and then include the view at the same time to display data.
My questions... |
I have to convert a JsonArray to an ArrayList but unfortunately the code below is used very often during the execution of the program! How can I speed it up?
Java:
public static ArrayList CastJsonObject(JSONArray object) {
ArrayList<Cantiere> tm = new ArrayList<Cantiere>();
Cantiere cant;
Client... |
I have a class that handles interactions with a custom rest/json webserver, for the purposes of handling online game matchmaking etc. I want the class to have very simple public functions like Server.Login() and Server.JoinMatch(), so they can be connected up at the UI layer easily. As you will see from the code fairl... |
I have written a simple JavaScript function to make an array reactive (i.e. observable). Is there anything I could improve? What the code does is take an array, a callback and a this value as arguments, then whenever the array gets updated or a value gets added to it, it runs the callback with the specified this value.... |
My new mobile phone is capable of importing contact information from a renamed *.VCF file stored on an SD memory card (https://www.quora.com/How-do-I-sync-contacts-on-Nokia-130). Annoyingly, it does not work very well for contacts with multiple phone numbers or anything not tagged as TEL: or TEL;TYPE=CELL:.
The followi... |
Could you please correct me if I'm not following best practices or code optimizations? It is working fine in test environment planning to deploy.
Trigger does two tasks:
Gives an error when trying to change case owner from
DS Service Queue
Data Services
RFP, Data Services and Case fields Categiry__c or Sub_Department... |
The question is from here.
Given two numbers N and K where N is the number of nodes and K is the number of nodes to be deleted, delete K nodes whose data is less than their next node's data. If no such nodes exist, delete the last node.
But it is still giving me TLE. I tried all the optimisations that could occur to ... |
After implementing suggestions from my previous questions about SJF, priority and round robin.
Here I have scheduling.h which contains a struct Data and virtual member functions. Then I have derived class for each scheduling algorithm. Only calcEndTime() is defined for each scheduling algorithm. I have asked to enter p... |
I apologize for that title, lol.
I have a Java method that I'm writing where I want to be able to pass in an array of Objects and two interfaces that will be used for lambda expressions that specify a particular value to use for calculation.
It's part of a larger class that I want to use for all kinds of Statistics cal... |
I was recently playing around with some code, and someone mentioned that my code uses too many classes. I didn't realize I've been doing ES6 incorrectly for so long.
I'm having a hard time finding a way to organize my code in a way that reads nicely. I say this coming from a C# background.
Thanks for your time, every... |
Please help me improving this existing, working code. I am not asking you to change what it does, as it handles connections already perfectly as designed by my own specs. I just want the code to be reviewed to be sure.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, ssl
from socketserver import ThreadingMixIn... |
I have a dict with a series of bools to specify if a particular aspect of my program will be run (e.g. settings['A'] and settings['B']).
If they are run the results need to go into an aptly named directory. The directory names (not the entire path) are also stored in the dict (e.g. settings['outputDirNameOut1'] and ... |
I am trying to make a stored procedure and pass some parameters for filtering. As soon as filtering is in horizon, code has to be as generic as possible with as few as possible if, else, etc.
How could I make this more readable? Can I use functions for this?
ALTER PROCEDURE [dbo].[Stats] @network VARCHAR(9) = NULL,
... |
I've implemented a card game called Macau. This is a follow-up from this topic, where I tried to get the game's design right before actually implementing it.
Even if the game is presented on that topic, I will give a brief explanation as it follows. The game consists of a standard-deck that contains 52 cards. At the v... |
Finished my first lone project and I'm wondering if the execution is passable. This is a basic lbs to tons converter. The customer drives on the scale loaded, then dumps the load and returns unloaded to the scale again. We need to convert the leftover lbs to tons. I am wondering if this is a concise way to perform thi... |
This is a follow-up post of my previous question: Displaying JavaScript object's structure on page with HTML which looked at how to display all properties of a JavaScript object on a page similar to how the console behaves in browsers. In this first question, I had figured out how to render object that had cycles.
Rece... |
This is my second attempt after I started to learn about STL. I am oblivious and need suggestions/advices on if there can be improvements made on this code.
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
string LongestWord(string... |
I have this kind of instance method:
def list_records(self,race_type,year=0):
yearnow= datetime.now().year
yearlist = [yearnow - i for i in range(4)]
if not year:
for y in yearlist:
if self.records:
yield self.records[utils.dateracetype_to_DBcolumn(y,str(race_type))]
... |
I have a table in Lua, which contains two 1-dimensional arrays in which each array contains approximately 800,000 elements. I want to serialize this Lua table to file efficiently. Hence, I planned to use Lua C bindings.
#include "lua.h"
#include "lauxlib.h"
#include <stdio.h>
#include <assert.h>
static int do_it(lua_S... |
In order to learn haskell, I wrote a solver for the Infinite House of Pancakes problem.
-- Solve the 'Infinite House of Pancakes' problem.
-- https://code.google.com/codejam/contest/6224486/dashboard#s=p1
import Text.Printf
import Control.Monad
-- Generic solver code
readInt :: IO Int
readInt = readLn
readIntList ... |
I tried implementing a queue using std::vector, using some properties of vector class. Is there scope for further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int fron... |
I write this session helper class to use it inside my projects for managing the $_SESSION variables setup after an user login or logout. It's very simple and after some tests it seems to work smoothly and fine.
The class doesn't have a constructor, this because the needed parameters that are the username and the user ... |
I've built a VBA Excel macro that works on a spreadsheet of duplicated files, and displays only groups in which at least one duplication is owned by the current user.
The spreadsheet lists file metadata, one file per row, grouped with other files whose content is identical, i.e. "duplicated". Each such duplication grou... |
The small bit of code below blits and image to the screen within a class. I call this 4 times to display the image 4 times, each image has a different y coordinate and doesn't need different x but when they are blitted they make the code MUCH slower. I know it is the blitting as well due to the fact that if i just draw... |
I have the following code I'm using to show/hide multiple shape groups in Excel 2016 using VBA and macros:
Sub Pic_1_SA_click()
ActiveSheet.Shapes("Group 23").Visible = True
ActiveSheet.Shapes("Group 71").Visible = False
ActiveSheet.Shapes("Group 19").Visible = False
ActiveSheet.Shapes("Group 20").Visibl... |
This is a functional component that I have developed in React Native for creating a circular progress view.
The code does not use any external libraries, just pure CSS. Article that I wrote while creating this code is here. Github repo. npm package.
import React from 'react';
import {Text, View, StyleSheet} from 'react... |
Merged cells are a PITA in Excel. They prevent doing a lot of actions and make copying columns impossible. So I wrote this little code to change all the merged cells in a given sheet into 'Center across selection'.
I did NOT test against vertically merged cells, but it should not trigger an error (just unmerge them).
S... |
I have written low quality php code, I'm not a good coder ;) Help me, please, to optimise it ;)
This simple code check bitstamp.net exchange rate, compare it with previous rate and print the result.
<?php
function getPrice($url) {
$decode = @file_get_contents($url);
return json_decode($decode, true);
}
$btc = ... |
I come from a C background and am trying to learn Rust. I wrote my first Rust program, to check the battery level on my laptop and warn me if it's low/critical.
It works fine, but I wrote it in a way I'm familiar with and was wondering if I'm missing out on some features of the Rust language that could make this more... |
I wrote a template class for a 2D vector that is intended to provide 2D vector arithmetic to be used in a Physics simulation program. Note that x and y are public or ease of use since encapsulation here would just decrease the readability of code that uses the class.
Is the general style of my code good and does it co... |
So I am making a little script to convert a string of a basic maths calculation eg:
"2+3+4-2+2-12+42"
and it should return the total.
What I have so far :
<?php
function my_operator($a, $b, $char) {
switch($char) {
case '-': return $a - $b;
case '+': return $a + $b;
default: return $a;
... |
This is improved code from my previous question. This mini game which we call "Moon Buggy" is available in beta from the google playstore.
The action is that you control a vechicle on the moon and you defend yourself against evil UFO:s.
I have written a separate class for the UFO which is instanciated once for every... |
Edit: This code was reworked and repostetd under a new question: Generic Skip list implementation in C++ Version 3
This is a follow up of:
Non generic Skip List implementation in C++
If you don't know what a Skiplist is: https://en.wikipedia.org/wiki/Skip_list
I continued the work on the Skiplist. I tried to incorporat... |
I'm trying to develop some templates for common HTML + CSS tasks I've been dealing with. One of which is a general search results list either from client- or server-side.
So far I'm using the following reusable code which seems to be working fine without any noticeable bug:
<ul class="query-list">
<li>
... |
I am currently reading the book C++ Concurrency in Action by Anthony Williams. In chapter 9, he implemented a lock-based work stealing queue and mentioned it is possible to implement a lock-free queue that allows the owner thread to push and pop at one end while other threads can steal entries from the other. So, I imp... |
I made a bare-bones implementation of printf based on an exercise in Chapter 7, problem 5 of "Pointers on C" by Kenneth A. Reek. What criticism do you have of my writing style?
For instance, do you find I added far too many header files in code. Should I add #ifndef guards for the header files? Do you find any of the ... |
Below is LRU Cache class implementation.
# Design and implement a data structure for Least Recently Used (LRU) cache.
# It should support the following operations: get and put.
#
# get(key) - Get the value (will always be positive) of the key if the key exists in the cache,
# otherwise return -1.
# put(key, value) - S... |
I built one JavaScript debounce function. I need a JavaScript expert's opinion if this is the correct way to do it, and if not, then what the flaw is in this current function.
var debounce = function(inpFun, wait) {
var timeout;
return function () {
if(!timeout) {
inpFun.apply(this, argume... |
Problem : A binary tree is given as an input, each node of binary tree contains one integer value. Find the maximum sum of collection of nodes such that following two conditions are met.
if node's parent node is considered for sum, then node cannot be considered.
if node's either of child is considered for sum, then n... |
I build a Tower of Hanoi solver which print the solution as an image
It works as expected but generating the image is relatively slow compared to the time to calculate the answer.
Here is the code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from PIL import Image
def hanoi(disks, source, helper, t... |
I'm trying to poll for newly created files.
Because the FileSystemWatcher class is known not to be reliable (here, here and here), and because it does not wait for the end of a complete file write, I created a new class to get files creation.
The specifications are:
Files should be signaled only when the file write is... |
Any suggestions to make this code better(efficient, style, etc.)?
I also want to know if there is a simpler way to check if a character is a vowel or not because I had to copy and paste "element == (vowel)" like 4 times.
int isVowel(char element)
{
if(element == 'a'||element == 'e'||element == 'i'||element == 'o'|... |
I have a situation where I need to use person's height in different units. Some parts of the system use Inches/Feet some Meters/Centimeters.
I was thinking of a Height value object which would encapsulate different measurement untis, and upon creation calculate and store all supported measurement units and provide acce... |
Requirements
What I need: attach meta information to methods, such that
it is 'easy' to retrieve all such methods for a given class instance
methods can still be called 'in a normal way', e.g. obj.method()
meta-data is accessible from the decorated method, e.g. obj.method.data
IDEs (PyCharm in particular) do not produ... |
I am creating an app (with react native) on where messages can be viewed. On the home screen you can see a badge with the unread/new messages. It shows the badge (after a short delay, you will see this in the code).
Although it works, I think there is room for improvement, so I hope one of you can take a look at the co... |
The problem
You are given a list of \$ n \$ positive integers. Your task is to split the list into \$ k \$ subarrays so that the largest subarray sum is minimized.
The input
On the first line you have two integers n and k; the size of the list and the number of subarrays. On the second line you have n numbers: x1, x2, ... |
I have a database with a number of stored procedures. These stored procedures provide the basic CRUD operations against the data. I'm trying to create a DAO layer with separate DAOs for each domain class (Album, Artist, Genre, Review, etc) which uses a common Base DAO.
Using the Album DAO as an example, this is what I ... |
I often need to update properties using the out parameter of the standard TryParse methods. However, use of a property as out or ref parameter is not allowed. So, I wrote my own implementation of the TryParse method MyTryParse using the generic extension method, which is supposed to work for all standard value types.
C... |
A non-empty zero-indexed string S consisting of Q characters is given.
The period of this string is the smallest positive integer P such
that:
\$P ≤ Q/2\$ and \$S[K] = S[K+P]\$ for \$0 ≤ K < Q−P.\$
So for example, for the integers 955,1651 and 102, convert the numbers
to binary and the function s... |
This is essentially a best practices question about reading a file and making sure it follows a specific format. My current implementation works, but it's a while loop with a bunch of if/else statements. I think it wouldn't be too readable for other developers.
/**
* Request the server to add the theatre details found... |
I have a form, I need to send untraslated values, but as well, I need to get translated ones from Vue to write them down in page.
For now, I ended up creating a 'shadow' property and changing it via the watch function. Note that I'm referencing the SELECT via the custom ref prop and Vue.$refs. So:
<select name="screw[t... |
This is my attempt at a C++ version of Java's LinkedHashMap. Any criticism is welcome.
I implemented important methods. Big thing still to do would be an iterator. First I wanted to get feedback on this thus far:
#include <unordered_map>
#include <list>
#include <utility>
#include <algorithm>
#include <set>
using name... |
I have incremented an integer in the function nextpalin() and converted it into a std::string for finding whether it's a palindrome or not.
If it is a palindrome I return it. The code is giving TLE on SPOJ but working fine on other online IDEs; how to make this code more efficient?
#include <iostream>
#include <string... |
I wrote this code to make sure account numbers (accounting), which are numbers, are stored as text in the range. Replacing r.value by r.text does not seem to work on whole ranges, so I need to loop. Any better idea?
Sub num2text(r As Range, Optional keepFormat As Boolean)
'change numbers to text, optionally leaving the... |
Given a string s consisting of lowercase Latin Letters, find the
first non repeating character in s.
Input:
The first line contains T denoting the number of testcases. Then
follows description of testcases. Each case begins with a single
integer N denoting the length of string. The next line contains the
stri... |
I'm trying to develop some templates for common PHP tasks I've been dealing with. One of which is a general image file upload handler.
So far I'm using the following reusable code which seems to be working fine without any noticeable bug:
<?php
if ( !isset($_POST['submit']) ) {
goto page_content;}
if ... |
I wrote a basic C++ template to manage shared resources like textures and shaders in a 3D engine. The idea is that the cache itself holds weak references to the resources (through std::weak_ptr) and turns it into strong references (through std::shared_ptr) when the resource is fetched from the cache or constructed if i... |
I have made a helper struct in Swift that creates circular icons from a PNG image (a white icon on transparent background) and a background UIColor. These variables are user-definable in my app, and the created icons are used in notifications and Spotlight, for example.
The PNG images are named iconA.png, iconB.png etc... |
I will start by saying this implementation was based on the approach taken with B-Trees in the book:
Introduction to Algorithms, 3rd Edition - Cormen, 2011
The implementation stores all the b-tree nodes in a binary file, and constantly writes and reads from the said file in order to add new ones and to update the nodes... |
I'm designing an isIn method that takes a value:any and checks whether it exists in an array. It's working, but I'm wondering whether I missed any edge cases:
/**
* Checks if given value is in the target array of allowed values.
*
* @param value The value being checked.
* @param target The target value to perform ... |
This MIPS Assembly program will make you access the elements in the 4x4 matrix in either row or column-major order i.e. accessing all elements row by row or column by column.
Output is posted below as well.
Data section has variables declared, Text section has the main function.
This took me several days to put togethe... |
I wrote this code to count the number of amino acids that appear in a proteome. However, I was recently told by someone I could improve it quite a lot to make it more readable and efficient by using dictionaries.
This is the code:
import Bio
from Bio import SeqIO
from Bio import AlignIO
import itertools
import numpy as... |
I am working on a bit of a multiple part project, the goal of the project is to have a spreadsheet full of order data (order number, customer data, products ordered, prices etc) merged so that the duplicate information is grouped up.
The above is an example of what the data looks like when it comes in.
I then got it ... |
I have defined a userdata in Lua (Lua version is 5.1) as shown below-
#include <lua.h>
#include <lauxlib.h>
#include <stdio.h>
typedef struct FloatArray {
int size;
float values[1];
} FloatArray;
static int new_array(lua_State *L) {
int n = luaL_checkint(L, 1);
size_t nbytes = sizeof(FloatArray) + (n - 1) * s... |
The following code is part of my practice in implementing algorithms in Haskell. I'm aware that bubble sort is a bad choice for sorting sequences in real applications.
import Test.QuickCheck
import Data.List (sort)
-- Going from left to right, swaps two adjacent elements if they are not in order.
-- After the first go... |
For an external application I need to send a command as a string, like this:
["START", "1", "2", "3", "4", "STOP"]
Note the double quotes!
I create this command with the following function:
def create_command(amount):
command = ["START"]
list = create_list(amount)
command += list
command += ["STOP"]
... |
I found this question in O'Reilly Data Structure and Algorithm in Javascript:
According to legend, the first-century Jewish historian Flavius
Josephus was about to be captured along with a band of 40 compatriots
by Roman soldiers during the Jewish-Roman War. The Jewish soldiers
decided that they preferred suicid... |
I wrote a program in Python that scans all files in a directory, makes dictionaries with stuff like date of creation and a hash of the contents of a file. Then i scan another directory which is just a copy of the original dir, but with some files added, deleted and changed. My program reports these changes.
import os
i... |
I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence.
For the sake of better time performance I made the function return out of the loop with false as soon as i+1 - i did not equal 1 or -1. I used continue to do this. Here is ... |
I wrote a little wrapper for Google Static Maps API so that I do not pull down from Google Maps if I have already retrieved the address. The below code works, but I wrote it in a quick fashion - not really paying attention to the best practices of golang.
Several questions I have about this code:
- How can I improve t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.