I am new to TensorFlow and I would really appreciate if someone could look at my code to see whether things are done efficiently and suggest improvements.
This code works okay and achieves around 91.5% accuracy on test data. The only real issue I have is a low GPU usage during training reported ...
I'm writing my first CMS (personal use) and I'm trying to make it the most secure I can. This is my project structure:
.
+-- css
| +-- images
| +-- style.css
+-- includes
| +-- config.php
| +-- connection.php
| +-- footer.php
| +-- header.php
| +-- session.php
| +-- user.php
+-- ...
Hi guys i have a string "key={value}&key2={value2}&key3={value3}" and have to produce a key-value pair of the string by splitting & and =. Also i have to watch out for corner cases such that if a key isn't present do not add it to the hash map but if a value is missing the key can be added with a...
Following is a very crisp solution for solving n-queens problem in Racket programming language. The method is to get all permutations (so that no 2 queens are in same line) and to check these for any of them being on diagonals:
#lang racket
; FOLLOWING FN RETURNS TRUE IF QUEENS ARE ON DIAGONAL...
I wanted to try implementing my own version of a C++ Thread Pool (I know there are lots of them..).
I was hoping that someone could tell if I did it okay.
Tasker.h:
#pragma once
#include <memory>
#include <queue>
#include <thread>
#include <mutex>
#include <shared_mutex>
#include <condition_...
In the past I always did AsyncTasks as private inner classes. The tutorials I found still recommend this (see here, here, here, and here). However, this has the potential to leak the context. Now Android Studio even warns about this and recommends making the class static.
I followed this advice....
#This is logout code where i applied the logic #
* the variables are correct as they are used in the code for future reference*
private void logoutWebService(String systemId, String imei, String lat, String lng ) throws ParseException {
SimpleDateFormat formatter1 = new SimpleDateFormat("h:mm...
I am reading a book that has some difficult vocabulary and I, in order to understand the book thoroughly, decided to collect and lookup those words am not acquainted with, spend sometime learning them, and re-read the book.
I have created an interactive console application specifically for this ...
Sorry was busy; based on the nudge in the right direction: what i still had to do: get the Evaluations, through the call GET http://MYTFS:8080/tfs/TFSCOLLECTION/TFSPROJECT/_apis/policy/Evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/TFSPROJECTID%2FPULLREQUESTID&api-version=2.0-preview given you have ID for your builddefinition you look for item->configuration->settings->buildDefinitionId; this should only be for 1 iteam in the evaluations; with this ID you can call the patch. Where is the button to accept the answer? It seems I am blind — Klemens Altmanninger47 secs ago
I have a dictionary of words of the following format (this is dico_en.txt):
alleged alleged ə.ledʒd a-ə,ll-l,e-e,ge-dʒ,d-d SUFFIX_NONE NULL al.leged 7 5 2 6658 PREFIX_ASSIMILATE all LIST 6 6
allegedly allegedly ə.le.dʒid.li a-ə,ll-l,e-e,g-dʒ,e-i,d-d,l-l,y-i SUFFIX...
I have developed software which plots x, y points on a dot plot. A typical graph looks like:
I started out with an array of arrays e.g.
[[564, 768, 75486, 88496], [7365, 98, 761, 8].....]
In the above example, each inner array contains 4 properties for each 'event' i.e. for event 1 the val...
I am learning Laravel ATM and I created a dynamic query of sorts using OOP. Just now I've come across this article: here In the comment section it stated that when creating a connection with the database it is better to use a static function instead. Revisiting my code after reading that comment ...
import java.util.Date;
/**
* A fix-sized array of students
* array length should always be equal to the number of stored elements
* after the element was removed the size of the array should be equal to the number of stored elements
* after the element was added the size of the array should ...
I have a function that makes some calculations and in general case returns an object with all required information, otherwise in throws an exception:
def f(*args, **kwargs) -> Success:
if everything_is_ok:
return Success(data)
raise Exception('..')
The problem is now I need to proc...
I have a text file containing the following data.
ascon1 201707011 John 77.5 11.5 11.5 11.5
ascon1 201707012 Grld 70.0 11.5 11.5 11.5
ascon1 201707013 Josh 79.5 11.5 11.5 11.5
ascon1 201707014 Jess 67.5 11.5 11.5 11.5
ascon1 201707015 Jack 97.5 11.5 11.5 11.5
I need the data to look like th...
I wrote a review yesterday for somebody's code. However, since it is out of my specific area of expertise, I would like someone else to give it the once-over, just to make sure I haven't misdirected the author of the code. What's a good way to get this to happen when my review has been accepted?
...
Just had a problem where I wanted to be able to have a data type that could be looked up with an index or key.
It seemed like a useful thing, so I fleshed it out a little:
I've tried to make the behavior as 'normal' as you would expect.
It supports slicing with key and integers
you can do a...
My goal is to precisely calculate the current timezone using C++ standard library, represented as the offset (in seconds) between it and GMT time.
Example: Italy is GMT+1 so my expected output is -3600. This offset represents the difference between italian time (i.e. 12:00) and GMT time (i.e. 11...
A general principle in API design which brings you quite far is to always look what PHP is doing, and then doing the exact opposite thing. — PhilippJun 17 '14 at 16:21
I don't think I'll really ever use Haskell, but it's given me an appreciation for better ways to write code, especially around side effects and failures
I'm learning Swift at the moment but I would like to produce well-organised code. The goal of my little app is to display the weather of my current location.
I use :
the API of Darksky : https://darksky.net/dev for fetching the forecast data
the Reverse Geocoding With CLGeocoder for fetching t...
Can the following code to swap two bits be optimized?
//ecx = bita, the index of the first bit to be swapped
//edx = bitb, the index of the second bit to be swapped.
//r8 = data, the int32 who's bits are to be swapped
//code ;latency //comments
mov eax,1 ;1
shl eax,cl ...
Changing TextBox.Text within the TextBox.TextChanged event can trigger a
recursive call to the same event handler. My class EventHelper is designed
to separate the action performed in the event handler from the mechanism that
prevents the recursive calls. The calls can be used as in:
public stat...
TS just isn't 'smart' enough to infer any of these types, so you generally have to specify a lot of them. And there's no syntax as far as I am aware that would make it possible to type R.lensPath properly. You'd have to explicitly specify those types
If I were to type this I would generally put it in it's own function and explicitly type the function instead of trying to use the generic type signatures that ramda comes with
Is it reasonable to pass project instance (which has method I want to multithread) to thread instances? Any comments welcome, even on how to name files as I am new to splitting code into multiple files.
main.py:
from helpers import MyThreads, MyThread
def MyProject(object):
def __init__(s...
Following source code (constrcutor):
public EventData() {
totalNumber = 0l;
events = new ArrayList<>();
}
I have no idea for what:
totalNumber = 0l;
Is best a good practise?
I am working on unit converter application. I used revealing module pattern to handle the logic. Converter is working but there are few things that bother me:
I tried to separate view from the logic but I am not sure it is done
right. Should I add view implementation to my module? I thought abo...
I've been working on making word's mail merge automatic in C# using Interop Services. It works, but for generating 47 files it takes 2-3 minutes, any way I can make it faster?
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
namespace Vizsga...
So, to start with I have:
var tempArray = [];
tempArray.push(get);
In this case, the get variable grabs the html of a cloned div.
What I've tried, but doesn't seem to affect the array at all:
tempArray.join(' ');
What I always get:
tempArray[div , div]
Fiddle: https://codepen.io/Bes7weB...
I've been reading that exceptions should only be for something "exceptional" and not used to control the flow of a program. However, with a CQS implementation, this seems impossible unless I start hacking up the implementation to deal with it. I wanted to show how I implemented this to see if t...
This program converts a date given from the French Republican Calendar to the corresponding date in our standard Gregorian Calendar. Im looking for some improvements that I should start making in my code as well as some tips on how to write less lengthy code.
For example, the RepubtoGregDate fu...
Look for all six letter words which are composed of two concatenated smaller words.
Please give me feedback regarding good coding stands.
*
import java.io.File
class KataExercise(val wordLength: Int) {
fun concatenatedWords(): List<String> {
val searchWords = dictionary
...
For multiple files I expect a loop. There is only one file handled in your whole code. This would be a feast for code review by the way. flag1 = true; return flag1; Really? Or if (!flag1) return; That is also utterly useless. — oerkelens15 secs ago
I have created a method to show a treeview of nested lists with radio buttons to select a category. I have a model called CategoryModel:
public class CategoryModel
{
public int idCategory{ get; set; }
public int idParentCategory{ get; set; }
public List<CategoryModel> childCategories...
@Heslacher I was reading an API for work that required returning a HTTP 202 Accepted status code, and thought it was quite humorous, so decided to copy @200_success. ;)
In swift, both of these are valid:
public static let x: Int
static public let y: Int
Is it down to personal taste, or is there some best practice? Do other common languages impose a specific order?
Is there any way I can modify the poisson-disk points generator finding here. I need to generate new poisson points using the coordinates of points in the textfile.txt to improve the distribution.
Below is the c++ code of poisson-disk sampling in a unit square.
poissonGenerator.h:
#include <v...
@ScottCraner: May I beg to differ - there is an endemic problem with the code as written, that penalizes performance by multiple orders of magnitude; and I believe that Financial Analysts who encounter this problem will look to Stack Overflow rather than Code Review for help. — Pieter Geerkens49 secs ago
@PieterGeerkens It does not matter where they will look. StackOverflow is for problematic code, while code review is for help in speeding up code that works. It is a matter of sniper vs shotgun. Stack Overflow is a sniper, specific problems. the betterment of code is too broad for this forum, by the standards set. Where as it is not for Code Review. That is why Code review insists that the code works. — Scott Craner34 secs ago
@ScottCraner: Except the posters at Code Review are anal-retentive _____s who care far too much about code style, and never help with any other actual problem. As long as that situation exists, Code Review is useless for this type of performance. — Pieter Geerkens11 secs ago
I tried solve the knapsack problem first time without view the solution. Here is the code:
int knapsack(vector<int> v, vector<int> w, int m){
int q = 0;
for(int i = 0; i < (int)v.size(); i++){
int k = 0;
if((m - w[i] < 0) || (v[i] == -1)){
v[i] = -1;
continue;
}
k...
Guys this a question i got part of foobar challenge
You're awfullyclose to destroying the LAMBCHOP doomsday device and
freeing Commander Lambda's bunny prisoners, but once they're free of
the prison blocks, the bunnies are going to need to escape Lambda's
space station via the escap...
When sanitizing the $_POST passed from the controller to the model, I need to sanitize the input and there are 2 options that I can think of.
For the first one, I can nest the if blocks like this:
if(!empty($username) && !empty($password) && !empty($csrf))
{
if($query != nu...
A lot of the Python code that I write looks something like this:
import logging
logger = logging.getLogger(__name__)
def foo(arg1, arg2):
logger.debug("arg1: %s", arg1)
logger.debug("arg2: %s", arg2)
# Do something complicated with `arg1` and `arg2`
...
The logging statemen...
Here is my orchestration endpoint where I call customer endpoint and product endpoint. Product endpoint contains info about what customer have what product. I do not like how it look and smells as shit hope there is a better way to do it. Ple
@RestController
public class ApiController {
pri...
My input file is a CSV of varying size, up to around 10GB. The file has several fields, however I'm only interested in the third column, a date-time field. The date-times are in UTC timezone, and they are not ordered.
Example of values in column:
2017-08-03T10:22:31.000Z
2017-08-03T10:22:32.000...
I am dealing constantly with the following code.
The thing is that literally it makes no sense for me to have all the spacing and divisions in the if-else when the code is so small that can be a block by itself.
When I read a line within line breaks I expect something difficult to understand o...
I have a function that validates data and returns a Boolean value if it's validated. Otherwise it will return a String with a message. Is this bad form? Or is it fine with what I'm trying to accomplish?
Private Function validateForm() As Object
If lvw.CheckedItems.Count = 0 Then
Retu...
I am working on improving my bash environment. I have added the following function to my ~/.bashrc in order to facilitate modifying my PATH as well as removing duplicated from my PATH which may occur from sourcing ~/.bashrc again.
# $1 the path to be added as an absolute path
# $2 a boolean for ...
I have some currency fields which need to be added together. However, some of them have a checkbox nearby. If this is ticked, the field is added to the subtotal, if not, nothing is added.
I'm currently using the code below, which works, but doesn't seem very elegant or easy to maintain. I'm sur...
I have the following, working code:
import pandas as pd
hld_per = 12 # Holding period in months
quantiles = 10 # Number of bins/buckets; Deciles, use 10; Quartiles, use 4; etc.
permnos = pd.read_csv('Ranks.csv')
my_headers = list(permnos.columns)
total_cols = len(permnos.columns)
pntls = p...
What
Beam search is a best-first search algorithm that does not necessary find an optimal path, yet has smaller memory-footprint. In this program, I attempted to answer a question how does it compare to A* and whether bidirectional beam search provides any improvement over unidirectional variant...
@Srnu If you have a solution that works, but you'd like it improved, post it on Code Review. This site is primarily for fixing broken code. Note though that Code Review requires that the code is working and complete. — Carcigenicate17 secs ago
@DanielSanchez I'd be more careful with wording: "post this" should probably be "post regarding this code of yours". See also. — Andras Deak17 secs ago
I think you would gain value from posting on Code Review instead of stack overflow. There are a lot of things that need to be addressed and their scope is more oriented for that site. — Erich17 secs ago
The class (Reader) reads log files by chunks, each chunk represent an event. It processes events top to bottom until a given maximum is reach. In others words, it reads until it's full.
For the Reader to start reading again it needs to empty its events list. To do so, another class needs to call...
unfortunately solutions like this don't pass code review in my company: blog.bdoughan.com/2012/01/…. with an unbounded number of IBar implementations, an explicit switch on type is a maintenance burden at best & breeding ground of bugs in the average case. polymorphic dispatch should be used instead of instanceof checks, but it's not clear how to actually use that approach in this case. — robotic_pancreas23 secs ago
Hi I have made a rest web service using express framework. Below is my snippet of code. I have repeated code in below code. I am creating a currencyItem object in two blocks and push it into an array.
I think it is not bad practice. Can anyone suggest me Is it OK? if not how I can improve it ?
...
I have a table that is linked to two other tables by foreign keys. Except that I can't actually link to the other tables in my queries because the table has millions of rows and the queries would take waaaaaaaaaay too long.
I'm trying to implement a single linked list based on Linus' comments about double pointers.
In my case I'm also using a tail pointer and I'm wondering if there's a better way to update the tail pointer which does not require the conditional below?
I'm still new to C so any other critique is a...
@202_accepted Well, I tried implementing the naive way, and when the query timed out after more than ten minutes, I knew that I had a problem. There's no way in heck the users would put up with a refresh rate of more than a minute. As it is, they're going to be complaining it's too slow, but unfortunately there isn't anything more I can do.
No, I've worked with bigger. The telemetry data warehouse was bigger. Still not that big by modern standards of big data, but big enough to be an interesting challenge.
What makes it tricky is that the users need filtering and sorting on as many columns as possible, and the page size can be set in a range from 10 to 100 records.
Here, I have written a simple FIFO multithreaded queue with following features (if I have implemented correctly):
Thread safe
Supports multiple container types (given that they provide some function) via template meta-programming
queue size can be limited
has several policies for enqueuing item...
It sounds like what you really want is a code review, so I suggest you to go ask your question at codereview.stackexchange.com . Bear in mind that people there will be able to help with python optimization and code inefficiencies, but the tuning of parameters such as number of epochs, bias vectors, and above all learning rate, will take someone with experience in the training of word embeddings (/ machine learning in general). For the latter, you should explain what your implementation does at a higher level. For instance, I'm not sure whether you use or reimplemented glove. — Nikana Reklawyks33 secs ago
thanks jon! can u provide an example of a template reference that would not be component relative? ie it work in jit but not aot? I'm not sure how someone would configure the template url in a different way then I did in the example I provided, but I'd like to know what to look for in case I'm doing a code review sometime — user857049536 secs ago
I have a struct with a double array member. The problem is that instances of this struct all seem to use the same array. This leads to all the structs being identical to the most recent struct that was initialized.
struct myStruct {
private:
double x[2]; //rx,ry,rz,vx,vy,vz
publ...
Upon visiting my website, I check if a cookie is set into the user's browser and proceed to logging him into his account. Currently I do the cookie check in my init.php file and I am asking where I should put it instead because I don't feel like this is the ideal place to be.
Here is my init.php...
This is a fixed up version (following RAII principles) of my previous reviewal. I have moved the construction of the object entirely to the constructor to prevent any bad object states.
The only thing I am slightly concerned about is if an exception is thrown, the destructor will not be called t...
I have been trying to make a roguelike for years. Ever since I was a kid I messed around with it. I have a working prototype now, but it takes forever to write the code for each and every place that you can walk in the game. Is there some way to make it easier? Like a variable inside a variable? ...
I'm developing a more complex website which requires several stylesheets for the frontend and the backend that are loaded only if some specific conditions match.
I'm developing in scss and compiling the files using gulp.
In my gulpfile I then declare an array with all the frontend stylesheets a...
This is a question from careercup.com. You are given an alphanumeric string. Complete the function sortSegments that will segment the string into substrings of consecutive letters or numbers and then sort the substrings. For example, the string "AZQF013452BAB" will result in "AFQZ012345ABB". The ...
Simulation take as input many parameters. Assume simulation is in scripting languages like python or Matlab. Example of such inputs is a mixture of double arrays/matrices and Boolean values like below:-
alpha =-3
beta = true
gamma = 1
cost1=ones(2,3)
cost2=zeros(4,2)
One simple way is just li...