instruction stringlengths 71 71.9k |
|---|
I am trying to learn how to write more object oriented javascript code, but I am having a hard time understanding the correct way to do it, and how it is useful for front end development. As you can see below, I tried to rewrite my old javascript code to be more object oriented, but it just doesn't seem necessary for w... |
I am working on a simple Texas Hold'Em dealing simulator. I am new to Python and was hoping to get some advice on my use of classes here. I feel like I am not using them as efficiently as possible, especially when dealing out the player cards. Specifically, I feel like the def deal(self, n_players) could be simplified ... |
We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return true if it is possible to make the goal by choosing from the given bricks.
bool make_bricks(int small,int big,int goal)
{
if(big > 0)
{
double test = (double)... |
In perl, there is that format facility for console output. I thought it might be good to practice some library design instead of algorithms once in a while. This may be compared to a GUI library: you start from an empty window, add some lines to it, add labels and other stuff to each line and so on. At this point I hav... |
SPOJ problem PRIME1 (also found on other sites in identical form):
Input
The input begins with the number t of test cases in a single line
(t<=10). In each of the next t lines there are two numbers m and n (1
<= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime num... |
I'm having trouble optimizing the Project Euler problem #43 :
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.
Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this w... |
I have some code that needs to access an API that requires OAuth authorization in the form of a token, and every time the token expires, it needs to be refreshed.
I made a function called _fetch() that wraps the API calls that I'm making, and will both authorize the requests, and automatically refresh the token if it h... |
Looking for code review, optimizations and best practices.
Node.java
class Node {
Node next;
int data;
public Node(int value) {
data = value;
}
}
Palindrome.java
public class Palindrome {
static Node reverse(Node head) {
Node prev = null;
Node current = hea... |
I want to make a vertical cycle slideshow. This works perfectly for me but I'm just wondering if it's possible to achieve the same functioning with a better code. I don't know if my code would provoke a problem in some situations or not.
jsFiddle
var pare = $('#slider'); // selecting the holder element;
var ob = $('#sl... |
I wrote a Brainfuck interpreter in Python and I'm wondering how to simplify it.
I handle separately loop commands and the others. A recursive function deals with loops.
import sys
array = [0] # byte array
ptr = 0 # data pointer
Read and execute commands except loop
def readNoLoop(char):
global ptr
# Increment/... |
I'm creating a relatively simple type-safe and thread-safe Rust event system. It is to be used with and within an IRC library I'm making, but should work just fine for other use-cases. It needs to be reasonably good and safe. Using it might require lazy-static, which makes me slightly worried, but even then it should b... |
I have written simple code to construct a graph, but I think there are too many different types for such a simple task.
In this code I need to store Node structs in the Graph instead of pure values because it encapsulates some logic. The user should not know about Key. The user will be working with references to nodes.... |
Recently I was experimenting with QTableViews and I wanted to create something where I can add a new row to a table without having any additional button/menu item outside the table. I achieved this by adding a single item to the view's model and set that not editable. Then if a double-click happens on the table I check... |
I'm using Rails 4.2.5, and I'd like to update existing records with a csv file with two fields: id,category. Where if the category field is blank, it defaults to misc.
Here's an example csv file:
id,category
123-123-123,0
123-123-124,1
123-123-125,
123-123-126,2
So, I've created some tasks, update_item_categories, and... |
Rob is looking to buy a used pickup truck. He will spend a maximum of
$10,000 but would like to spend as little as possible. He will spend
up to $3000 for a 2000 or older model, $5000 for a 2001-05 model,
$7000 for a 2006-09 model, $9000 for a 2010 or newer model. Rob will
not buy a red truck but he will pay 2... |
Assume the built-in function Ascii(c), where c is a one character
string, will return an integer containing the ASCII value of that
character. Write a function that accepts a string, uses Ascii(c) and
additional processing to produce a one way hash value from the string,
and returns the hash value as a string.... |
Scenario
Currently filtering through a list of ~3100 rows of data presented to the end-user in the form of an index (think, list of car models).
This is done in such a way that every item is available in a long list to the end-user however they have the possibility to filter down their results into something more rele... |
The following is an a self-tutored attempt to take a leap into understanding simple usage of wait() and notify() methods.
The code is responsible for scanning a directory structure with each directory being scanned by a new thread, for the files present in it. All results to get accumulated in a data collection and dis... |
project is the data frame. For the purpose of the code, HOUSE.NO is a column of the type character, and NO..OF.FAMILY.MEMBER is another column of the type integer. My aim was to find out the house numbers which repeated, and then find out if the no of family members reported for each of the house matched, and identify ... |
After coming across Douglas Crockford's views on class-free OOP, and doing away with new and this in Javascript I tried defining an object with its own variable and function, and returning it in JSON, as shown below:
var newObj = function (name, lang){
var obj = {
"name":name,
"greeter":gree... |
Sometimes, we have to do some fixing to insert a string into an HTML property. Or just to display it.
But not everything is safe! Consider the following example:
document.getElementById('name').innerHTML = prompt('What is your name?');
This allows to introduce HTML vulnerabilities quite easily. Specially when you wa... |
The method toggle of Element.classList expects a parameter which names a CSS-class.
You can't assign multiple classes at once by using for example an array.
So you have to write something like ...
div.classList.toggle("hidden-element");
div.classList.toggle("border-defs");
div.classList.toggle("green-theme");
Therefo... |
Kindly accept my apologies as Java is something my mind cannot digest no matter what I do. At the moment I have an assignment and have written a piece of code and have used Constructor (I think so) but not sure if I have used it correctly and if Yes then will need some guidance in order to refactor the code.
Anyhow I ... |
I have a query consisting of UNIONs.
SELECT CONCAT("You sent track request to ",u.username) AS ACTION, h.`dateTime` FROM login_user u
LEFT JOIN
history h ON u.id = h.`toUserId` WHERE h.`fromUserId`=28 AND h.`Action`="Request"
UNION
SELECT CONCAT("You Accepted track request from ",u.username) AS ACTION, h.`dateTime` ... |
I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key.
Can you help me understand, compare the modulo approach with my attempt to use a tree?
import random
import hashlib
from collections import defaultdict
i... |
At the moment, prtscn takes a server, and a list of port ranges to test (of the form x,y-z,a-c,d,e etc). The -v option will show all ports being scanned, and the -r option will return the first open port in the list. If -r is passed, the list of port ranges is optional. In this case, if the port list is missing, -r wil... |
My goal for this script was to:
Create new folder
Create AD group FS-TESTSHARE-R
Create AD group FS-TESTSHARE-RW
Apply both groups to the new share folder
Set full read permissions to FS-TESTSHARE-R
Set full read/Rights permissions to FS-TESTSHARE-RW
Set full access permissions for local machine admins and domain admi... |
One of the most annoying things about the VBE (VBA's IDE), is that it doesn't have a status bar.
Rubberduck 2.0 works around this by introducing the RubberduckCommandBar, which [ab]uses msoControlButton controls as though they were labels - the command bar constantly resizes as the text changes, but at least we get to ... |
The following code is for my Object Oriented Programming class. My program simulate the cashier's machine to order food. The code uses Model View Presenter. This class is the model.
I have an ArrayList to hold the possible order possible. The View uses it to create JButtons.
I have an ArrayList to hold data to know ... |
This method finds the common ancestor of two nodes in a binary tree.
Any style suggestions or ways to make it more idiomatic? Is the algorithm correct? Rubocop says the cyclomatic complexity is too high, how would you break this up?
class Node
def initialize(value = nil, left = nil, right = nil)
@value = value
... |
Below is the code for, Singly linked list implementation,
function List(){
this.start=null;
this.end=null;
}
List.makeNode=function(){
return {data:null,next:null};
};
List.prototype.add=function (data){
if(this.start===null){
this.start=List.makeNode();
this.end=this.start;
}e... |
I have a notebook here which details my code and may be more legible.
I worked on a project that flattens a table that initially looked like this (this is table1):
18+fem 18+male date station
17118 15925 12/1/2014 ADSM
16006 11379 12/2/2014 ADSM
19259 18846 12/3/2014 ADSM
16386 17068 12/... |
I am suppose was to incorporate arrays in my NIM game java code, so that we can allow the user to decide on how many heaps are in play. I am stuck and have no clue how to do so.
Heap Class
public class Heap {
private int heapSize;
public Heap(int size)
{
heapSize=size;
}
public boolean remove(int size)
{
bool... |
Link to sanitized xls on dropbox if test data is needed
Essentially the reports I work with aren't bad -
The issue is the way it exports to excel -
With the problem being that these cells are filled with LF characters breaking apart the data entries in the cells (usually a listing of employees in format empID / emp n... |
I wrote a small header that is supposed to take care of calling the right strtoX or or stoX function for me and doing so at compile time. The code contains two functions: num_cast and string_cast. Each returns a number or string from the argument specified. See main for an example on how to use this.
I'm looking for re... |
The code does the following:
Gets an array of objects and filters them according to some properties
Returns the array of objects with the filtered data
I'm using the following code which is working and I wonder if there is a way to write it better.
By the way, I can use LodashJS if it's helpful here.
filterNullUndefi... |
I'm creating a Pong clone for use in teaching JavaScript to beginners. Unfortunately, I am largely a JS beginner myself, so I probably missed something in the below code; however, I do not want to shortchange my students.
Also, the code does work as intended (with the exception of the sound-playing code, since I couldn... |
I built this game that I used to play at family get-togethers. I am still working on the final implementation of how to actually play someone in the game. Please critique the main logic of the dice and how I find the values.
var dice1 = new dice(1);
var dice2 = new dice(2);
var dice3 = new dice(3);
var dice4 = new d... |
CGbR project
I am currently working on a project that generates code from classes. The idea is to achieve maximum performance by replacing reflection use cases with fast, generated code.
Current results look good, but I want to take this chance to find room for further improvement.
Class under test:
[DataContract]
publ... |
After a lot of research, I created this wrapper which I think fits very well to my needs. My project is a TCP server and I will be using this wrapper every time the server receives a packet. Basically, the wrapper will work marshaling raw byte[] into higher-level representation of the data as marshalable structs.
What ... |
I have a school project to create a program that works the same as the Linux cat. The code works, but I just need find out where I can Improve it or handle errors. The program has 3 .c files and 1 header file. I'm also not allowed to use system functions; I have to use read(), close(), open() and write() and while loop... |
Here is my previous question:
Java Tic-Tac-Toe game (implemented through MVC)
I'm reposting again because I made a lot of changes to the code. I wasn't able to implement everything as I don't know some of the stuff, but I tried to do as much as possible.
Summary of changes:
View doesn't have as much logic now.
Model h... |
I'm solving the following problem using the Chain Of Responsibility design pattern in Swift:
Not all mechanics are created equally. Some mechanics are more
experienced and can do more than others. We need a system where every
job is propagated from the least experienced mechanic to the most.
This way experience... |
The following converts Arabic numbers to Roman numerals.
I decided to factor each digit into its place value, then use a mapping to convert it to its Roman equivalent.
For example, 1997 is factored to:
\$(1 \times 10^3) + (9 \times 10^2) + (9 \times 10^1) + (7 \times 10^0) = 1000 + 900 + 90 + 7\$
The Roman numerals fo... |
I'm solving the following problem using the Mediator design pattern in Swift:
Assume we track the location of all our mobile mechanics. We have
noticed that there are times when a mobile mechanic might need
assistance from another mechanic or a last minute need for a part that
someone else might carry. We want t... |
I'm just messing around with class inheritance. I originally had a separate goal in mind but I ended up here, and my new goal was to have a parent that was completely ignorant of it's self, i.e. no default attributes. This would seem to make it easier to subclass, the MeleClass could set; for instance canRange to True ... |
I'm looking for any kind of advice, like when or where to do exception handling, the overall library structure/layout, usage of classes/partial classes, code efficiency, naming conventions, and so on and so forth.
Note: Knowledge of cryptocurrency technology would be an advantage.
The following code is the section that... |
I'm writing some code which is basically supposed to http get some information from my own website and parse it, which (finally) works. However, when I compile the code, it shows this:
Sketch uses 14,466 bytes (44%) of program storage space. Maximum is
32,256 bytes. Global variables use 1,281 bytes (62%) of dynamic
... |
I have been coding Java for 5+ years and before that did a little professional C. Picking up C++ again for the fun of it and I feel like I am just writing Java in C++ rather than understanding the C++ way of doing things.
Anyway, I wanted some thoughts on my simple little class to make sure I am C++ing right.
This is m... |
I have this if else block code
if($_POST["item"]=="All"){
$notificatioSetting->AllNotification=$_POST["status"];
}
else if($_POST["item"]=="Accept"){
$notificatioSetting->AcceptTrackRequest=$_POST["status"];
}
else if($_POST["item"]=="Deny"){
$notificatioSetting->DenyTrackReques... |
I reproduced my version of Abstract Factory Pattern in Java. I know it's redundant but can I get critical comments about my code. Is it really the classic implementation of the pattern or not?
/*
* The demonstration of Abstract Factory Pattern
*
* Here the 'DocumentFactory' creates documents of types
* 'Resume' or 'L... |
I wrote a simple function to determine if a year is a leap year or not. It works, but does not feel idiomatic.
isLeapYear :: Int -> Bool
isLeapYear year =
(mod year 400) == 0 || ((mod year 4) == 0 && not ((mod year 100) == 0))
Is there a more "haskelly" way to write this function ?
|
I am currently discovering Golang, and I try to implement some random variable generation functions similar to R functions.
To avoid code repetition, I'd like to use inheritance, which is quite complex with Go at first sight.
Each variable implements a x.R() method, which generate a random value following x distributio... |
I'm developing a website and I cut the images that I will use:
<div class="news-top">
<p>CSS contains the top image</p>
</div>
<div class="news-center">
<p>CSS contains the center image (repeat-y)</p>
</div>
<div class="news-bottom">
<p>CSS contains the bottom image</p>
</div>
And inside news-center class ... |
I am building a simulation where you have 'Agents' distributed over a rather large landscape. Because the number of Agents is small, compared to the size of the landscape, I use the PIC approach where the landscape is divided into rather large cells and every cell can contain multiple agents - in contrast to a classica... |
Can this code be made more like idiomatic ruby using methods such as map or inject?
@random_tour is a variable length array of points on a graph:
[[0, 0], [2, 1], [4, 3]]
I want to calculate the distance to reach each point using the manhattan distance (number of moves horizontally + number of moves vertically).
For ex... |
I have an assignment to encrypt files (+- 1 gb) and speed is an important factor. I am also kinda forced to the C# language since nobody in my group knows C++. The time now recorded for 100 mb is 12 seconds could somebody give me advice if it is possible to improve the speed my encryption function below.
private void b... |
The idea is, you enter an amount of ships, for example 10. It will then place 10 ships on a 10x10 grid (0-9). You may enter a coordinate, and it will tell you if it is a hit or a miss. A simplified version of the well-known board game.
C indicates 'Computer'. These are not shown on the grid, but are stored in the 2D a... |
I have the following structure of a table:
| id | profile_id | sku | vendor | price | importRun |
| 1 | 39 | 123 | myVen | 2.0 | 1 |
| 2 | 39 | 456 | myVen | 2.0 | 1 |
| 3 | 39 | 123 | myVen | 3.0 | 2 |
Related: StackO... |
Here is my script which takes 50k records from a CSV and does CRUD operation with them. Unfortunately there are a lot of issues with the performance.
CSV fields are: msisdn, resellerid, product
Following are the steps performed:
Read the CSV.
Create Temp table.
Select top 1000 records and mark the status with random s... |
Purpose
Implement a solution that returns the values in the Nth row of Pascal's Triangle where N >= 0.
Math
First three rows of Pascal's Triangle:
1
1 1
1 2 1
...
...
These row values can be calculated by the following methodology:
For a given non-negative row index, the first row value will be the binom... |
public static List<Integer> storePrimes(){
int limit = Integer.MAX_VALUE / 10;
boolean primes[] = new boolean[limit];
List<Integer> primeList = new ArrayList<Integer>();
int i = 2;
while(primeList.size() <= 10001){
while(true){
if(primes[i] == false){
... |
I've written a C function to find the program less that the operating system should provide. If lessis not provided, some other pager variable should be used. I compile it with gcc -ansi -pedantic -Wall -O3.
int findless(char *less_token, int ret) {
int breakloop = 0;
char *new_str;
while (less_token != NU... |
I was wondering if there was a better way of writing this...
I have a CSV file (about 6640 lines). After reading through the file, the values for the DFN_Network are stored in a list. After that the values of the DFN_Network are matched with their corresponding existence in the values of the dictionary all_dictionary. ... |
Requirement:
Python Function will read a LIST of TUPLES. The structure of the tuple is ("STRING", "STRING","STRING",INT,"GEOGRAPHIC VALUE")
This Geographic value can have 5 values "zip", "city", "county", "state" and "country"
Now if a Tuple has elements where geographic values are (....,"zip"),(....,"county"), (....,... |
Maybe a somewhat odd choice of language, but here is a program in ><> I have tried
to optimize the execution time of. (Not golfing). The efficiency is measured in the number of required instructions on an ideal ><>-machine, which uses the same amount of time to execute each instruction.
The program does a complete fac... |
The program I have developed is currently used for detecting and recording keystrokes. I have added some built in security measures that can easily(somewhat) be modified to suit individual user needs!
I won't go into the mechanics because the Source is readily available and easily understandable! I realize that this h... |
I want to handle input like the following
ls -al | awk '{print $1}'
Now to parse it I couldn't tokenize at whitespace because of the quotations and I had to make a special case for awk instead. The code below successfully parses the command-line input. Is there a better way?
int handleToken(int awk, char *token, char ... |
I have a listing of invoice line items that I need to apply some convoluted business logic to. We have another listing of items that I compare the invoice items to and if I find matches, I then need to ensure that that all of the values from yet another listing of items are present on the invoice in the correct quanti... |
this program does work entirely without any errors appearing however I would like to shorten it down to make it more reliable and neat
def compress_sentence():
sentence_to_be_compressed, output_file_name, position_file_name = input('what sentance would you like to compress?').split(), input('what would yo... |
I am making a visual novel game and I was wondering is there a better way of setting character attributes and initializing than the way that I have done down below. As you can see I did an abstract class so that I can call each character without rewriting a bunch of code. I also have an array that initializes everythin... |
In an attempt to think up a more efficient String Matching algorithm than the naïve \$O(n \cdot k)\$ one I came up with a slightly modified approach.
In my algorithm (code in Java), I tried a little modification of the \$O(n \cdot k)\$ approach where every time a character match starting from i fails after k positions,... |
I'm building a checkout process where I am quite frequently making SQL connections based on user input so this is quite important. I want to know if it's well-protected from any SQL injection or other forms of SQL attack.
I'm currently trying to implement a prepared statement approach with some sanitizing with htmlspec... |
The following code works, I just want to know if there are any suggestions as to how I can make it better or more secure.
config.php:
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'database');
?>
connect.php:
<?php
class DB_Connect {
private $con;
pu... |
I haven't done much C++ coding the last few years, so I've been reviewing in preparation for upcoming interviews. I wrote a minimally functional singly linked-list. I'm using my implementation for practicing interview problems and hopefully later to build more complex data structures.
Currently, the code is not te... |
The background is the question at https://stackoverflow.com/questions/36634394/nested-shared-ptr-destruction-causes-stack-overflow. To summarize, for a data structure that looks like:
// A node in a singly linked list.
struct Node {
int head;
std::shared_ptr<Node> tail;
};
If the list grows too long, a stack o... |
I'm working through Sedgewick's Algorithms book for fun and educational purposes. I am implementing a simple Stack<T>, using System.Collections.Generic.Stack<T> as a guide:
[System.Diagnostics.DebuggerDisplay("Count = {Count}, Size = {_values.Length}")]
public class Stack<T>
{
// Constructors
public Stack(int c... |
This is a an example application for testing some encryption and decryption functions in Golang. The functions encryptString(), decryptString() and hashTo32Bytes() will potentially make it into a live application, so I need to know that these functions are safe and if not, what I can do to make them safe.
I want to ha... |
I want to generate all possible combinations (without duplicates) of all sizes less or equal than \$N\$, so for example if \$N=3\$ I want to generate the following
\$\{1\},\{2\},\{3\},
\{1,2\},\{1,3\},\{2,3\},
\{1,2,3\}.\$
I created the following algorithm in Java. Is there a more optimal way to generate?
public class ... |
I have a customised Arduino board that will be connected to a battery and never power reset (it needs to be very reliable and cope with code hangs).
The board will always be put to sleep when not in use. I will use 2 external interrupts on pins D2 and D3 to wake up from sleep.
A watchdog is enabled to detect program lo... |
What this does?:
Interactions is an Enum whereas Interactable is an interface (not @Functional Interface). Every Interactable has a list of Interactions that it can do. The below code snippet, filters out all the objects that contains any of the provided Interactions. It does not check for all Interactions, so if any o... |
I'm doing multithreading at university and we've been asked to implement the producer consumer problem in C.
My code compiles and produces the right result. From debugging it, it seems to be waiting for the semaphores to be freed etc. I'm using Xcode 6.4, hence the need for sem_open() instead of sem_init(). I just have... |
I created a gaming community website about 13 years ago. It uses PHP, SQL, HTML, and CSS, and does not use a framework or template engine. It includes features such as a login system for members, different levels of access depending on your rank, dropping members that are inactive from the member list, and other featur... |
I have a list of input, a greedy method and a dynamic programming method. I wrote a unittest script to test my two methods with input list but I don't know if I'm writing it right:
import unittest
from land_selling import Offer, Seller
class LandSellingTest(unittest.TestCase):
offers1 = [
Offer(0, 6, 2),
... |
Following this SO post and this Wikipedia article, I wrote a Python script to simulate physics of 2D elastic balls.
I define the physical behaviour of each ball in the Ball class. Then the function solve_step enables to compute position and velocity of every ball for one time step.
The balls are moving inside a square.... |
Two strings are anagrams if they are permutations of each other. Assuming we have an ASCII alphabet we can take 128 integer array to count the characters in the first string. Then decrement the count for the corresponding character in the second string. If all the character counts are zero then the strings are anagrams... |
I've just been going through core data structures and algorithms recently, wanting to get back in touch with the core fundamentals. I'm starting simple with a LinkedList implementation in C#. The functionality works and was able to test it. I'm just wondering if yo see anything with the code that could be improved.
usi... |
I have just coded a Card class which gives a suit, rank and a color to a card. However, I have serious doubts that my code is not well organized and not well structured.
I would like to receive tips on how to improve my code if possible so I can learn from them.
Card class:
import java.util.Random;
public class Card {... |
Is this a fair/clean way to detect a cycle in a LinkedList? Should work for both single and double LinkedLists'.
public bool IsCircular()
{
if (Head != null && Head.Next != null)
{
var slow = Head;
var fast = Head.Next;
while (slow.Next != null && fast.Next != null && fast.Next.Next != n... |
I've implemented the sliding blocks puzzle in Python to solve it using different algorithms.
I'd like to know if the class "Sliding_blocks" is nicely designed or if I am missing
concepts of OOP.
I think that the indices of the blocks are a bit obfuscated, because I mix tuples,
lists and arrays (arrays are better to ad... |
I needed an event bus in C++ with a few features:
Possibility to add/remove both functions and member methods.
Ability to remove automatically those listeners that wrap member methods of expired classes.
Easy to use registration facilities to attach member methods as listeners.
The last point is quite important, for ... |
I'm having trouble optimizing my code for the exercise in Project Euler #44
Pentagonal numbers are generated by the formula, \$P_n=\frac{n(3n−1)}{2}\$. The first ten pentagonal numbers are:
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
It can be seen that \$P_4 + P_7 = 22 + 70 = 92 = P_8\$. However, their difference, \... |
As stated in the tags, I'm a beginner to C. This code implements a dynamic array (List in .NET, vector in C++, etc) for any pointer type. I would like that it be reviewed on memory usage and code structure/style.
list.h
#ifndef _game_structures_list_h
#define _game_structures_list_h
#include <stdbool.h>
typedef enum ... |
I've have methods for a stack and bag using a dynamic array in C. As far as I can tell everything is implemented correctly, but I'm wondering what I can do to improve this code.
dynArray.h
/* dynArr.h : Dynamic Array implementation. */
#ifndef DYNAMIC_ARRAY_INCLUDED
#define DYNAMIC_ARRAY_INCLUDED 1
# ifndef TYPE
# d... |
I have two different implementations for retrieving posts from the users someone is following and I want to know which one you would recommend using. First I'll show you the tables, and then the two implementations.
Post table
id (PK)| poster_id (FK) | value | created_on
Repost table - necessary for both implementati... |
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
A number n is called deficient if the sum of its proper divisors is less than n and it is ca... |
I stopped using Lodash to become better at JavaScript. These are recursive utility functions to deal with nested arrays:
const _ = {}
// find object in nested arrays
_.findDeep = (arr, obj) => {
return arr.map(item => {
const key = _.keys(obj)[0]
if (item[key] === obj[key]) return arr
if (item.children)... |
I was inspired by the Phillip Trelford "Beyond Lists" presentation published on InfoQ. So, I decided to make it simple, yet still capable to act as IList<T>.
I tried to stay close to the Core .Net System.Collections.Generic code style, this is the reason why I decided to explicitly implement Enumerator for the class.
T... |
I made a C# console roulette game. Check it out and give opinions on how to improve or ideas for some other features? It's not finished yet so it has lots of room for improvement. I am very new so take it easy on me.
GitHub link
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using... |
Interview problem:
Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the stream ends.(Like : "aca" : 2 , "cat" : 1 , "hello" : 1 , "world" : 0 ).
This solution works functionally. Please let me know ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.