instruction stringlengths 71 71.9k |
|---|
The task for Project Euler #1 is to find the sum of all the multiples of 3 or 5 below 1000.
Here's what I coded:
#include <stdio.h>
main()
{
int size=1000, i=0, sum=0;
for (i=0; i<size; i++)
{
if (i%3==0 || i%5==0)
{
sum+=i;
}
}
printf("%d", sum);
return 0;... |
I've implemented a command line todo list in Haskell. I've run hlint and build with -Wall, but is there anything else I can improve?
module Main where
import Control.Applicative ((<$>))
import Prelude.Unicode
import System.IO (IOMode(ReadMode, WriteMode), utf8, hClose, hGetContents, hPutStr, hSetEncoding, openFile)
im... |
I'm using this code to compute a cartesian product:
def cartesianProduct[T](in: Seq[Seq[T]]): Seq[Seq[T]] = {
def loop(acc: Seq[T], rest: Seq[Seq[T]]): Seq[Seq[T]] = {
rest match {
case seq :: Nil => seq.map(acc :+ _)
case seq :: remainingSeqs => seq.flatMap(i => loop(acc :+ i, remainingSeqs))
}
... |
I've built a C decoder program. The length of an encoded message will be given and the message itself in the following line. All the characters of the message will be in uppercase letters. The task is to print out the decoded message.
Encoding: A->B, B->C...Y->Z, Z->A (well, you get the idea)
#include<stdio.h>
main()
... |
Background
The gear selector on a car allows the driver to select which state the transmission should be in.
In the example picture, one of the five letters (P, R, N, D & S) lights up to indicate which state the transmission is presently in.
The position of the rotary dial is sufficient to determine which state the ge... |
An Atbash cipher is a simple substitution cipher wherein a key is used to determine what letters to swap, for example:
Original alphabet: abcdefghijklmnopqrstuvwxyz
Substitute (key): zyxwvutsrqponmlkjihgfedcba
Original message: hello world
Altered message: svool dliow
In my program, I get the key by printing the o... |
I wrote a program to show graphically the solution of the problem of the Tower of Hanoi. Here is a video of an example run.
The logic of the solving is taken from StackOverflow (see links in docstring), I wrote the part dealing with the graphics, so review is most welcome on the graphical part that I wrote.
The code is... |
I'm in the process of designing my own programming language and I have absolutely no experience in computer science other than the code I look at.
I created my first lexer, I've improved it enough that the lexer can actually lex its own source code.
What I'm asking here is how can I improve this lexer?
GitHub
#ifndef _... |
I would like to do POS tagging on around 8,000 tweets. I have a function and am using data.table to call it on every row. The problem I'm having is that it takes over 1.5hours to run this chunk of code.
Code:
options(java.parameters = "- Xmx3000m")
library(rJava)
library(NLP)
library(openNLP)
library(data.table,quietly... |
I have been working on some code for a basic inventory management system and I have all the features that I believe are need like adding parts displaying parts list and the such as you can see. I believe I have worked out all the bugs I can find. I'm looking to see if I got all the bugs out and maybe some optimizations... |
Problem statement
Let us first describe a SimpleFunction:
SimpleFunction( string A,string B ){
int answer = 0;
for( int dig = 1; dig <= 9; dig++ ){
if(string A contains digit dig and string B contains digit dig){
answer = answer * 10 + dig;
}
return answer;
}
So b... |
I wrote a log parser in Python and Julia. The Python version takes about 8 seconds to process 350 files, while the Julia version takes about 8 seconds to compile, after which it takes over 20 seconds to process 350 log files.
I wrote the original parser in Python several months ago, with regex, a custom class, and lots... |
I am using this basic extension for a Swift project. It works well, but I want to make sure it is the absolute fastest way to get a substring.
extension String {
func substring(start: Int, end: Int) -> String {
if (start == end || self.strlen() == 0) {
return ""
}
let startIndex ... |
I have a method which does URL decoding on the string value passed along with using Charset:
public String decodeValue(String value, Charset charset) {
if (!Strings.isNullOrEmpty(value)) {
try {
value = URLDecoder.decode(value, charset.name());
} catch (UnsupportedEncodingException ex) {
... |
Mostly robocop and hound give "line is too long" for such code statements. I just wanted to know which one is better and preferable way.
This one is a way to avoid making the message long so just do multiple string interpolation:
timeGet = "<span class='message'>after #{getTime2(online, offline)}</span>"
logs[index].e... |
I haven't done much Python programming, but I really like the language so I've been using it for side projects that I work on. The problem with this is that I don't have the opportunity to have my peers review my code and give suggestions.
I've been working on a project that will be scraping GitHub looking for secur... |
Problem statement
Consider a matrix with \$n\$ rows and \$m\$ columns, where each cell contains either a \$0\$ or a \$1\$ and any cell containing a is called a filled cell. Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally; in other words, cell \$[i][j]\$ is ... |
Online coding challenge Hacker Rank.
Given a list of unsorted integers, find the pair of elements that have the smallest absolute difference between them? If there are multiple pairs, find them all.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Sol... |
I want to be sure that in terms of auto-layout or just following the proper methods of doing the following is acceptable. I am not sure if there will be an constraint issues or efficiency problems that could slow down my app. It is working so far, I am in the process of trying to animate it as it resizes.
import UIKit
... |
public class ProgressDialogUtils {
private static ProgressDialog progressDialog;
/*
* Create an progaress dialog instance
* @param Context contex
* @Title title of String
*
* */
public static ProgressDialog createProgressDialoge(Context context, String title) {
progressDialo... |
My code:
import subprocess
import os
import platform
class Speaker:
"""
Speaker class for differentiating different speech properties.
"""
def setVoice(self, voice):
self.voice = voice
def setWPM(self, wpm):
self.wpm = wpm
def setPitch(self, pitch):
self.pitch = pitch... |
Here I'm merging a list to end of another list after sorting it according to another list.This should sort processdetails list according to the order in routeplans list if any item not present in processdetails list is found it should keep the order and add it to processdetails list. Simply saying it just merging two l... |
This is a simple implementation of Conway's Game of Life in Java. The algorithm I use is inefficient however. Every Cell's neighbors (alive or dead) are checked on every iteration.
import java.util.Scanner;
public class GameOfLife {
public final static int BOARD_HEIGHT = 20;
public static Cell[][] board = new... |
I am using ButterKnife in my project, and as we know we have to write ButterKnife.bind(this); in all the activities, so I have just created BaseActivity like this:
public class BaseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState, int layout) {
super.onCreate(savedInst... |
I am currently programming a game in java, and I recently implemented a centralized event dispatcher system in order to decrease coupling between different parts of my game.
My system consists of three classes : GameEventDispatcher, which contains the actual dispatching functionality, GameEventListener, a simple listen... |
I track the hours that I have worked on something in an Excel sheet (actually Google Spreadsheet, but semantics). This is tracked in the following format:
Date | Start (time) | End (time) | Description
I can download this as a CSV and my program will run through it and tell me how many hours I've worked in total and pe... |
I'm working on a project where user adds many products and compare their prices, average price, minimal and many other statistics.
There are two currencies for now, EUR and CZK.
I'm here to ask you for advices - either about performance or a better structuring of my code.
There are for example 10 prices of one produ... |
I've written some Python-code to generate the Norwegian National Identification Numbers.
Being fairly new to Python, I'd really appreciate a review on this code in regards to best practices and style.
import calendar
def is_valid_date(d):
dd,mm,yyyy = [int(i) for i in [d[:2],d[2:4],d[4:]]]
days = {
1:... |
I have created a double-ended container, but I have doubts about its efficiency in terms of performance. Can you please criticize the code? What can be done extra, such as shortening it?
#ifndef EXERCISE_H_
#define EXERCISE_H_
#include <iostream>
typedef unsigned short ushort;
template <typename type_t>
class list{
... |
A quick description on the problem I solved on codewars.com but remember I just want a small part of my solution refactored (just the for-loop):
Description
Vasya wants to climb up a stair of certain amount of steps (Input
parameter 1). There are 2 simple rules that he has to stick to.
Vasya can climb 1 or 2 steps a... |
The code ive written takes the user entered numbers and sorts them into a list and finds the two biggest numbers, im looking to make the code less verbose. any help/advice is greatly appreciated.
def printTwoLargest():
numList = []
num = 'holder'
x=0
y=0
while num != '':
num = input('Please... |
I've finished an implementation of what I believe the Publish-Subscribe pattern is for practice and possible use in personal projects even though this implementation is fairly similar to the Observer/Observable classes of the Java API.
I'm looking for a review of my code-style, JavaDoc usage, API usage, implementation ... |
I've got some code that plots some displays from a weather URL and locations in a CSV file. I'd like to see if anyone can make the code more efficient, the code runs fine without any errors and I'm aware you won't be able to test it, but if anyone could take a look at making a class function or breaking up the function... |
Code directory structure:
./Computing$ ls -LR
.:
fileIO list record file.txt mergeSort.c mergeSort.exe type.h
./record:
record.c record.h
./fileIO:
file.h fileReading.c
./list:
arrayImpl.c linkedListImpl.c list.h
Compilation procedure:
./Computing$
./Computing$ gcc -Wall -Werror -I. -DARRAY ./list/*.c ./reco... |
This code is meant to download images from an image board to create a local backup. Images are grouped by tags selected by the user and then downloaded using multiprocessing. Normal use of this program would be daily or weekly, resulting in a typical download queue of no more than 100. However, if the user opts to down... |
Could someone tell me if this is a bad idea for coding my validation for a password and it is bad? This is for registration for my site. Could you please tell me why and how you would go about it (I am a beginner and at PHP)?
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['co... |
After having showed a previous implementation of my "Resistance System", I decided that I was completely wrong about how I had been going about things. The system, as it had been presented, was completely erroneous in both theory and execution. I can admit that. Realizing this, I took a step back and realized that I co... |
I wanted to learn about pointers and someone suggested that I give C a try, so I went through Linked List Basics from Stanford CS library, implemented some of the code (and tried to improve the code a bit as I went), as well as wrote "unit tests" (to the extent you can call them such in C).
I'm using "Microsoft (R) C/C... |
Recently, just for fun, I've created a clone of the arcade game Tron. Since I am still a novice when it comes to C++, I would really appreciate all the feedback I can get from those with more experience.
Cleanup.h
#ifndef TRON_CLEANUP_H
#define TRON_CLEANUP_H
#include <utility>
#include <SDL2/SDL.h>
/*
* Recurse thr... |
I am looking for feedback on:
any inputs on unforeseen use-cases where the code would be incorrect.
(floating-point errors, etc).
my method of using a "static class" acceptable
is using the default of 10 decimal places a good default or should I
not round/truncate to decimal places if possible
Acceptable suggestions ... |
I just started to use Python and Pandas. My current solution to a problem looks ugly and inefficient. I would like to know how to improve it. Data file is Census 2010 can be viewed here
Question:
Only looking at the three most populous counties for each state, what are the three most populous states (in order of highe... |
Below is the implementation of a comparer that compares objects of type Region first by index and then by it's type. The sort order of the type is defined within the comparer.
I know, it's a trivial piece of code, however I am happy about any comments about the realization. :)
public class Region
{
public RegionTyp... |
I've been doing lately CodeWars and here's my working code for this challenge.
The challenge :
Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.
My code :
public static String long... |
I have following input range (slider), values allowed are from 0 to 100.
I need to map values from the slider to a input text, with the following rules:
range => text
0 => 2000
100 => 200
With the value in between accordingly.
Currently I am using the following script, which works, but I would... |
For some reason or another, I want to have available unsigned integers of sizes other than 1, 2, 4 and 8 (e.g. an unsigned integer with 3 bytes). For most platforms, compilers don't make those available; so - I rolled my own.
Other than asking for a general review, I will also pose a few specific questions / requests f... |
So uhm, this program allows you to vote to 3 person and has 20 voters. However my teacher want's this reduced by using loops. So here's the program:
import java.util.Scanner;
public class Vote
{
String a, b, c, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20;
int va, ... |
I have three conditions like the following:
if (IsAllTriggersRequired && meterFlag && workFlag && timeFlag)
{
result.Add(new TodayTaskTest { Code = item1.Code, Id = item1.Id, Title = item1.Title });
}
else if (!IsAllTriggersRequired && (meterFlag || workFlag || timeFlag))
{
result.Add(new TodayTaskTest { Code =... |
I have this code that is working as intended I would just like to speed it up.
#include <windows.h>
void pressW();
int main(int argc, char** argv) {
DWORD x = 566;
DWORD y = 967;
DWORD red = 2039797;
DWORD gold = 43963;
DWORD blue = 15715270;
while (true) {
if (GetAsyncKeyState(0x31)... |
Here is my code . I am not sure is it best practice or not? Please help me to clean my code. I initial all value. Should O put all in optional ?. Is there any alternative option? I can do that for sweeter and clean code.
:
class Shop {
var shopId : NSNumber = 0
var imgUrl: String?
var rating : Float = 0... |
I have a very hard time figuring out how to proceed. I built an Access DataBase which I use to process data in order to build several weekly and monthly reports. I wrote VBA codes in Excel and in Access.
Basically, for now, Access VBA processes data, exports tables on temporary workbooks then runs macros on Excel to co... |
I'm searching a way to literally shorten my code.
For the moment my code is this;
if(getDashConfig().getBoolean("enchantments.multifirearrow.enabled")){
MultiFireArrow fire = new MultiFireArrow();
DashEnchant.getEnchants().put(1, fire);
DashEnchant.getStringEnchants().put("multifirearrow", f... |
Occasionally I need to implement periodic checks in a loop in a background thread, a typical example being asynchronous processing using a message queue. While it’s not terribly complicated, I wonder what simpler, more elegant solutions exist.
I post my solution, and I’m eager to hear any constructive criticism!
The r... |
I have solved Project Euler's problem number 47, which reads:
The first two consecutive numbers to have two distinct prime factors
are:
14 = 2 × 7
15 = 3 × 5
The first three consecutive numbers to have three distinct prime
factors are:
644 = 22 × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.
Find the first fou... |
I am doing this Codility problem
You are given N counters, initially set to 0, and you have two possible operations on them:
increase(X) − counter X is increased by 1,
max counter − all counters are set to the maximum value of any counter.
A non-empty zero-indexed array A of M integers is given. This array represent... |
I've got 20'000+ court documents I want to pull specific data points out of: date, document number, verdict. I am using Python and Regex to perform this.
The verdicts are in three languages (German, French and Italian) and some of them have slightly different formatting. I am trying to develop functions for the various... |
I try to avoid keeping passwords etc. in memory or in plain text anywhere. But I am on a huge time crunch and this will only be used internally this week then probably won't get touched again. I just want to make sure this is secure and if not, what the risk is.
I'm mostly concerned about the password sitting in memory... |
I am solving the UVA 11340 problem:
Problem Description
News agency pays money for articles according to some rules. Each
character has its own value (some characters may have value equals to
zero). Author gets his payment as a sum of all character’s values in
the article. You have to determine the amount of money tha... |
I have made a Query Builder, (not the full version of it yet) but I wanna ask if there is someone out there, there can improve this code even more. Will be nice to know so I can code the rest in the better way :)
<?php
class DB {
private static $instance = NULL;
public static function sql(){
self::$in... |
I have a few Flask projects that I want to install, each in their own virtual environment. The approach is derived from this tutorial. The steps to create the VE's are very similar, so they're easy to automate. So I wrote this, as a first step. It seems to work OK:
#! /bin/bash
if [ $# -lt 2 ]
then
echo ... |
Below is the unsorted array and sorted array implementation of priority queue.
Code directory structure:
./code$ ls -LR
.:
pqClient.exe pqClient.c list PriorityQueue type.h
./list:
arrayImpl.c linkedListImpl.c list.h
./PriorityQueue:
arrayImpl.c heapImpl.c PQ.h sortedArrayImpl.c
type.h
/********* type.h *****... |
Count duplicate List<int> in List<List<int>>.
A duplicate is not order-dependent. { 1, 2, 3 } is a duplicate of { 2, 1, 3 }
Looking for speed without getting silly.
public static void CountListTest()
{
List<List<int>> testData = new List<List<int>>
{
new List<int> { 7, 3, 4 },
new List... |
I get an id via Get request to fetch an object from the database.
I have used mysqli prepared statements to avoid any security problems. As I am new to these stuff I would like a confirmation that implemented the logic correctly and safe.
User goes to
website.com/post.php?post=130
In post.php i do the following:
Chec... |
I've been reading the Rust versions of this, and just because I'm kinda tired, I thought I'd just throw together something in C.
Here's my 15 minute effort to solve the 2016 Advent of Code Day 1, Part 1 problem. The task is to follow some directions (90° turns and steps on a rectilinear grid), then state the rectiline... |
I am working with two web applications, one is webform-based Site1 and other is an MVC application Site2.
TODO:
Pass a complex object from Site1 to Site2. In response get View from Site2 to Site1 and display it:
function test()
{
$.ajax(
{
type: 'POST',
... |
I've started my first "job" like 2 weeks ago, and to be honest I've received a quite hard task to do, since I'm beginner with Android, and quite fresh at programming. The thing I needed was to find the way to rotate the buttons while changing orientation of the phone, after some research I've found a solution on the we... |
I've just finished my first program written in Java. It's a simple, boring, yet well-known FizzBuzz challenge where you have to:
Write a program that prints the numbers from 1 to 100. But for
multiples of three print “Fizz” instead of the number and for the
multiples of five print “Buzz”. For numbers which are mul... |
Please check out my code below. I know I might be asking a lot, but this is newbie code which I feel can be improved quite a lot. So far I haven't been able to get it "better", or "simpler".
What does the code do?
The code first grabs all goals from the database. A goal is a simple table:
CREATE TABLE `goals` (
`id` ... |
The gist of the code is that there's an assembly line of products, in this case Toy and Book, that get inspected by workers who then add them to a box. The box is then sent to someone who knows what to do when they receive a box for a given product. I made the fields of Product, Toy, and Book public to shorten the code... |
I have a CArchive Which contains a serialized CMapStringToString.
From my research it is my understanding that it is quite difficult to directly read a CArchive from within a C# DLL. So I decided to read it in the MFC application and feed it into the DLL interface.
At the moment I am doing the following:
m_pInterface->... |
I'm re-implementing the common core functions that work on list as a learning exercise. I'm new to Haskell and often find myself staring at what I've written trying to determine the simpler or more elegant solution I'm certain exists. I'm also unsure about my naming conventions, since there are some things the style gu... |
I have a C# application where I have implemented the MVP pattern. On one of my forms I have two ComboBoxes with values through which I loop with a button press. The first ComboBox contains different scenarios and the second one contains different (threat)actors. I show each scenario, and for each scenario I show each a... |
Given a string, I've done the below to search a CSV for a keyword and display the row if it's found
<?php
$ch = fopen("test.csv", "r");
$header_row = fgetcsv($ch);
/* This will loop through all the rows until it reaches the end */
while(($row = fgetcsv($ch)) !== FALSE) {
$cols = array($row[0], $row[1], $row[2], $... |
I'm writing code for a worker receiving message from a queue.
It should
send an email
save the fact that this email has been sent
acknowledge the job
log some info.
I wrote the following code, but I find it ugly!
Do you have some advice on how to refactor it ?
class MailWorker
def initialize(logger, db, smtp)
... |
I'm still new to programming. I have made a book record system and I just wanted some coding review if there is any mistakes I should fix or any improvements that are needed.
Here is the code I made
#include <iostream>
#define MAX 5
using namespace std;
struct record
{
int id;//stores id
float price;//store price
int q... |
I am writing some code to search my database and show results. Is the below code ok and safe enough? new to PHP and Mysqli so really appreciate any help that I can get on this subject. Thanks
<?php
$conn = mysqli_connect("localhost", "root", "", "tutorial");
if(mysqli_connect_errno()){
echo "Failed to... |
(See also the follow-up question.)
I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements:
the stack has maximum capacity,
pushing an element,
removing the top element without returning it,
peeking the top element,
client is blocked whenever popping from an empty stack,... |
I am new to using Python and the following is the first script that I have written. I will execute a test complete project and will be started via team city. Once test execute has been called - the log file needs to be processed for consumption through TeamCity.
import sys
import argparse
import subprocess
import os.pa... |
The rules are unsurprisingly:
Write a program that prints the numbers from 0 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."
#include <stdio.h>
int main(void) {
int i, j;
... |
I have an app which has a session mechanism. When a user creates an account in the app initially, the API returns an access token, the expiry date of that access token and a refresh token which can be used to retrieve a new access token when the existing access token expires.
I have written this singleton class to stor... |
This post is the first in the MathCore series.
The next post is here: Arbitrary precision π (Circular Constant) in Java - MathCore #2
Disclaimer
My project is too big to be reviewed in a single question. So, I'll post one class at a time.
The relevant methods needed from other classes are added as snippets.
Roots.jav... |
I am working on a script in Python 3.5 that will take in data from several large files. The script takes a while to run, so I am trying to optimize the functions that take the longest. In particular, each file contains around 1 million arrays of around 200 floats.
I need to:
compute the difference between consecutive ... |
I'm trying to figure out some way to improve the code below. My main problem is the method getPrice.
Some advices:
In the else clause, I need to query the information in the database (using EJB injection).
The ProductPrice and MarketPrice are very different JPA entities. So, I can't refactor them to use inheritance/co... |
Again playing around in R with a Edx CS50 homework.
Performance relative to %in% is above my expectation. But I still wonder whether I am breaking any good practice/style, norms, or common sense overall or in the tiniest detail.
BiSearch <- function(table, key) {
# Takes sorted (in ascending order) vectors
stopifn... |
This little project is about working with doctrine Entity object and everything is working fine.
This is my first project in Symfony 3. Please review my service file and give me some advice to improve it. My main concern is lack of error handling.
service.yml
parameters:
services:
app.ToDoList:
class: A... |
This code works and does exactly as I want, but I am wondering if/how it could be done faster/more efficiently? This runs quickly on a demo file, but bogs down when I introduce much larger files (3-100GB).
Premise:
Take a large list of latitudes and longitudes remove the negative values (WGS1984) and put them into a No... |
Continuing from yesterday, here's a simple solution in C to part 1 of Advent of Code Day 2.
I used a simple state machine to map from each keypad key to the next keypad key given the input.
// http://adventofcode.com/2016/day/2
//
// "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.... |
Here are the requirements:
If initial_invoice? is false, existing_invoice always exists.
If initial_invoice? is true and existing_invoice exists, I'd love to use the existing_invoice.
I'd love to refactor this code.
existing_invoice = find_existing_invoice(invoice_obj[:id])
invoice = if !initial_invoice?(invoice_... |
I am learning concurrent programming and am writing a thread safe LRU cache for practice. Below is my first attempt. Kindly comment and let me know where I can improve.
PS: There have already been a few questions asked on this topic but a more toned down version will help me understand the underlying concept of concu... |
Problem: Write a function to convert Integer to String, using only
pointers, without array indexes, string must be dynamically
allocated.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// move each character in array one place to the right
// we need to make place for new character on the left
void... |
I've wrote a function where the doubles from a string are removed:
def removeDoubles(string):
output = ' '
for char in string:
if output[-1].lower() != char.lower():
output += char
return output[1:]
For example:
removeDoubles('bookkeeper') = 'bokeper'
removeDoubles('Aardvark') = 'Ardva... |
I've written the following code where all vowels are removed from a string except if the string starts with a vowel then this vowel is maintained.
def removeVowels(string):
output = string[0]
for char in string[1:]:
if char.lower() not in 'aeuio':
output += char
return output
I was won... |
I've added a sort function to my library of utility functions. I will need to extend its behaviour at a later time but for now it's just a replacement for the qsort() function.
I've implemented Yaroslavskiy's Double Pivot QuickSort which is fast and easy to implement (and has been selected as the sort of choice for Jav... |
I'm trying to test my implementation of ports-and-adaptors for tkinter.
Assume I have a tkinter Entry declared like so:
entry = tk.Entry(container)
entry.value = tk.StringVar()
entry.configure(textvariable=entry.value)
In module ports.py I have a simple function to set the value:
def set_widget_value(widget, value):
... |
I'm navigating to a view. I have an EventDateTime property which I want to set to DateTime.Today unless the navigation is coming from MyCustomView
This is what I've come with so far. It's working, but I find this really ugly:
public void OnNavigatedTo(NavigationParameters parameters)
{
if (parameters != null)
{... |
I have a file with mostly 0 and 1. For each line I would like to compare it against all others (without the redundancy) and count the different combinations. It is slightly more complicated as there are also "N" in the matrix when there is missing data. For example if the two lines are:
line1 = "0 0 1 0 1"
line2 = "0 1... |
I have written following code to solve Sudoku puzzles in Racket (a Scheme/Lisp derivative programming language). Following relatively simple code appears to work but are there any bugs in it or can it be further optimized? (semi-colon indicates start of comment on that line).
(define (SolveSudoku sentboard)
(define (... |
The class I'm using is called Review and looks like this:
public class Review
{
public virtual Guid Id { get; set; }
public virtual int Rating { get; set; }
public virtual Guid RestaurantId { get; set; }
public virtual Guid UserId { get; set; }
}
I'm using a LINQ statement to first check a few thing... |
I am a C++ newbie, and trying to figure out what the best practices are for writing the "Big Five" member functions, as prescribed by C++11's unofficial "Rule of Five".
My class with a raw pointer is:
class MemoryBlock
{
public:
// Default constructor
explicit MemoryBlock(): _length{0}, _data{nullptr} {}
ex... |
I wrote this to be able to compare two different arrays to figure out how many words were in common as a percentage value.
The use case is that I have array a which is a list of the most commonly known and used words in a language (normally something like 2000 different words).
In array b I have the text.
The end resul... |
This is the Good Numbers problem at Code Chef:
A number is called a square-free number if there does not exist a number greater than 1, whose square divides the number. For example, 8 is not a square-free number as 4 (the square of 2) divides 8. Similarly, 4 is not a square-free number. However, 1, 3, and 6 are all sq... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.