instruction stringlengths 71 95.1k |
|---|
I developed a program that collects probe requests from WiFi devices. It already works but I think that a programmer can improve it.
#!/usr/bin/env python
import platform
import threading
import signal
import sys
import time
import subprocess
import re
import os
import os.path
import argparse
import distutils.spawn
... |
I have the following code in a validation module. It works the way I want it to, but it has an obvious select n+1 problem. I would like to refactor this code to make a single call to the db to perform this validation.
Is there a way I can do it using linq or do I need to perform more major surgery? I am trying to avoid... |
I recently did a coding problem for an interview that I unfortunately did not receive the position. So I figured I'd get the code reviewed by other professionals because after asking about the problems with the code I got stonewalled by the organization.
The problem is just serving from an API endpoint using Angular an... |
I have an implementation of a factory like so:
public class CommandActionFactory : IFactory<ICommandAction, XElement>
{
private readonly IDictionary<string, IFactory<ICommandAction, XElement>> commandActionFactories;
public IDictionary<string, IFactory<ICommandAction, XElement>> CommandActionFactories
{
... |
To learn more about OOP, @nhgrif challenged me to implement a Shape abstract class (more details in code remarks below. Here is how I did it. Any and all advice appreciated!
Shape.java
/* nhgrif says:
* Phrancis ready for inheritance/polymorphism?
* Given the following abstract class:
*
* public abstract class Sha... |
My application compiles and seems to work correctly, but this is my first C project so I welcome any criticism. I developed this in Pelles C with no standard lib. Efficiency and optimizations are more important to me than readability or conformity. The parts that I'm particularly concerned about are marked with comment... |
I have been reading this great book and I decided to do the Project in Chapter 5: Writing an Assembler for the Hack Assembly Language.
You can find the specification for the Hack Machine Language and the Hack Assembly Language here.
I have a working implementation here already. That one took me about 2 - 3 hours. Then ... |
I use NHibernate to search for data in the table Register. It contains monetary registers, incomes and outcomes. Some registers are repetitive, so I have managed to implement a few properties that my C# will check if a determined register is repetitive and loop through its repetition in order to add more registers to t... |
I have the following functions that for the most part are utilizing much of the same code (except for the actual message). What are the possibilities, if there are any, for combining / reducing these functions so that there isn't so much redundancy?
// ACCOUNT DISABLED FUNCTION
function accountDisabled() {
... |
I have a big project called 'PyDOS', written in Python 3.4, and it's going very well. Post your answers of anything that could make it look cleaner.
import time
import os
import sys
import random
import operator
def textviewer():
os.system('cls' if os.name == 'nt' else 'clear')
print ("Text Viewer.")
file_nam... |
This code mimics the "likes" tooltip from Facebook.
Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not shown.
It works as expected, but I'm sure it could be better written.
<? if ($count = $this->likes->count()) {
... |
I've implemented both as follows. Could someone be kind enough to just play around with various inputs and let me know if there are any bugs?
#include <iostream>
using namespace std;
/***************************************************************************/
class AStack {
public:
AStack(int);
... |
I was hoping to get some feedback on the implementation of this class for programmatically converting an access file into a PostgreSQL schema (works by obtaining schema data from the cursor object).
import os
import json
import pyodbc
import psycopg2
import time
import sys
# Refer to https://code.google.com/p/pyodbc/w... |
I created a New Event Emailer.
this takes some fun events from a nice SQL query and creates a little HTML message and sends it to all the subscribers of events, when new event types are added we need to be able to tell them that they need to add the events to their subscription if they want to be notified of them.
On... |
I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame:
library(energy)
pairwise_dcor <- function (DF, progress = FALSE, parallel = FALSE) {
stopifnot(is.data.frame(DF))
v <- names(DF)
n <- length(v)
corr <- matrix(1,... |
I have been working on this Rational Operations calculator where you can input two rational numbers and can add, subtract, multiply and divide and the final output is the reduced answer.
For example:
\$\dfrac{3}{4} \times \dfrac{8}{15}\$ and the output would be \$\dfrac{2}{5}\$.
I have all but the reducing done i hav... |
I'm trying to make a kind of Dungeon Keeper clone. I got the code up and running and even supporting touch events. But I don't think it's as well optimized as it could be, so I am looking for help and best practices on helping improve my map.
You can test it out and play with it here or for full screen here.
It runs pe... |
I'm completely new to C and my first project is to create a simple cURL-like HTTP request client... but first, I need to create a function that can parse a URL. I've created this function, and it seems to work quite well, but since I'm so new to the complexities of C, can someone check for any errors or to see if I can... |
I've made a little mechanism for creating 2-D vectors in Lua. Vectors have two components i and j, and support addition, dot product, magnitude, and conversion to strings.
Vector = {
new = function (i, j)
return setmetatable({i = i, j = j}, {
__index = Vector,
__add = function (self, v)
return... |
I have several methods that wrap the $.ajax() method and return its jqXHR, but I need to force fail before even calling the original $.ajax() and still allow to use success/error methods of the result.
//just a very simple example, actuall code is more complicated
$.rpc = function(method, args) {
if (!method || 's... |
Codepen Link
I've tried to Google, but there's no library that has an API to toggle table columns when clicked elsewhere on the page, so I've decided to do this:
function deleteColumnOnClick() {
$('.hide div').click(function() {
var index = $(this).index();
$('table thead th').eq(index).toggleClass... |
I used this answer to make a table with datatables.net and dc.js. However, I detected a performance issue in this loop:
function RefreshTable() {
dc.events.trigger(function () {
datatable.api()
.clear()
.rows.add( YearDimension.top(Infinity) )
.draw() ;
});
}
count = dc.chartRe... |
On our main symfony2 application at work I have had to manipulate some outputted grid fields by wrapping them in a hyperlink tag. This happens in quite a few different controllers, so I made a method to do this to prevent code repetition.
I decided to do this using DOMDocument and construct the new hyperlink with that... |
We have a base module consuming the company API. In each app I've written almost always a service per controller. Because most controllers are specific to a entity (a single user, a single post, list of posts written by a user), when I initialize them to query the data I have to request for that Id. So the service requ... |
I have four radio buttons and I want to display relevant contents for each of them if they are clicked. I am using knockout.js for data binding.
Is there a better way to write the if statement block?
<li class="row">
<div class="col-3">
<label>
<input type="radio" data-bind="checked: print_size_radio" na... |
My Google Maps Script v2
I re-factored my code to be more OO.
Does it have any more room for improvement (naming, readability, oop, etc.)?
I'm importing Gmap.js in the head tags and the main.js just before the closing body tag of the HTML document.
Gmap.js
'use strict';
function Gmap(element, options) {
if (!(typ... |
This code works, in the same way that a cardboard bicycle works until you cycle through a puddle. It powers a box that plays a sound file in sync with some lights on movement detected by a PIR sensor. Once the sound file has finished it concatenates some text and two random strings from an array and prints it. Once it'... |
I have an assignment for writing a Sudoku solver and have achieved the functionality required but a lot of the code is "ugly" and I'm wanting to simplify it but unsure how to.
def hiddenSingleCol(snapshot, cell):
j = cell.getCol() # Get column number for cell
colCells = snapshot.cellsB... |
I wonder if the following 301 redirect is the best way for my situation. I used this post on SO to give me the following 301 redirect:
RewriteRule locations\.php$ compare-biomass.php [R=301]
What we've done is changed a filename from locations.php to compare-biomass.php.
The new URL should be:
www.mydomain.com/compar... |
I was asked to write PHP code that can be used to parse a config file on the same server (same directory as well) and output all configuration parameters, and have them all be cast to the correct type. I wasn't allowed to use any of the existing functions made specifically to parse files, all string manipulation.
Class... |
I'm trying to implement a function to determine if a substring is indeed a substring of a string s.
This is what I came up with but I feel that there must be elegant way.
#include <iostream>
bool isSubstr(std::string s, std::string sub) {
if (s.size() < sub.size()) { return false; }
for (int i = 0; i <= s.size... |
Find the kth to last element of a singly linked list
Any comments?
import org.junit.Test;
public class Solution {
// Find kth to last element of a singly linked list
// Solution proposed: Use a runner that is k steps ahead
// when runner hits end of linked list, slow on kth to end element
public Node n3 = n... |
I have implemented a BST from scratch. My aim is to draft better code and understand some pitfalls which I may have overlooked.
It includes the following functionalities:
Insert a new item.
Find the Depth of a node, given the level of root is 0
Find the number of nodes in the subtree of a given node.
While removing t... |
On my educational trek through the capabilities of JavaFX, I thought it would be a valuable challenge to create Tic Tac Toe. It took me far longer than expected to get this far, but despite likely being even further from completion, I'd like a review on the current state of things and on anything my 'blind coding' unwi... |
I'm coding a school project that involves MVC and threading.
This is my Main class. From there I launch the actual client.
public class Main {
public static void main(String[] args) {
Controller myController = new Controller();
ScreenModel screenModel = new ScreenModel();
ChessBoardModel... |
Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop.
This code works on my project, but I think its not the most elegant solution. Have someone any improvements?
InputReader.java
public class InputReader {
private Strin... |
Based on dropdown value and search text I need to filter a list and return.
Method 1
if (selectedValue == 1 && searchTerm.Length == 0)
return users;
if (selectedValue == 1 && searchTerm.Length > 0)
return users.Where(user=>user.Name == searchTerm).ToList();
if (selectedValue == 2 && searchTerm.Length > 0)
return user... |
I have created a library which consumes the Imgur API.
This is the main file.
var request = require('request-promise'),
fs = require('fs'),
path = require('path');
var Imgur = function(options) {
this.options = {};
if (typeof options.clientId === 'undefined' || !options.clientId) {
throw new ... |
I have a class Vector3d with 3 double components and want to store several of them in a Field. For reasons of efficiency when sending a Field over a network via MPI, I would like to allocate contiguous memory in the Field class and let the Vector3ds store their components in that chunk of memory. In addition, Vector3ds... |
I have a search form in my application. When I search, it takes too much time to retrieve and display data, so I need to optimize this code.
public void search_thread()
{
Stopwatch sw = new Stopwatch();
sw.Start();
string sqlcmd = "select en.eventname,q.Q,q.QLevel,q.QUsed,q.QType,q.QAlt,q.QStatus,q.QTag... |
Project Euler problem 48
The series, \$1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317\$.
Find the last ten digits of the series, \$1^1 + 2^2 + 3^3 + ... + 1000^{1000}\$.
I made two different implementations of this problem, and added a benchmark, using rolfl's UBench library.
The code:
public class ProjEuler48 {
... |
I've created a function that makes a query of a database table and managed to use the results in another page where the function is called.
Is this approach good?
function cart_list($db, $user){
$stmt = $db->prepare("
SELECT
o.username,
o.quantity,
p.description,
p.product_name,
FROM
orders as... |
From the README.md
Introduction:
The purpose of data-in is to read all the lines from a text file and return the file's contents as a Clojure value in a standardized manner.
Specification:
Takes:
Filename
Assumes:
a space delimited text file
Returns:
Vector [L1,L2,...Ln] where Li:
represents a line in Filename
is... |
I am working on a fairly complex (at least it feels complex to me at the moment) search program and am looking to possibly increase the performance. Everything works exactly how I want it to, but I'm just wondering if there are any slight performance increases I could benefit from. In this code, even minor performance ... |
I have just completed problem 29 from the Project Euler website:
Consider all integer combinations of \$a^b\$ for \$2 \le a \le 5\$ and \$2 \le b \le 5\$:
\$2^2=4\$, \$2^3=8\$, \$2^4=16\$, \$2^5=32\$
\$3^2=9\$, \$3^3=27\$, \$3^4=81\$, \$3^5=243\$
\$4^2=16\$, \$4^3=64\$, \$4^4=256\$, \$4^5=1024\$
\$5^2=25\$, \$5^3=125\... |
The following example is an accordion script in JavaScript that does not use jQuery. When I started looking for a simple solution to this requirement I did not accept the idea of having to use a powerful and robust library for a simple implementation. I didn't like the idea of use a machine gun when what I really need ... |
I was tasked with re-writing a login VBScript we use on about 50 machines. The original script was hacked together by someone who clearly had no idea what they were doing (multiple lines that literally did nothing, including creating persistent shares, deleting them, then recreating them 4+ times in a ForEach loop)
I d... |
Assume you have an array of random integers and a sum value. Find all
pairs of numbers from the array that sum up to the given sum in O(n)
time. Find all distinct pairs. (1,2) and (2,1) are not distinct.
import java.util.HashSet;
public class PairsSummingToElement {
public static void main(String[] args) {
... |
The function below converts a time code into seconds, while maintaining the decimal value (fractions of seconds). The time code fed to this function will always contain microseconds. This currently works, but I'd be interested to see how it could be improved/simplified.
def Second_Conversion(x): #Takes a string such ... |
I will post both of the modules, some of the code in them may be "irrelevant" for the main concern here, which is Security.prototype.authenticate(). Nevertheless, comments are welcome about all of the code.
Security.prototype.authenticate() is a controller for a /login API-endpoint.
security.js
'use strict';
var crypt... |
To brush up on my C++ chops, I've implemented a toy version of "SICP Streams", which behave like lists with one twist: the first element of the list is always available, the rest of the list is stored as a "promise" to produce the rest of the list. Calling rest() forces its evaluation.
Following is my implementation o... |
I set about doing it as a challenge (and it's still far from finished) but I hit lots of problems. The main one that caused most of them was it can't deal with even numbers (it can be (1,1),(1,-1),(-1,1),(-1,-1), but nothing with a 0), so I had to multiply everything by 2 and add 1, which caused such a headache later o... |
Question:
Write a function that accepts integer values for day, month and year and returns them in a valid format. If the day is above 30, then convert it to 30. If the month is above 12 then convert it to 12. Similarly, if day or month is below 1, then it converts them to 1. Finally it ensures that the years are betw... |
Consider the following segment of code:
# Fetch my orders
orders = repo.get_orders_for(self._customer[0])
if len(orders) > 0:
current_order_no = -1
for (order_number, quantity, pid) in orders:
# Print new heading if needed
if order_number is not current_order_no:
print("Order #{}".... |
I need to make a library in which I will have synchronous and asynchronous methods in it. And then if there are any exception like TimeoutException or any other exception, I need to log an error into our company's storage system with the logging I have both from synchronous and asynchronous method.
Core Logic of my Lib... |
I like this solution but maybe there is another way. My goal with this is to limit user editing to the amount of credits they have. What do you think?
Here is what it does:
Credits are stored as user meta _credits (int).
Users can only edit pages, posts, custom post types if they have credits left.
Show a proper mess... |
In this code snippet, I want to be able to return the Amount as it is, unless the CashFlowTypeID is 12, 13, 14 or 15, in which case I want to return Amount, but negated.
How can this code snippet be improved? (Would you consider bitwise operations?)
public decimal GetAmount(decimal Amount, int CashFlowTypeID)
{
if ... |
This function will run every x seconds.
PAN: The name we are calling our fixed width file we are transmitting.
Private Sub Start()
' Get the data from the API so we can get ready to make the PAN File
Dim Baker As New PAN.Maker
Baker.SetIngredients(GetAPIData)
' Make the PAN file
Baker.Make()
... |
I need to convert a string value to its primitive type in JavaScript. Other values that are not of type String should just be returned.
Example:
String '34' should be converted to 34
String '34px' should be kept as '34px'
true should return true
'true' should return true
Here is a working example (please look at cons... |
I am trying a trial multiplication for factorization. This is a general example, but each sequence can be specified to pairs of sequences \${p,q}\$ for a given \$n\$. For example, if \$n\$ ended in 3, then {\$p,q\$} would be: {1,3},{3,1},{7,9} and {9,7} with sequence steps of -10 and 10 respectively.
The essence of the... |
This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.
How can I indent this code to make it look great and be well formatted?
parser = argparse.ArgumentParser(description='Collect WiFi probe requests')
parser.add_argument('-i', '--interface',
default... |
I've got a function which updates an existing record or inserts a new one, but it looks very clunky to me.
using (SQLiteConnection db = new SQLiteConnection(AppSettings.DbPath))
{
db.RunInTransaction(() =>
{
var y = db.Table<MyClass>().Where(x => x.GUID == this.GUID && x.VersionNumber == this.VersionNu... |
This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.
I have this line of code:
airport_path = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
It seems to be too long for Python style standard. Can I shorten it or make it mul... |
This is a follow-up to Log probe requests of WiFi devices, focusing on a specific element of the code.
Can I simplify this code and make it more readable?
if not os.path.isfile(args.tshark_path):
print "tshark not found at path {0}".format(args.tshark_path)
sys.exit(1)
if not os.path.isfile(args.ifconfig_path):... |
I have the following method of some class, which also defines the method isAllowed:
auto filter(const auto& in)
{
auto ret = decltype(in) {};
for(auto x : in)
if(isAllowed(x))
ret.insert(x);
return ret;
}
This is a clear case where copy_if could be used instead. I see two alternative versions... |
I wrote 2 classes in order to implement some basic cryptography algorithm. I tried to use some object-oriented concepts of C++. I'm a beginner, so any comment or suggestion is welcome.
First class: Message
The header:
#ifndef MESSAGE_H
#define MESSAGE_H
#include <iostream>
#include <fstream>
#include <string>
#includ... |
I have recently completed problem 25 from the project Euler site.
The Fibonacci sequence is defined by the recurrence relation:
\$\qquad F_n = F_{n−1} + F_{n−2}\$, where \$F_1 = 1\$ and \$F_2 = 1\$.
Hence the first 12 terms will be:
\$\qquad F_1 = 1\$
\$\qquad F_2 = 1\$
\$\qquad F_3 = 2\$
\$\qquad F_4 = 3\$
\$\qquad F... |
I wrote a simple to use C++ INI file parser. The only thing it requires is the STD libs (of course that come with most major C++ compilers) So far it works very well, and the only thing that needs work is the string parser to handle special characters in the key's value. I.E \", \ \n \r.
You can view the code here:
awe... |
I have this function to remove nodes that matches a certain criteria in the list. Initially when I wrote it, head node was not deleted if head->value was >= delete_value, but other nodes in the list were deleted, so I decided to write the last if statement to only delete and amend the list if head->value was >= delete_... |
I am developing a C# program, which performs various tasks in parallel threads. I created a Base task and let all tasks derived from this class execute. I just want to know if this a viable approach which won't cause unforeseen consequences if various tasks run in conjunction.
public abstract class BaseTask
{
priv... |
Use Case
The third party library that I am working with implements its data model in this fashion.
Interface
- Implementation (24 different implementations)
- Interface
- Implementation (variable number of implementations)
- etc...
Unfortunately, none of the interfaces have definitions fo... |
I am writing a conditional that checks two values, for several different scenarios.
What I am modifying is a series of objects, some of these objects are in arrays, and some are just arrays. I need to check these values and then check a file, and then check my values (the series of objects, array objects, and arrays) a... |
I wrote some code which simply retrieves the HTTP status code of the passed in URL. There are multiple potential causes of the same error. I am hoping to get some all around feedback on this code, but my primary concern is that I have low readability in an attempt to provide good feedback in the event of an error.
pr... |
I'm working with libGDX for a game, and over the last few days I have tried a few different types of serialization before settling on a custom serialization implementation. XML had huge file sizes, JSON was a bit better but unfortunately gave me problems on iOS, and Serializable would not work because if I extended tha... |
This is my first attempt at creating an event system.
My plan is that upon publishing, the listener receives both a reference to the model and to the publisher. This allows the publisher class to have multiple owners, and provide a way for listeners to know exactly how they were called.
To do this I've made the base cl... |
I need to make a library in which I will have synchronous and asynchronous methods in it and this library will be used by our customer in our company. Some customer will call the executeSynchronous method to get the same feature and some customer will call our executeAsynchronous method and with the latter method they ... |
What I'm building is a URL builder. A marketing person inputs a URL and can test that URL to see if it's valid, then they select a demand channel and then hit 'Generate Campaign URL'. I've omitted the other form fields, as I'm only interesting in refactoring the code for the onclick event of the 'Test' URL button.
In a... |
I have a fairly basic question here: I want to find if two lines on a 1-D plane intersect. I know of two simple ways to solve this, but I wanted to know if Python has a more elegant way to solve this.
x = [1, 10] # 1 = begin, 10 = end
y = [15, 20]
z = [5, 12]
#Method 1: Works. Is quick. Lots of typing.
def is_intersec... |
This checker works perfectly but I have a strong feeling that I could make this script much more compliant with the "Zen of Python", especially having read a book about it recently. There is no doubt that I made this script much longer than needed, so if you see something I can shorten, please say so.
#!/usr/bin/env py... |
Is there a better way to check if a number is a prime?
#include <iostream>
#include <math.h>
using namespace std;
bool doAgain();
bool isPrime(int num);
int main()
{
do {
int num = 0;
do {
cout << "Enter a positive integer to check: ";
cin >> num;
} while(num < 1);... |
I know this code needs some organization like classes, enums, methods, arrays or something but I just want to know if I could have created a character movement script, thereby shortening the code without using enums, methods, array etc. (keep it the same). Is there any ways to shorten this?
namespace rpgProject
{
... |
Working on a project, I encountered a need to create a wizard and when I ran into the need for a second, slightly different wizard, I generalized into these classes.
I originally based it off of this tutorial and attempt to adhere to these design considerations:
Allow traversing the pages in a flexible manner as neede... |
I've been working on creating an individual final project for my python CS class that checks my teacher's website on a daily basis and determines if he's changed any of the web pages on his website since the last time the program ran or not.
I would really love some suggestions for improving my code, especially since i... |
I have a WPF Control Panel app, where I'm trying to stay close to an MVVM architecture. The control panel (the "the CP") is for a WCF service ("the Scheduler"), hosted in a Windows Service ("the Host"). My main concern, and topic for review here, is how I am avoiding blocking the CP responsiveness for too long. The Hos... |
I'm working with an API which gives me 19-digit ID numbers, formatted in blocks of four except for the last 3 digits. While I tried a for loop, I thought it would be most efficient to simply use a StringBuilder and substrings as the length of the ID will never change (documentation is omitted for privacy reasons):
publ... |
I have 4 properties which I calculate using LINQ:
public decimal TotalEatin { get; set; }
public int EatinAmount { get; set; }
public decimal TotalTakeout { get; set; }
public int TakeoutAmount { get; set; }
The way I generate the values are done correctly this way, but I think the code is a bit cumbersome because of... |
This code takes the results of a database query and uses them to populate the options in a combobox on a form.
Would it be better to start with an empty htmlCode and then concatenate all the <option> code in the loop before finally using echo outside the loop?
Also, do I need to declare $boxOption, $paramKey and $param... |
I have written a program where the user inputs a regular expression and a replacement string, and the program will search through a set of files and do the replacements.
The user is allowed to use backreferences in the replacement string (to refer to capture groups in the regex).
The part of the program I would like ... |
I'm trying to learn more about kernels, so naturally I started to program one. I'm using tutorials from here. Right now I have modified the printf() that was supplied there. It used goto and I didn't like that.
Can anyone see anything wrong with this code? It worked fine when I tested it.
printf("hello %c world %c",'x'... |
There is a custom summary function needed as to receive an integer input (e.g. 32456) and returns 3+2+4+5+6. Can you think of any other (or better) solution besides this?
public class CustomSum {
public int sum(int input) {
int sum = 0;
while ( input >= 1 ) {
sum += input % 10;
... |
I was wondering if this code looks neat, and if I should change anything. I was planning to implement Frames (or JFrame) tomorrow on it. Would it be a good idea to use functions?
import java.lang.Math.*;
import java.util.Random;
import java.util.Scanner;
public class Paradox {
public static void main(String[] args){
... |
I'm new to Python, and after running through some introductory exercises I wrote a class definition for working with some hardware, specifically a Signal Recovery model 7230 lockin amplifier. In the interests of learning good habits from the beginning, I've tried to write "good code" that is properly documented, follo... |
I've come up with two ways to do sprite movement with CreateJS, and I'm wondering if one is better than the other as far as performance and maintainability.
The player data is saved in a json file and looks like this:
{
"spritesheets": ["head_short.json", "clothes.json"],
"animation": "stance_w",
"position": [300... |
I'm writing a C program to reserve seats in a movie theater. I am validating the selection of seats:
const int TOTAL_ROWS = 10; // 1 to 26 -> 'A' to 'Z'
const int SEATS_PER_ROW = 5; // 1 to 9
int seats[TOTAL_ROWS][SEATS_PER_ROW]; // reserved seats, reserved seat == 1
char codes[TOTAL_SEATS][2]; ... |
I am looking for some comments on my code and whether or not this is the best way to create an abstract class. In addition, some of the abstract methods are rarely called so I use the base variables within the subclass to make sure onCreateDialog selects the correct stuff. Hence, the getTitle() > 0 conditional.
public ... |
Here's my program for factoring a number. It works, but it's quite slow.
I'm looking for suggestions for optimizing. The lines are indented just for readability.
ClrHome
Disp "N=Number
Input "N: ",N
If N≥1 and not(fPart(N:Then
{1→ʟF
If N≥2:Then
For(A,2,iPart(√(N)))
If not(fPart(N/A
... |
I have a predicate builder that initially evaluates to false. Because of this, the very next expression should be a logical Or. But if I need a logical And I need to keep track of a boolean value. And this boolean value hasPassedFirstCheck is the thing I want to get rid of.
var cars = PredicateBuilder.False<Cars>();
va... |
I am trying to learn concurrent programming in C++11. I tried to write code for a classic producer consumer concurrency problem. Would you please review and make any comments about it?
#include <iostream>
#include <thread>
#include <deque>
#include <mutex>
#include <chrono>
#include <condition_variable>
using std::deq... |
This is the first jQuery program I've written, and it doesn't do much, but I'd appreciate the feedback. Just click on the different colored buttons to do things.
Codepen
var $greenElement = $(
'<div style="width:750px;height:25px; \
background-color:green;" class="green-bar"> \
<p>Hello</p> \
</div>'
);
var $... |
I have just finished with the first Ruby exercise on Level Up Rails, and wanted to get an idea on how I can refactor the code.
You can find the original exercise on github - including the requirements that I have to implement as well as the CSV data files (there are two).
Requirements
Go check out the CSVs and come ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.