instruction
stringlengths
71
71.9k
In my previous post Optimise compare and match method using scripting.dictionary in VBA I wanted to address optimising the scripting.dictionary approach I was using and I feel I have achieved that (feel free to correct me though!). I am now implementing user input boxes which have also increased the complexity and now ...
I have an ItemData class in my program that stores saved data about a game inventory item that can change, such as its durability, quality, number of bullets in the clip and similar. ItemClass, on the other hand, lives in a DLL, and holds data that is always true for specific item, such as its name, max durability, siz...
editArticleService.show(item.facility, item.administrator, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, q30, q31, q32, q33, q34, q35, q36, q37, q38, q39, q40, q41, q42, q43, q44, q45, q46, q47, q48, q49, q50, q51, q52, q53, q54, ...
Wherever the biggest number is always use the 'big' value If another number is equal to that number, use the 'big' value Set the next number in line to 'medium' If another number is equal to that number, use the 'medium' value Set the next number in line to 'small' If another number is equal to that number, use the 'sm...
What is Spellathon? The rules of Spellathon are as follows: Create words that have 4 to 7 letters. Include the center letter in every word. Form at least one 7-letter word. Plurals are acceptable. The dictionary used is in English. Here is a similar implementation. The dictionary (word list) I'm using is this. public...
How can I calculate simplex numbers in all dimensions? Example: dimension: 2| 3| 4| simpl(1) 1| 1| 1| simpl(2) 3| 4| 5| simpl(3) 6| 10| 15| simpl(4) 10| 20| 35| simpl(5) 15| 35| 70| First I considered about a recursive implementation...
Description Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter. You'll be given a string of characters representing the letters the user has dragged their finger over. For example, if the user wants "rest", the str...
This previous iteration of this question can be found here A utility class to handle the state of the Application object. Storing the application's initial state (ScreenUpdating, EnableEvents, Calculation) Disabling those settings for performance improvements Restoring the original state Operations that may nee...
I've made my first turn-based game in PyQt5. I suppose that its idea can also be used by other novice GUI programmers. There is a 5 by 5 squared unpainted field and 4 players. Each player starts at corner square and has his own colour. Player can move to adjacent square and fill it with his colour if it isn’t occupied ...
I've a file which is divided into two parts: The header The data part The header has of course a different format than the data part. The header part contains lines that look like this KEY: VALUE or KEY : VALUE or KEY:VALUE, in theory, clearly. The data part starts with a delimiter, which in my specific case should ...
To get n-th member of a struct without non-empty bases and w/o non-public members C++ now have a pretty way: #include <type_traits> #include <utility> #include <tuple> struct filler { template< typename type > operator type (); }; template< typename aggregate, typename index_sequence = std::index_sequence<>, typename...
I'm trying to write a C++ multiplication program using classes (for the first time - I usually try to avoid OOP) and am having trouble freeing my memory. What I'd ideally like is a matrix class with a function for allocating, initializing, multiplying, and freeing my matrices. What I currently have is #include <iostre...
Is this algorithm good or can I improve it? static void QuickSort(int[] a) { QuickSort(a, 0, a.Length - 1); } static void QuickSort(int[] a, int start, int end) { if (start >= end) { return; } int num = a[start]; int i = start, j = end; ...
Shortly, I need to create a Java application with client/server architecture (clients represent some sort of math functions and when they are done computing, server consumes these values and produces a final result). Also, there are should be two types of cancellation, first one allows to stop the server by entering a ...
I'm an absolute newb when it comes to PowerShell, and this is pretty much my first real script. I'd now like to know ways to improve it and if possible to shorten the code even further. I use it together with an XML file containing links and keywords to download the "latest" version of different applications to keep my...
This snippet is about a generic matrix type. The nice part is that given two matrices with respective entry types, say, of short and float, the result matrix entry type after the multiplication will be float. matrix.h: #ifndef MATRIX_H #define MATRIX_H #include <algorithm> #include <iomanip> #include <iostream> #inclu...
The function is to click a button, the browser window then scrolls to the top of the page, then a class is added to a menu item (with CSS to make the sub menu appear). Then when the cursor leaves the sub menu, the class is removed to allow the sub menu to disappear. Can I make the following code shorter or more efficie...
I am working on a sorted data file, so there does not need to be any sorting logic. I find unique values, feed them into an array, then use the worksheetfunction.sum to get totals for a field. Is this as efficient as I could be, or are there some things I'm not seeing and should? The "Items" sheet is where a number of...
I used strtok to tokenize a string. But many developers said me to avoid strtok, why? How should I optimize this code? Is it really wrong that I used strtok? If so then with what should I replace it? DWORD FN_attack_speed_from_file(const char *file) { FILE *fp = fopen(file, "r"); if(NULL == fp) { re...
I am reading in a file which consists of scores between two teams. The team that wins gets 2 points, if the teams tie both teams get one point. The result is ranked by points and if there is a tie ranked by alphabetic order. Then this is written to an output file. Any suggestions to improve the code? Input file: Bl...
I am new to C. And I just want to know if my code is horrible or not. I tried to make program to delete all comments in C program. It's from "The C Programming Language Second Edition" book, Exercise 1-23. Here is my solution : #include <stdio.h> #define MAXCHAR 1000 int c = 0; int d = 0; int newFileText[MAXCHAR]; int ...
I'm writing in Python (3.4) a double search function that looks in a list for one value and then the other alternatively. That is, start searching the second value once you find first the first value (and start searching from where you found the first value) and vice-versa. My first approach was to write a recursive fu...
Imagine you want to run a bunch of tasks in parallel, but you can't be sure that all of your tasks will eventually terminate or rather decide to eat up all your memory and CPU time. This should be easy, right? Create a new thread, run your task, and kill the thread if it doesn't terminate in a given time slot. Well, he...
We are using the following for evaluating strings for a pseudo fuzzy search. Curious if anything sticks out as needing optimization function getEditDistance(a, b) { if (a.length == 0) return b.length; if (b.length == 0) return a.length; var matrix = []; var i; for (i = 0; i <= b.length; i++) { ...
The following Function is one of the main analysis functions of a larger subroutine. The subroutine is responsible for translating codes that look like this "1|G|XNYM:O:LO:201611:P:44:+1/XNYM:O:LO:201611:C:51:+1" to something similar to this "LIVE WTI American X16 44.00/51.00 Strangle". There are multiple scenarios ...
I'm new to React.js and I've written a simple notes application as my first React program. I would like to know if it is idiomatic React code. List.js var React = require('react'); class List extends React.Component { render() { var items = this.props.items.map(function(item) { return <li key={item.id}>{i...
I want to achieve this var arr = [1,2,3]; var duplicateArr = duplicate(arr, 2) // will be [1,2,3,1,2,3] var duplicateArr2 = duplicate(arr, 3) // will be [1,2,3,1,2,3,1,2,3] I have implemented it like this: function duplicate(arr, n) { var len = arr.length; if (n == 0 || n == 1) { return arr; } if (n > ...
This is my best effort at converting a 32 bit integer in EAX, to an 8 character ascii string (result in RDI). It will work accurately up to 99,999,999. Higher values could be done using an xmm register. The byte order in RDI is correct (e.g. if copied directly to video ram, the most significant byte is displayed fir...
I was writing a basic calculator program to practice my skills at python. I'm a beginner at Python and was wondering if there is a way to simplify this code of mine? It seems a little bit too long and messy in some sort of way. Again, I'm still a beginner so I don't know all the tricks in the book! import math import t...
Keep in mind i'm not an expert or developer, working in IT operations and improving my coding skills. Goal: Trigger to send email when a specific configuration table is updated or deleted. Should never happen unless done for a release CREATE TRIGGER [Cfg].[t_tablename_TrackConfigChanges] ON [Cfg].[tablename] AFTER INSE...
I'm working on my data structures knowledge and wanted to create a graph with a small DFS driver which simply prints the nodes as it visits them. Here's my graph class: #ifndef GRAPH_H_ #define GRAPH_H_ #include <stack> #include <random> #include <iterator> #include <unordered_map> #include <unordered_set> template <...
I am an R programmer who is learning C++/Rcpp. I wrote some code to recreate survey adjusted contingency tables a la SAS's surveyfreq procedure using Taylor Series linearization to generate standard errors. Here is the documentation from SAS that I used as reference.I've reached the point where I know my code is correc...
I wrote code to demonstrate the Infinite Monkey Theorem which states that if a monkey types at a keyboard for an infinite amount of time it will almost surely type a given text such as William Shakespeare. Here I've replaced the monkey with Python code. I have a sentence and let Python choose from the 26 letters of the...
Over the last couple of weeks we build a huge Javascript menu. And we might think the whole code is a little bit too much. We are not pros, but came to a quit acceptable solution. (yeah it´s German, we know) We used jQuery-3.1.1. and jQeury-ui. I´ll put a short overview of the menu at the end. The question is, can we s...
Using Python 2.7 and here is my code which implement trie match for a whole word, and also support if the whole word contains ? (match any one character) or * (any zero or more characters). My question is wondering if any improvement I can make (in terms of performance) and also if any code functional bugs, please feel...
I coded a python solution for the question below. I am after the fastest solution. Also, I would be grateful if you could point out parts that are not pythonic / inefficient. Question: A website requires the users to input username and password to register. Write a program to check the validity of password input b...
I have modified a Z-Algorithm for string similarity in order to match strings which differ in 0 or 1 char. However, it seems much slower than original Z-Algorithm although from my point of view there is only a minor different and it also has a O(n) time complexity. Input is a string in which a pattern is going to be fo...
This is my second game, not yet finished but working. I've put so much time into it I wanted to get feedback before continuing. I always learn so much from those that comment. Whilst my first (still a work in progress), is object orientated, this isn't. Given that though, I certainly appreciate the OO method more now....
I'm beginner java programmer and would like to ask you to take a look at my code. I wrote small rest service among with tests. Now I have to questions to ask. The test methods: @Transactional public class CustomerControllerTests extends RestApplicationTests{ @Autowired private WebApplicationContext context; ...
Working on below problem and post problem and my current code. My idea is to always iterate from the minimal in-degree node which has not been visited before. Then based on this node to do a BFS. I am not sure if there are better ways to implement in terms of performance. If you also find any other code issues or bugs,...
I have an abstract class Consumer: abstract class Consumer { const API_DOMAIN = 'https://test-api.com/v1/'; private $client = null; private $credentials = []; public function __construct(array $credentials) { $this->client = new Client(); //This is GuzzleHttp/Client. $this->credent...
I have made this PHP login page. As far as I know, this is secure enough to avoid attacks and injection. This script: Notifies me with an e-mail when someone logs in or fails to login Only one user at a time CAPTCHA Secure session Auth lasts for 20 minutes Password is stored with MD5 hash Max 3 login attempts, then it...
(See the next iteration.) I have this small template function for conveniently dumping a sequence into a string such that there is a delimiter between two consecutive elements, and no such after the last element: #include <algorithm> #include <iostream> #include <iterator> #include <sstream> #include <string> #include ...
I wanted to cache methods using unity interception and not have the parameters passed in stay alive for the sake of caching. If the objects would have gone out of scope without caching then the cache should be invalidated. Also wanted to use MemoryCache class as if memory is low the cache should be the first thing to...
I have a CSV containing ~600k part numbers to be uploaded to my website's inventory. However, this CSV only contains limited information. We're missing pricing and other related information. To get this information I'm required to make requests to the provider's API, and add it into the CSV. At the moment, I've been sp...
I am using MVVM pattern with databinding. I have written tests. But I want them reviewed. The test is related to JUnit test on the ViewModel. FeedViewModelTest.java @RunWith(PowerMockRunner.class) @PrepareForTest({Observable.class, AndroidSchedulers.class}) @PowerMockIgnore("javax.net.ssl.*") public class FeedViewModel...
Problem statement I've tried to solve the following Euler problem in a very straight-forward way, ideally avoiding recursion if possible and writing it in a functional style. What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? The full ...
I am working on a program to decode MMS PDU files. They are binary files and I am reading them byte by byte and decoding each header value as I come to it. One header value is the Date, and it's represented as follows (in hex): 85 04 57 E2 A2 49 0x85 is the "Date" header, 0x04 is the data length (4 bytes) and the 4 f...
One of the things believed to contribute to destabilizing Rubberduck 2.x, is the fact that a lot of COM object references are stored in many places, and Marshal.ReleaseComObject is never called for those, which is what the alleged problem would be. To fix this, I've undertaken the task of completely wrapping the VBIDE ...
I am working on a program to decode an MMS PDU file. In the file, the "content-length" is represented in a unique way. According to the MMS spec WAP-230 Section 8.1.2, it is encoded as a "Variable Length Unsigned Integer". Basically for each byte, the 1st bit is the "continue bit" and the other 7 are the "payload". ...
I'm trying to call a promise recursively. If I get a responseData with a key error I want to call the promise again and again until I don't get it. _getUser (url) { console.log('fetching url', url) return fetch(`$(url)/api`, { method: 'POST', headers: {}, body: '{"key" : "body"}' }) ...
I have coded a sudoku grid validator as a problem set from an online course. My input to the validator is a list of lists, that represents a sudoku grid. For reference, below are examples of an ill-formed sudoku grid, an invalid one, and a valid one. # check_sudoku should return None ill_formed = [[5,3,4,6,7,8,9,1,2],...
I have recently finished developing my ASCII based snake game. As a newbie to C++ I would appreciate it if I was given feedback as to how I could improve my code when it comes to efficiency and readability. #include <iostream> #include <cstdlib> #include <conio.h> #include <vector> using std::cout; using std::cin; usi...
I wrote a program to convert spaces to tabs. If there are 4 spaces it should convert them to tab. Please let me know how to improve it. #include <stdio.h> #define TABVALUE 4 int c, d, s; int main(void) { c = s = d = 0; while ((c = getchar()) != EOF) { if (c == ' ') { s++; for (i...
I made a simple linked list in C with the following functionalities: Create(creates the list); Find(searches for an element in the list); Insert(inserts a value at the beginning of the list); Destroy(destroys the entire list). It only uses integers (for simplicity), and I want to know for possible errors and how to imp...
I must write updates in a database from a flat file (CSV). I want to do that in the shell, with tools such as AWK. #!/bin/bash cat in.csv | sed -e '1d' | awk -F';' -v q=\' '{ # For each line. print "DECLARE @v_trmID varchar(16) = " q $1 q print "DECLARE @v_trmNom varchar(6) = " q $3 q print ...
I load some data from from my webservice via a method using blocks and callbacks. From my ViewController I make a request to the data loading class and pass the callback block: - (void)loadRadioStationList { [self.radioDataLoader getRadioStationList:^(NSArray *data, NSDictionary *dictData){ self.alphabetiz...
This asks the user if they would like to enable stack overflow protection. If they enter yes (Y or y), then a Boolean SOProtection is set to true. If they enter no (N or n), then SOProtection is set to false. If neither Y, y, N nor n is entered, then it clears the input stream (to protect against a case where multiple ...
I'm learning C++ as well as algorithms. Here's my implementation of finding the closest pair problem. I tried to minimize memory by using only iterators. And points are being read from points.txt file content: 2,1 3,5 8,3 5,8 9,1 5,2 3,3 4,5 6,5 1,9 Output is: Closest pair are: 3, 5 4, 5 Here's the code: #include <...
I don't really want to convert to using classes, but other feedback is appreciated. Game loop is at the bottom. colors.py r = '\033[0;31m'#red o = '\033[1;31m'#orange y = '\033[0;33m'#yellow g = '\033[0;32m'#green b = '\033[0;34m'#blue v = '\033[1;35m'#violet B03 = '\033[1;30m' B02 = '\033[0;30m' B01 = '\033[1;32m' B00...
I was wondering if someone could please point me in the right direction with this bit of JavaScript I have been working on. I have made this form that currently has onblur JavaScript validation and additionally I am to make it dynamic so that when a user selects an option from a dropdown option form a div is shown with...
This is a follow up of this question Optimal substructure of ED: Here is the reasoning behind my solution: let \$x = (\alpha _{1},\alpha _{2},\alpha _{3},...,\alpha _{m})\$ and \$y = (\beta_{1},\beta_{2},\beta_{3},...,\beta_{n})\$. We define \$c(i,j)\$ for \$ 0\leq i\leq m\$ and \$0\leq j\leq n\$ as the minimum edit di...
I have 3 classes: Server, Client, RequestHandler It's about reading out commands and executing them What the programm does: 1) The Server starts, opens a ServerSocket and starts listening for Clients on that Socket. 2)Several Clients start and try to connect to the socket. 3)If a client succesfully connects to the Sock...
The PowerShell script below queries the Security event log on one or more servers for events with id 4663. When trying to retrieve all audit events for event id 4663 with the following code the computer throws the following exception: how can we to optimize this PowerShell? So I just want to fetch security event log ba...
Curvesort is an adaptive integer sorting algorithm I discovered independently. It maintains a doubly-linked list, whose nodes have the following structure (in pseudo-C code): struct node { int key; int count; node* next; node* prev; } Above, count gives you the number of times key appeared in the seque...
My app, particularly the MainActivity suffers from some lag when I scroll through the RecyclerView. I tried to fix OverDraw as much as I can. This is what my OverDraw screenshot looks like: activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr...
I developed a cost to ship app in python. To use this app, you will need to install wxpython. Please review and tell me the areas i can improve. import wx # including a module class Test(wx.Frame): # creating a class def __init__(self, parent, id=wx.ID_ANY, title='McCastle App\'s - Shipping Calculator', pos=...
I am new to java and graphics, and I am creating a java program that draws a star. It took me a few hours, but I finally have it drawing a star, but I am wondering if there is a better way to write the "draw" method without having to repeat myself over and over. I am trying to use loops to minimize all this code, but I...
I have a school assignment to allow a user to enter a GTIN and then validate that it is correct. I have finished the code, but my teacher has told me I will get more marks if I can make it more efficient. I realise I could use a loop in lines 5-12, but am not completely sure how. Any feedback is welcome, but I'm real...
It is my first program in Clojure. It read RSS feed's list from text file, get each feed and store result into sqlite database. project.clj: (defproject cowl "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://...
I made a particle simulation in vanilla JavaScript. It can currently handle around 10000 particles (staying 58-60 fps on my machine). For testing, controls are MB1, MB2, R, Z. How can I make this more efficient? var width, height; var head = []; var hcount = parseInt(prompt("PARTICLE COUNT? <Default: 10000>")) || 100...
I need to implement a queue of requests which can be populated from multiple threads. When this queue becomes larger than 1000 completed requests, these requests should be stored into a database. public class RequestQueue { private static BlockingCollection<VerificationRequest> _queue = new BlockingCollection<Verif...
This is my solution to the common 'Array Rotation' algorithm. As I am currently practicing for coding interviews, I want to make sure that my code in fact valid for coding interview scenarios. Would I lose points for using JavaScript's built-in shift and push array methods? function main() { var n_temp = readLine().spl...
I am trying to write a simple program that allows to encrypt a string of plaintext so that it can be transmitted via an "insecure channel" by which I mean a "regular chat"; be it Skype, Facebook, or even email or something similar. This is what I came up with: At first, one user, Alice, will generate a cryptographicall...
The code below extracts data from one web page - I emulate search, select all results from the list and when the list appears (42000 items) I loop through these items. I get an id value from their href to create a proper link (example href is href="javascript:NeuFenster('rb_id=570964&land_abk=bw', so I don't want any J...
I wrote the following prefix tree data structure for this Leet code challenge. Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. However it keeps timing out on the long input. As far as I know the insert, search and startsWith ...
I am new to "modern" C++ and decided to learn about smart pointers by implementing a doubly linked list. I have a few problems with this code: Should the tail pointer be a weak pointer? Should the head pointer be a unique pointer (If yes, then the node after head will have a weak_ptr to the head node, causing a unique_...
The goal of this function is to open a menu with a CSS class (animation is done through CSS transition), call an overlay on top of content and prevent scrolling at the same time. Also, since the designer didn't add any hamburger icon, I created a class (.header.isG_navSemiOpen) to add an in-between transition to tell t...
Can you please provide some improvement advice for the following function? It is working OK now, but as I have zero experience with PHP I guess there is a lot of room for improvement. function addNewUser($ES_Client, $username, $password, $fullname, $email, $function, $department, $access){ auditLog($ES_Client, "Cre...
I made a program that uses the Adafruit pressure sensor, and the DHT22 temperature and humidity sensor to log pressure, temperature and humidity every 30 minutes. I left it outside my house overnight yesterday in the hopes that it would have logged all the data overnight but it had logged only once. I'm guessing it dra...
I'm displaying a conflict marker for each actor for each day, if the current day is in their conflicts: <li v-for="date in next_three_months"> <template v-for="actor in cast"> <template v-for="conflict in actor.conflicts"> <i v-if="date.datestamp==conflict.datestamp" class="is-conflict"></i> </template>...
Here's my script: def index(seq, item): """Returns the index of an item in an increasingly-sorted sequence (if exists) otherwise returns the index where it would be inserted, using binary search. seq: a sequence. precondition: seq is sorted increasingly. """ # Updates the se...
I had read about quicksort in some articles. Is this is a correct implementation of quicksort? function quicksort() { // Setup data to sort $data = array(); for ($i=0; $i < 500; $i++) { $data[] = rand(0, 515); } // Begin looping for ($x=0; $x < count($data); $x++) { for ($y=$x; $y < count($data); $y++) { ...
This is my first ever program written in Rust (after reading the book). It is small tool to sort all lines from stdin according to two criteria. First one is time when given log line was generated - in my case files contain logs from many applications which all uses same time source. The second is related to the fact t...
I've written a small CLI node program to list the contents of a directory with an output similar to that provided by npm ls but listing both files and directories, not just directories. I wrote this for two reasons: Personal interest: practice recursion Frequently I want see the contents of a directory without having ...
Question: Find the largest in a list that list is stored as two sections, one in ascending order and the other in descending order. Elements are distinct. E.g: Input [2 3 4 5 6 7 10 9 8 7] Output: 10 My solution is below. Works on my unit-tests. Want to know if there any improvements from the coding point of vie...
I am new to Javascript and jQuery. I made a calculator by looking at other calculators, codes. I don't know so much Javascript methods, so I stick to eval method because I have no idea to produce answer in another way. I didn't create any function. Instead I lock buttons with Booleans changed by pushing buttons. I ...
I was using early bind to reference the dictionary and realised that some users might not be willing to manually add the reference to use it and just consider the macro to be 'broken'. I looked at programmatically enabling the reference but that would still require the user to go through several steps to change their m...
The goal of the code review by order of importance (i.e. What I hope to hear from you): I've verified correctness using a straightforward matrix multiply function though I am open to those who want to verify correctness. I'm just starting to learn about the benefits and challenges posed by coding things in SSE, while ...
Using Python 2.7 and here is my code to calculate ROC/AUC and I compare my results of tpr/fpr with threshold, it is the same result of whay scikit-learn returns. My questions, (1) any ideas for improvements (especially for performance in my existing code) (2) any smart ideas to calculate of AUC? import numpy as np from...
I was given an assignment to create an implementation of a tokenizer object (by object, I mean a struct with associated functions that operate on instances of the struct). This tokenizer retrieves tokens from an input string given the following rules: The input string cannot be changed Tokens can only contain digits ...
I came up with the following for a blocking and non-blocking queue implementation. Please suggest any changes/improvements/gotchas. Blocking queue: public class BlockingQueue<T> { List<T> buffer; private static final int MAX_QUEUE_SIZE = 100; public BlockingQueue() { buffer = new ArrayList<T>(); ...
Where I currently work I'm tasked with writing a good encryption and decryption code which will have DEK as well as KEK. Haven't started on KEK yet. I have already told them, that we need expert help, but I don't think I am going to get any. Any tips on KEK how to generate them and where to store them? (HSM ?) would be...
I have done my first PHP-MySQL project with MySQLi connection. Please review this and inform me about security and performance issues. dbconnect.php $DBhost = "localhost"; $DBuser = "root"; $DBpass = ""; $DBname = "mysqli_login1"; $DBcon = new MySQLi($DBhost,$DBuser,$DBpass,$DBname); if ($DBc...
I am trying to make a simple model that returns the conditional expectation of a target with respect to the value observed for another variable. Basically, given a feature \$F\$, a level of this feature \$f\$, and a target \$y\$, the predicted value is: $$p=\mathbb{E}[y|F=f]$$ As much as possible, I tried to follow sk-...
(See the previous iteration.) Now, I have defined an iterator for dumping contents of a sequence such that the last element is not followed by the separator string. main.cpp: #include <algorithm> #include <iostream> #include <iterator> #include <sstream> #include <string> #include <vector> using std::cout; using std::...
I want to send mail which will have day to day report. I have setup action mailer like this class ReportMailer < ApplicationMailer ... def send_stats(hash) @emails = ["my@email.com"] @stat = hash mail(:to => @emails.join(","), :subject => "Daily Count of tasks") end end The send_stats method will ...
I want to create a function that splits an image into many separate blocks that when put together look like the image as a whole, often called a Rasterbator. Given the number of tiles for height and length I want and the image to Rasterbate I want the function to draw the split up image with a little padding in between...
I've been trying to reduce the indentation from a method in my code. The solution will probably be unrelated to the language, in this case python, although it may rely on some python specific libraries e.g. itertools. The code below is part of this implementation of Kruskal's algorithm. def generate_diff(self, ndarr, ...
I recovered some spaghetti code and I have to refactor it. I do not want a method with over 200 lines, for me it is not object oriented programming. I am trying to ponder on the question and would like to have your suggestions. private static IQueryable<Trade> BuildTradeQuery(IRepositoryFactory repository, SearchCriter...