instruction stringlengths 71 71.9k |
|---|
I'm am writing a Linux kernel driver for HD44780 LCDs connected via I2C bus. In my last change I tried to decouple low-level code (which talks to the device via I2C) from device's logic (printing characters, parsing special characters, managing screen geometry etc.). I tried to solve it via a callback and it seems to w... |
Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps.
I set myself a simple challenge to count the instances of each letter in a sentence, ordered alphabetically. ("Hello World" -> "[D, 1]; [E, 1]; [H, 1]; [L, 3]; [O, 2]; [R, 1]; [W, 1]; ... |
I am preparing for a interview for a junior level c# position. I take two arrays and find the common int between both of them. Let me know if you have any feedback.
using System;
using System.Collections.Generic;
namespace CommonElement
{
class MainClass
{
static void EnterArray1IntoHashSet (int[] ar... |
I've recently taken a renewed interest in non-standard languages like Brainfuck and TIS-100. I'm currently writing a Fibonacci generator in Brainfuck which differs a bit in approach from the usual generators already around.
Since my current understanding of the language is very limited, the limited debugging capabiliti... |
We've been hard at work creating a browser-based GUI/Client for playing the Cardshifter TCG for the past week or so. Today, I just finished doing a pretty complicated layout for the chat lobby, along with @SirPython who put together the JavaScript/AngularJS code, which I will include with his permission.
Here's the ful... |
This is a little baffling to me as to why the CUDA code runs about twice as slow as the CPU version. I am just counting all the primes from 0 to (512 * 512 * 512). The CPU version executed in about 97 seconds whereas the GPU version took 182 seconds.
CPU: Intel Core i7 @ 4 GHz
GPU: NVIDIA GTX 960
Any ideas why?
#incl... |
I have created a login script to demonstrate the usage of sessions in PHP. The focus is not on security, databases or encryption. The idea is to exemplify how you can use sessions to protect pages from user access.
Key points to focus on:
Logical structure (return early, missing checks, error handling).
Compliance wit... |
I've been reading Dive Into Python and I needed to actually program something before I forget everything I learned. So, this is my first Python project (apart from trying the basics and playing with console).
I first wrote this using lots of globals but that looked stupid so I rewrote it as a class. It was more-or-less... |
I was going through design questions frequently being discussed in interviews and have found a problem which states:
Consider a company which wants to process salary hikes of its
employees during recession period. As a precautionary measure, instead
of hiking all employee salaries it decided to hike only for the
... |
I recently added this ShaderBatch to my engine, which takes care of rendering objects which share the same render technique (shader), like billboards and lights. I would like you to point out if there are any relevant changes I could make to my class.
PS: Is the term "ShaderBatch" appropriate ?
ShaderBatch.h:
/*
* Sha... |
I have written a function to take some shorthand input and expand it into the full form, for example a-z0-9 becomes abcd...789. I added protection from buffer overflow exploits (knocks on wood), and have covered (or think I have) all and any edge cases that the user could throw at it.
Are there any ways in which my cod... |
I am making a dropdown menu in JavaScript for my website, and recently I decided I wanted to make it a plugin (as in, upload it on the web and make it compatible with other plugins). I am new to making plugins (and JavaScript) and I was wondering what you think of my code. My goal with the plugin is so that all the use... |
I made a custom UITextView for vertical Mongolian writing. It is made by subclassing UIView, which has a subview called rotatedView. This rotatedView itself has a UITextView subview. So there are three views: a parent, a child, and a grandchild.
The UITextView contains the actual text. The rotatedView is a container t... |
I started with my own implementation of an algebraic calculator but ran into issues very early into the process. Then, I implemented the algorithm here. Please provide some inputs on areas where I can improve.
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
class infixProcessor{
public:
... |
I have created this library mostly for a learning experience with sockets and threading.
For this review, focus on socket/threading. Let me know if I properly implemented both. If you want to comment on other part go ahead I'm open to any comment.
I have read this for the threading code.
I'm using lock() and ManualRese... |
I have a switch statement with five cases, and four of them are really similar to the others. How could I properly refactor this code to eliminate the duplication of code?
func appendOperand(operand: Operand) {
let displayedString = amountLabel.text!
if displayedString.last != decimalSeparator {
switch ... |
Recently I've been fiddling with the idea of sending a text message using C. Looking at a few options, I thought that using libcurl to send an SMTP email using TLS for some security would be the best and easiest option. Here's what I would like reviewed:
Method: Is there a better/easier way I could be sending an SMS... |
I want to improve my implementation for the following problem:
You are given an array of n integers. A sub-array is "Negative" if sum of all the integers in that sub-array is negative. Count the number of "Negative sub-arrays" in the input array.
Note: Subarrays are contiguous chunks of the main array. For example i... |
I solved this prime number verifier problem:
import scala.io.StdIn
object Main extends App {
val testCases = StdIn.readInt
for (i <- 0 until testCases) {
val limits = StdIn.readLine.split(" ")
val m: Int = limits(0).toInt
val n: Int = limits(1).toInt
for (j <- m to n) {
var prime = false
... |
I have tried to write a small light weighted php session handling class that use PHP's session_set_save_handler() function to overwrite the default session handling functionalities and usage Database to store the sessions data instead of default files system. It checks for possible session hijacking attempts and renews... |
I am studying multi-threading and have tried to implement a thread pool. Please provide feedback, mostly from multi-threading point of view. I have implemented two pools, one for adding tasks in queue and the other for taking and executing the requests.
PoolManager.java
package com.learn.threading.threadpool;
public cl... |
I have a method which will send a text mail using JavaMail API and I am trying to write a test case for this method which will check if an Exception of type javax.mail.MessagingException is not thrown.
If a MessagingException type exception is thrown, the test will fail, else it will pass.
public void sendMail() throws... |
Last weekend I had an idea: Why not remove dozens of classes by removing all the basic get/set/equals/hashCode implementation of my data object interfaces? I tend to code against interfaces, so I normally end up, for example, with an "Account" interface and at least one implementation (AccountImpl), etc. But most of th... |
See the next iteration.
I was in the mood for some basic AI, and decided to code up an algorithm for solving "\$M\$ missionaries, \$C\$ cannibals in the boat with \$B\$ places" -problem:
Demo.java:
package net.coderodde.fun.cannibals;
import java.util.List;
import net.coderodde.fun.cannibals.support.BreadthFirstSearch... |
I am new to VS 2012 and need to use it with SQL Server. I need to get data from a table in SQL Server 2012 with 500 rows and 15 columns and process the data in it and update another table. All this has to be done in 100 ms.
I tried traditional method with SQL query filling a dataset and then access the table, rows and ... |
We used this VBA code mainly to hide blank rows and unhide non-blank rows. After that, the second code sorts the rows by a defined column value once the worksheet activates. This process takes too much time with this code.
Could anyone help me optimize this code and make it faster? (The worksheet contain an average of ... |
I have written this code for checking whether all leaves are in the same level or not, in a binary tree. Any suggestion or improvement is appreciated.
import java.util.LinkedList;
import java.util.Queue;
public class Methods {
//* ---- Method for check whether all leaves are in the same level or not --- * ... |
My services(or services that depend on services) need to know about a current action group id. To add an extra optional parameter to each service for the id was an idea but in my current environment to difficult and ugly because every service would have to take in the parameter only to pass it to other services.
My sol... |
#include <iostream>
#include "Point2d.h"
#include "Collection.h"
#include "Coordinates2d.h"
#include "graphics.h"
#define PRECISION 0.01
Point2d Approximate(double t, Point2d const & pt1, Point2d const & pt2)
{
double x = pt1.x * (1-t) + pt2.x * t;
double y = pt1.y * (1-t) + pt2.y * t;
return Point2d... |
I have written code to get all urls on a webpage & put them in a set, and would like tips on simple changes I can make to increase its performance.
soup = BeautifulSoup(html_doc)
for link in soup.find_all('a'):
url = link.get('href')
if url is None or ' ' in url or '<' in url or '>' in url:
continue
... |
My webservice class:
public class ConnectionExector {
private Context context;
private static final int WAIT_RESPONSE_TIMEOUT = 3000;
private static final int CONNECTION_TIMEOUT = 30000;
protected ExecutorService executorService;
// to handle thread result
Handler handler = new Handler();
/... |
This is a simple Game of Life implementation, with one neat gimmick: You can specify the rules that the simulator uses to decide whether cells should live or die. Congrats, God!
I'd especially like tips on:
Idiomaticity: As always, I abuse language features, and I'd like help doing that.
Efficiency: After a certain po... |
This code review request is regarding data access layer coding. I have used the method I am about to describe in a few smaller applications, but I am noticing limitations that I would like to avoid in larger applications I am working on.
The specific area of data access I am referring to is reading data and converting ... |
The code is correct, passes all testcases, I am looking for input on cleaning it, readability etc
def insertionSort(a)
return if a.nil? || a.empty? || a.length == 1
sort_index = 0
for i in 1..a.length-1 do
for j in 0..sort_index do
next if a[i] > a[j]
temp = a[i]
... |
I have these two XMLs that I want to merge together based on these conditions:
If any of the element is more than 7 weeks old, it has to be deleted.
If any of the element is newer with the same date (regardless of time), take everything from the new XML.
Sample XML:
<programme start="20150317173000 -0000" stop="20150... |
I have written the following program in Go to mergesort a singly linked list. It does bottom up merge sort and hence does not have to find the mid of the linked list. Please review the algorithm and the code for idiomatic Go.
package main
import (
"fmt"
)
type node struct {
val int
next *node
}
type lis... |
I've concerns about the code below because I'm getting a lot of unnecessary data from my DB and I delete it afterward to only have the "good" data. I didn't find any good workaround to get the data directly from the query.
Basically what I have is like the Reddit comment section. There are comments (post entity) which ... |
Short Description:
I'm working on a "small" project for our finance department. The problem I'm having is managing this large function (at the bottom). It's so large because I'm having troubles reducing the function into smaller parts without either having to pass many parameters along or recalculate some things. Any t... |
I'm working on this code for exam in an MIT Python course. It's working but I'm trying to improve it. What could I do, and what should I avoid?
aDict = { 0: 1,
1: 2,
2: 2,
4: 2,
5: 2,
6: 3,
7: 2}
values=list(aDict.values())
keys=list(aDict.keys())
value_copy=values[:]
uniqe=... |
I just finished writing a simple version control. You register files using "add", and then "com" will save them inside a directory, with an ID attached to it, same ID for all files. With "rev" it will copy back the content of the files, but won't delete any file other than the one in the "commitdir".
package main
impo... |
I scraped some data looking at trajectories of popular posts on Reddit, and now I want to group and histogram them by type. I put this class together in C++ to do so. Characteristics of the data are that they contain a value and a time (treated as y value and x value) for each data point and that the number of data poi... |
In this exercise, I do not want to use any container such as Spring or Glassfish. I am deploying my application to Tomcat. I only use JPA. What I want to achieve is to follow best practices and OOP concepts correctly, and a good separation of concerns and layering.
I have a database table like this:
mysql> DESCRIBE boo... |
Here is an attempt to sum even extremely very large numbers. As the extremely bigger numbers are fed to the method as String type this became possible. This method can accept even negative numbers also. However for positive numbers, the + sign must not be provided too.
import java.util.Arrays;
import java.util.Scanne... |
I learned code about a week ago and I wanna hear some recommendations and stuff I could add to my code. This is a fight system I made for my text based game. Please tell me what I could do better.
import random
import time
import sys
def fight_snake():
fdmg1 = int(random.randint(1,7))
edmg1 = int(random.ran... |
I have written a small class to generate and animate one of those trendy particle webs. I plan to use this as the main background of my personal website, so naturally I'm concerned about the performance.
Currently, Chrome's task manager shows it sucking up anywhere between 10% CPU and 20% CPU. I'd like to lower that ... |
I want some recommendations or something I could add to the game. Please tell me what I could do better or what I did wrong. I made this during the time I learned Python.
import random
num = random.randint(1, 100)
while True:
print('Guess a number between 1 and 100')
guess = input()
i = int(guess)
if i ... |
Main question
I am setting a font for a UITextView that is a subview in a custom view. I only set it if the user didn't specify the font size in the Interface Builder.
I have the following working code
if self.view.font == nil || self.view.font!.fontName != mongolFontName {
view.font = UIFont(name: mongolF... |
I am working on building an RC car/robot with Raspberry Pi and Arduino. I connected Arduino to Raspberry Pi using USB and send serial commands with python. I haven't done much programming with Arduino nor Python.
This just the beginning of this project and would like to get feedback on the code. Is it a good practic... |
This is my first text-based game I made. It's very small because I just learned Python and wanted to start small and then code bigger programs. Please comment on this.
import random
import time
import sys
def fight_enemy(enemy_name, min_enemy_damage, max_enemy_damage, min_player_damage, max_player_damage):
enemy... |
I'm learning JavaScript and have tried making a simple quiz from scratch.
JS Bin
//Define global variables
var count = 0,
zCount = 0,
yCount = 0,
sumPoints = 0,
aQuestion,
allQuest,
aChoices,
bChoices,
allQuestions,
... |
I have a function that takes a description as a String and returns a shortened version of the description.
The shortening is done by checking if a word matches the key of the HashMap<String,String> map and replaces the word by its abbreviation defined as the value in the HashMap. If the word cannot be found it in the H... |
Is there any easier/shorter/better way to do the marked part?
plnkr
<body ng-app="">
Apple <input type="checkbox" ng-model="apple" aria-label="Toggle ngHide"><br/>
Banana <input type="checkbox" ng-model="banana" aria-label="Toggle ngHide"><br/>
<div>
<!-- This part-->
<div ng-show="apple || banana">
You wa... |
Below function checks if a grade exists
----------------------------------------------------------------------------
-- CHECK IF THE VALUES WE PASSED AS PARAMETERS EXISTS AS A ONE ROW RECORD IN THE TABLE
----------------------------------------------------------------------------
function record#exists(
i_m... |
I need to write an IntArray implementation for college. I'm wondering if my code could be better and if it is efficient. In the header file are the methods listed that we need to write.
Header file:
#ifndef INTARRAY_H_
#define INTARRAY_H_
#include <iostream>
using namespace std;
class IntArray{
private:
in... |
I recently created this website for use as a portfolio because I thought it would help set me apart from other internship applicants next summer. I created this website using a mixture of pre-existing bootstrap classes and my own CSS style sheet.
I would be very grateful if anyone would be willing to offer any advice o... |
I created the below script to sent a request to a website, then convert the table in the results to an array of PSObjects which I can work with in PowerShell. This uses some nasty hacks (e.g. using a regex to strip HTML tags from my XML to try to improve the likelihood of it parsing as valid XML), but I couldn't find ... |
Like Twitter and Instagram and others I wanted to display numbers like 1.2K and 3.8M etc. My function works well enough but I would appreciate any input you may have.
function abbrNum (num) {
if(typeof num !== 'number') {
throw new TypeError('Expected a number');
}
var shortNumber;
var exponent... |
I'm stuck on Codechef problem COOKMACH, which asks for the minimum number of operations needed to transform integer A into integer B, where each operation can be either doubling the number or halving it (rounding down). 1 ≤ A ≤ 107 and 1 ≤ B ≤ 107, and B is an integer power of 2.
In eclipse, the code runs in time, but... |
This entire class came out of a chat discussion, and I'm curious on how it looks. (This is like literally 30 minutes of development time.)
The idea is to allow very easy, quick implementations of Google's reCAPTCHA ("I am not a robot") checkbox CAPTCHA algorithm. It only requires minor work from the implementor to make... |
Working on VSDiagnostics, I implemented a tool that adds the default access modifiers to C# code. An example use would be starting with this:
static class Foo { }
And ending with this:
internal static class Foo { }
This is the analyzer:
public override void Initialize(AnalysisContext context)
{
context.RegisterS... |
Here is my code to retrieve a class from a different solution (both solutions are in the same folder) using an XML file:
var xml = XElement.Load("settings.xml");
var query = xml.Elements();
foreach (var XMLProtocol in query)
{
string NameSpace = XMLProtocol.Element("NameSpace").Value;
string... |
This is a follow-up to the other post I made (less than an hour ago) about my Google reCAPTCHA C# implementation: Google reCAPTCHA Validator
This adds support for error messages, so that you can determine why a reCAPTCHA request failed (if an error was returned).
This also fixes a bug if you were to use the ReCaptchaLo... |
I'm very new to JavaScript, so I'm not sure how to optimize the following code (which seems to run fine) further, though I did try to implement a few tips found on the web — such as using local variables for document elements, using do/while loops instead of for, or using join for string concatenation. I've read about... |
My goal is to obtain the nth weekday of a given month. Parameters are a date from a given month and the nth weekday I'm trying to obtain. It returns the Nth Weekday of the month if it exist and returns DateTime.MinValue othewise. For my purposes weekdays are M-F.
Is there a more elegant or efficient way to implement th... |
I wrote a script to turn a file like this one into a colored 2D histogram:
xbins, ybins, xmin, xmax, ymin, ymax
12, 12, -0.1, 24, -0.1, 25.1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0... |
I would like to make this code more elegant and have it written in a more standard manner, but I cannot write anything better with my current JQuery knowledge. So I would appreciate any suggestions to refactor the code below for better performance.
(function ($) {
var Doc = function () {
this._init();
... |
I submitted this exercise for a potential job. I really was hoping to get some meaningful feedback, so I can improve. Instead, they gave me a one line response: "showed a limited understanding of data management techniques and dom interaction." Not sure why they said dom interaction as this has nothing to do with the ... |
Linked:
Google reCAPTCHA Validator: Iteration II
I have also created a simple Google Recaptcha Validation class to handle verification.
I used some code from CodingFusion's post Google New reCaptcha I am not a robot using asp .net, but I have altered it so that it fit my use case, and to make it extendable and reusa... |
I've been thinking about error handling in C++ lately. Exceptions are a great way of handling errors in most applications. However, I work in the games industry where it is commonly accepted that exceptions should be avoided, so I'm looking for a clean and simple alternative. (The validity of avoiding exceptions in gam... |
I have three text fields (DevExpress ButtonEdits set to read only) on a Windows Forms app. They look like this:
They're used by dragging and dropping a single file on each field.
If a dropped file belongs on a particular field (correct file type with legal contents), the file is parsed and its contents are used to p... |
Our quest: Create a big simulation for Conway's Game of Life, and record the entire simulation history.
Current Approach: Cython is used for an iterate method. The history of life is placed in an HDF store, with help from pandas, and matplotlib is used to visually check results.
What I could use help with: While I'd lo... |
I've built a calculator. I would not use angular or bootstrap because I am becoming addicted to them. I also wanted to check for double '.' use, and to limit the screens max text length but did not make it in time.
I am new to JavaScript, CSS and HTML and would like to know how I am doing.
<html>
<body style="font... |
This is my first text-based game I made. It's very small because I just learned Python and wanted to start small, and then code bigger programs. I added some stuff since the last time. Please give your honest opinion.
Here is my original question about this game.
import random
import time
import sys
def fight_enemy_3... |
Out of fun, and to practice my rusty C# skills, I've made a very basic program.
It only has 1 function: When you move the mouse to a side of the screen, it shown on the other side. Like an infinite scroll!
I am totally aware that there are users with 2 or more screens. I'm sorry, but it only works for 1. It's a limitat... |
I'm trying to come up with a script that will add license headers to certain files (depending on extension). My Bash is very average, so any guidance would be much appreciated.
I'm not quite sure what to ask for except for whether I'm making any gross mistakes.
#!/usr/bin/env bash
set -euo pipefail
shopt -s globstar ... |
I'm working on some code examples in 'Automate the boring stuff in python...' to prepare for my first year of CS. I want to know if its better to use an array with random selection below or rather multiple if/elif conditionals to generate output. Any and all suggestions are welcome.
import sys
import random
import time... |
This code checks 2 images' pixels, compares each pixels based on the threshold (<= 7), finds a best fitting watermark image from the system given 6 images, and loads that image next to the cover image.
For a 100*100 watermark image this particular code takes nearly 130 secs to give output.
Please suggest some ways to o... |
Here is the source of the question.
Given a singly linked list, swap the list items in pairs (reconnect
the pointers, not simply swap the values). For example:
Before: A->B->C->D
After: B->A->D->C
Revision 1
Revision 2
Revision 3
Revision 4
This revision is available on GitHub.
I decided not to delete my iterator... |
I'm trying to make a program that will create an account on Reddit using an HttpWebRequest. I ONLY want it to do that. (I don't care about it storing a cookie or anything else.) I just want it to be a simple program where you type a username into Username_TextBox.Text and a password into Password_TextBox.Text and then ... |
I've been looking for quite some time to fix the wobbly spinner issue. Many people made numerous suggestions using fonts / pure CSS / CSS + JS. Unfortunately, none of the proposed solutions were acceptable to me.
The problem with fonts like FontAwesome is that the icon has to be perfectly centered in a container for it... |
What I have is a grocery list. Once I select a grocery by ticking the checkbox, I can select an amount for that product and a unit (unit is referred to in my below code as group). Once I am done, I click save and the values are updated in the database. But for all checkboxes that are unchecked, the values should be upd... |
I'm going to job interviews soon. How I can improve my coding style and write better code?
package com.amoghantarkar.Stack;
import java.util.*;
class ArrayStack{
private int capacity;
private int top;
private int[] array;
public ArrayStack(int capacity){
top = -1;
this.capacity = capa... |
Problem:
Classify the user (such as infant, child, teenager, adult) based on user's age.
Solution
Please run the solution here.
The code snippet written below works well as expected. I want to know if there's a better way to do or refine this.
package main
import (
"errors"
"fmt"
)
func age(urAge int) (int,... |
I am a casual C# programmer, not formally trained in OOP at all; mostly I focus on Transact-SQL in SQL Server, and so when I write C# apps I get grief about the constructs and methods I use. Here is a simple app I wrote for this blog post - it was not meant to be a production app, and performance is certainly not a pri... |
This code basically checks for four types of alarm flags in .ItemArray[5] to .ItemArray[8]. If an alarm flag is true then its corresponding setpoint is checked for realtime value. The setpoints are in .Itemarray[1] to .Itemarray[5] and the real time value is in engValues[i]
If an alarm exists a row is added to a table ... |
I would like to know how to improve the performance of the following query:
SELECT Kunde.Nachname,
Kunde.Vorname,
Kunde.Debitorennummer,
sum(Abmeldestatus) AS Abmeldestatus,
Ab1.Fruehstuck,
Best1.Menu1,
Best2.M... |
Can someone tell me how I can improve this code? It works ok, but I feel that I'm using too many pointers.
#include <iostream>
using namespace std;
struct link{
int data;
link *next;
};
class link_list{
private:
int boundaries = 0;
link *tail;
link *temp;
link *head = NULL;
public:
void add... |
I plan to work on Introsort, which requires a working implementation of heap sort. Also, the heap sort implementation must be able to sort arbitrary ranges within an array, which, in turn, requires some more involved index manipulation.
Heapsort.java:
package net.coderodde.util.sorting;
/**
* This class implements he... |
So, I took a look at the August Challenge:
The top-voted answer is
Racetrack1:
"In the game of
Racetrack2, cars race
around a track bounded by two concentric closed loops drawn on a
square grid. Implement a program that plays this game."
1Links to answer in meta
2Links to wikipedia article of game
and I tho... |
Yesterday I found myself struggling with creating an A * algorithm in Java, but this morning I finally figured it out, so I would love to hear what Code Review has to say about it!
The goal here is not performance since it was a learning exercise. I tried to make the code and algorithm as readable and simple as possib... |
As part of a project I'm working on, I need to measure FPS. In the past, I would do this within the actual project itself, but recently I've been trying to implement more abstract (and reusable) manners of doing such simple things.
So, I built an FpsCounter class that handles all this for me!
/// <summary>
/// A utilit... |
Now I have this Introsort for integer arrays. Basically, Introsort is the same algorithm as Quicksort. However, in the very first invocation of that "Quicksort", it computes an integer threshold that is logarithmic in \$N\$, where \$N\$ is the length of requested range. Whenever Introsort notices that its current recur... |
I created a R package to calculate Pi with a Monte Carlo simulation.
My goal is to optimize the parallel function SnowPi as much as possible. This is the SnowPi.R code:
FSnowPi <- function(DARTS, ROUNDS, proc_num, numprocs) {
retvals <- .Fortran("snowpi", avepi = as.numeric(1),
DARTS = as.integ... |
I made an attempt to implement a Properties File MRU Cache with a limited cache size which are of the most recently used properties can only be held in. A read miss from this cache leads to a read from the file for that particular property and keep it in the cache until it goes out of the limit where other recently pr... |
Here is a simplified implementation to obtain the duplicate words in a text using lambda expressions.
public class FindDuplicateWordsInText {
public static Set<String> findDuplicateWordsInText(String text) {
String[] words = text.split(" ");
Set<String> duplicatesRemovedSet = new HashSet<>();
... |
I am relatively new to Bash, regular expression and stuff.
In a directory, I need to read the last line of all the files that contain the word "fitness", and list (on one line and separated with comas) the first element of these last lines (where elements are defined by spaces), whenever the second element (or any elem... |
In order to learn Go, I've implemented the cat program in Go. I want to know if the code is idiomatic and what could be improved.
package main
import "fmt"
import "io"
import "os"
var errors int
func main() {
catFilesOrStdin(os.Args[1:])
os.Exit(getExitValue())
}
func getExitValue() int {
if (hadErrors(... |
I want to check some timing of my (pre-C11) C++ and wrote a class:
class ScopedTimer {
timespec start_,end_;
std::string name_; /// name of this timer (used in output)
bool active_; /// if not active, no output is printed
clockid_t clock_id_; /// clock type used for this timer
public:... |
Right so I was doing a quick project, and sought a quick way to finish one section of my Python code. I handed it in, but I'm well aware that it's bad code, but I was wondering if there was a good way to condense this code into fewer lines.
def nGen_army(level, strength, weakness):
if weakness == 1:
if lev... |
I have this piece of code, and I want to make if the way I'm calculating the time complexity is valid:
void traverse() {
int currSum = 0;
for(int i = 0; i < original.length; i++) {
currSum = original[i];
for(int j = i + 1; j < original.length; j++) {
if(max <= currSum) {
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.