instruction stringlengths 71 71.9k |
|---|
I wrote a C program that builds a social network graph of characters in a novel. The program takes two text files as input: a list of the names of the characters in the novel, and the file of the novel itself. The output is a list of name pairs, representing times where those two names occurred within five lines of eac... |
My task is to use the following pseudocode and improve it (make it run faster). Also I have to analyze the runtime of the given pseudocode and of my new code that i improved.
What does this algorithm do? It finds the smallest and greatest number in an array and creates the difference of them.
Pseudocode (given in task)... |
The following query is taking over 800ms to run, and returning 300 rows. When deployed to SQL Azure, it takes much longer on an affordable price tier.
SELECT
Tests.Id,
Tests.Title,
Tests.AuthorId,
Tests.[Status],
Users.FirstName + ' ' + Users.LastName AS AuthorName,
(SELECT
COUNT(1)
... |
I'm trying to make a small parabola calculator just for fun. Is this code good?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define _X_UNTIL_Y(q,w) \
while (argv[1][q] != w) { \
q++; \
}
#define _ATOI(s,d,f,g) \
strncpy(s, ... |
I have written a simple PHP Script that takes $_POST input and uses it to add data to a .json file. Given the security flaws in my last post, I wanted to post this just to make sure. I can't see anyway for someone to attack my server using this program (especially because this is a script for an internal website), but ... |
In my application I have an accounts model:
class Account < ActiveRecord::Base
belongs_to :user
has_many :invoices
end
The Account model belongs to the User model. After the user is created, some default accounts must be created:
class User < ActiveRecord::Base
has_many :accounts
after_create do
Account.c... |
This is a class which provides a simple event system mechanism:
template <typename T>
class EventChannel
{
private:
using idType = unsigned int;
static idType& getId()
{
static idType id = 0;
return id;
}
static std::unordered_map<idType, std::function<bool(T)>>& getHandlers()
{... |
I have a WPF project with Prism 6 and EF6. In my project I have a MainTabModule which has four ViewModels. One of these ViewModels is called ContactViewModel.
The MainTabModule will initialize and resolve my EF context and will also resolve my services. Finally I register my views to the regions in the Shell. This mean... |
I'm trying to make a small program which takes a number (form 1 to 1000) and shows the primes between 2 and that number. Right now I have a quite functioning program (except a couple of bugs), but the problem is that it needs a lot of cycles. In the worst case scenario (limit = 1000) it takes roughly 2 million cycles t... |
Based on the previous question, I have improved it to make it insert regular function. Also, I have implemented a new template approach to obtain the signature from any function by testing its operator().
I would like to know how I can improve it further.
#include <functional>
#include <typeindex>
#include <string>
#in... |
I am trying to learn C coming from Python. Below is an implementation of bubble sort, slightly optimized. Any advice on best practices, readability, use of macros, and edge cases would be greatly appreciated.
// Int Bubble sort slightly optimized
// USAGE: ./bubble_sort 7 3 5 4 0 1
#include <stdio.h>
#include <stdlib.h... |
The purpose of the following function is to find all non-empty directories, and the files in those non-empty directories. It recursively checks each directory on an SFTP server to see if it has any files, and if it does, adds it to a default dict using the path as the key. The function uses paramiko.SFTPClient and stat... |
I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, strdup, malloc andstrcpy. The program makes the correct output for another program (my program is a shell command language interpretor) showing that I have 1800 lines of code:
$ cat *.c *.h|wc -l
{cat} {err... |
I've a sample code to create a simple menubar here which works, but I'm not sure if that's the best way to code it. Can somebody please validate if there is a better way to do the same?
In short
I've create a sample page with a directive called <menu-bar>
<menu-bar></menu-bar>
The directive merely points to a templa... |
Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has the largest sum = 6.
For this problem, return the maximum sum.
My solution (pseudocode and code) is below. ... |
I'm very new to Python, and so I'm trying to learn it by doing simple programs, like a calculator. But I don't know if this is the "Pythonic" way to do it, or if I am making beginner errors.
So could someone please tell if something is wrong with it, and how to improve it?
Here is some sample input and output:
Enter t... |
I have two Dictionaries with around 65,000 KeyValuePairs each. I used foreach and if-else statements to compare them and get values, but it goes very slow. How could I optimize my code and gain more speed?
private void bgwCompare_DoWork(object sender, DoWorkEventArgs e)
{
var i = 0;
foreach (KeyValuePair<strin... |
I discovered the FizzBuzz test while looking up something else on stackoverflow, so I decided to try it and see what I would come up with. I'm kind of new to jquery and JavaScript, so I'm looking for a critique on my code. What can I do better? Changes? Simplifications?
My priorities on this were -
Maintainability &... |
I found myself wanting to brush up on some notions about parsers and grammars and, at the same time, to exercise my Haskell - I am a Haskell newbie; moreover, I haven't touched the language at all in a couple months.
You can find the complete result here, and, separated by hrs and without the module boilerplate, pasted... |
I made a program that can modify a list using commands that the user enters.
The commands that are supported are (used from actual program):
/add [value1] [value2] [valueN]... - Add a value to the list
/rvalue [value] - Removes a value from the list
/rindex [index] - Removes the value at the specified index from the l... |
My today's goal was to create a function, which would evaluate the entropy of a given string password. It's mostly about how random the password is.
This little code is based on the C# code from Jeff Atwood answer post on Calculating entropy of a string
Based on the wikipedia article I checked this as ok, still I am un... |
I've written tests that use Bash for testing a custom shell. I think the tests work but I'm sure you know better because this is my first test I write this way.
#!/bin/bash
echo "-- Testing our implementation of OpenShell --"
echo ""
echo "- If you have any problem in passing a test read the corresponding"
echo "- sou... |
I'm trying my hand at an address book and the goal is for it to have a bit more of error prevention. For instance, for the key "phone" to have 10 digits, and not allow alpha characters at section 4. I believe I have formatted this properly to the best of my ability. I understand this is very elementary as I'm new to an... |
def age_post(post) do
birthday = Timex.date({post.birthday_year, post.birthday_month, post.birthday_day})
now = Date.now
years = Timex.diff(now, birthday, :years)
Integer.to_string(years) <> " ans"
end
I'm quite new with the elixir language, I'm pretty sure you can get the same result than that... |
I have written my own solution to the Reader-Writers problems using semaphores based on the psuedocode from Wikipedia. I would like to gauge the correctness and quality of the code.
import java.util.concurrent.Semaphore;
class ReaderWritersProblem {
static Semaphore readLock = new Semaphore(1);
static Semaph... |
I have a response String as shown below which I need to parse it and store it my class. Format is shown below:
task name followed by this dotted line ------------- which is also fixed
and then just below key:value pair. It can have many key value pair
Below is the response string.
abc-------------
Load:79008
Peak:49... |
defmodule Baby.Post do
use Baby.Web, :model
schema "posts" do
field :cover, :string
field :email, :string
field :firstname, :string
field :lastname, :string
field :birthday_day, :integer
field :birthday_month, :integer
field :birthday_year, :integer
field :description, :string
f... |
I am preparing for a coding interview and I have the following questions:
Find the biggest positive number sequence in the Integer Array.
If Input is [1,2,5,6,-7,5,7,8,5,6,7,-6,7,0], then output should be
[5,7,8,5,6,7], which is the longest positive digit sequence.
Below is my code for the above program:
public c... |
I wrote a C++ implementation of a sparse table (I wrote it for an arbitrary function) and I want so much to ask for a review. I'd like to know how I can make it better, especially the consistency of the code and the design.
Explanation:
For example, you want to solve the RMQ problem with a lot of queries. You can preco... |
I need a function to remove duplicated pairs from a list. The following is example list:
a = [1, 1, 1, 2, 3, 5, 4, 4, 5, 2, 3, 3, 2, 3, 1, 6, 6, 6, 6]
I need remove all pairs [a[i], a[i+1]] if a[i] == a[i+1] until all such pairs eliminated:
[1, 1, 1, 2, 3, 5, 4, 4, 5, 2, 3, 3, 2, 3, 1, 6, 6, 6, 6]
[1, 2, 3, 5, 5, 2, 2,... |
I've created a simple utility class for use in my Unity2D project, which allows a Sprite to have separate sprites for when it is facing East, North, West, or South (that's the order that z-axis rotation places them in). There aren't too many Unity-isms in the code, and the part that I'm most concerned with is the inter... |
This is a simple pool allocator, based (to at least some degree) on a previous answer. The basic idea is pretty simple: allow a user to allocate objects of some type quickly (in relatively large contiguous chunks) and only free objects when the allocator itself is freed, then destroy all the objects and free the memory... |
I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). Instead of directly using smaller and smaller h, we can solve for the slope m in y=mx+B with a given B. That B represents a specific h after some substituting and simplifying where B = f(x)... |
I have a text file with the following three line pattern with blank lines in between. My script sorts alphabetically by each person's last name and preserves formatting. I would love to see other options to improve this in Bash. For example, the group command that redirects into final.txt repeats a lot. Also, it would ... |
I am studying Gang Of Four design patterns and I want to implement a builder pattern in Java.
It seems there are two options to build a builder pattern:
Using two different classes: A target class and a builder class
Using a nested static inner builder class inside the target class
Using builder class as a separate c... |
For a while now, I've wanted to write a stack-based "Turing-tarpit". This is the perfect excuse to learn Ruby, which I have never used before, so I wrote Brain-flak.
The language only uses these characters, ()[]{}<> in various contexts. Here is the interpreter:
class Stack
def initialize(name)
@name = name
@d... |
I am completely unaware of all the Android features and available libraries.
I just designed a login system to practice it. I have referred to a few books and tutorials.
Layout
I am using relative layout. And have two EditText and one button for login and one button to start register activity.
Activity
public class Log... |
I made a simple list with drag and drop ordering function using JavaScript, HTML and CSS. Although I tried to do this as efficient as possible, I'm sure there are some improvements to be made.
What would be considered bad practice in my code below and what could be improved or are there any suggestions for another appr... |
I have a photo_shouts_controller.rb and text_shouts_controller.rb which both have almost similar implementations, and I would like to refactor it.
I have implemented a refactoring but I am not too sure if that is the best way to do it.
Current implementation
class PhotoShoutsController < ApplicationController
def cre... |
Previous question
After applying the suggestions, I wanted to revise the question with the new code because I don't think this is good enough.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* global loop counters */
int i=0, j, k;
/* to find a, b, and c from the input */
float A(const c... |
I have a list of conversion histories, where information about user channels is stored. For example user may have app for iOS and Android installed. Each time user logs in, I store a conversion history, so that there might be multiple rows with shared data (e.g. client is always iOS).
I need to get the latest usage of ... |
The Gilded Rose Kata is a refactoring challenge, in which some frankly disgusting code is thrown at the developer, and they're told to make a small change to it. For reference, the (truncated) requirements and the original code are given here:
All items have a SellIn value which denotes the number of days we have to ... |
I am getting the number part of the container ID that the button is in. Now I am wondering if I need to create an array using split and then put this number in a variable, or if there is a more efficient way to get it.
.match() also returns an array, so this is almost the same as using split.
I mean the code works and ... |
I began studying C# 5.0 a few days ago and am trying to avoid duplicated code for validation of input values.
class transcript
{
//Use lamda expression and Func for validation logic
Func<byte, byte> validate = (grade) =>
{
if (grade > 100)
throw new ArgumentOutOfRangeException("grade can`t be more than ... |
This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Mendelian inheritance. The repository with all my up-to-date solutions so far can be found here.
The next part of the Rosalind challenges is basically asking for a Fibonacci solver, with a twist.
Problem: F... |
I want to run an application and write (append) its processing time into a file. Also, I want to see the stdout and stderr output on the shell, but don't want to write it in a file. After running the process, I'd like to see time measured.
Since I'm on Bash, one solution would be this one, but it's pretty ugly, since t... |
I'm trying to work with the following class, which is inside a library I currently cannot change:
// This class represents "external" code as far as my review
// request is concerned: I cannot change this, currently.
public class AddressDto
{
public string Name { get; set; }
public string Zip { get; set; }
... |
Even I know that this isn't a good way of writing code, but I need to improve this.
Here I am retrieving data from Server in Json format by Posting some variables in doInbackground. Getting all the products depends on Posting variable ie Latitude and Longitude of Current Location.All the Json data are stored in LocalD... |
Write a program that can calculate the Hamming difference between two DNA strands.
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^ ^ ^ ^^
The Hamming distance between these two DNA strands is 7.
import java.util.Optional;
public class Hamming {
public static int compute(String s1, String s2) {
valida... |
I posted an earlier version of this code a couple of days ago, so it's the updated version of the code posted here.
#include <iostream>
#include <functional>
#include <conio.h>
#include <unordered_map>
#include <string>
class EventListenerHandle
{
template <typename U>
friend class EventChannel;
pr... |
I've implemented a class, which provides access to different static resources, which are used by different frontends. I'm hesitating, because in Java getters and setters are quite wide spread. So my question is, if this code smells bad?
public class ResourceManager {
public static final Preferences Preferences = ne... |
Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a count of these elements. Now push the current element into the ordered stack and pop the count number of elements from t... |
Description:
Bob is a lackadaisical teenager. In conversation, his responses are
very limited.
Bob answers 'Sure.' if you ask him a question.
He answers 'Whoa, chill out!' if you yell at him.
He says 'Fine. Be that way!' if you address him without actually
saying anything.
He answers 'Whatever.' to anything else.
... |
I'm actually doing my own Prolog compiler just like SWISH one with Java. Prolog is a logic language that is particularly suited to programs that involve symbolic or non-numeric computation. Prolog consists of a series of rules and facts. A program is run by presenting some query and seeing if this can be proved against... |
I need to sort a list of lists. The following is a compare function:
def compare(lhs, rhs): # lhs&rhs are lists
delta = len(lhs) - len(rhs)
if delta > 0:
return 1
elif delta < 0:
return -1
if lhs < rhs:
return 1
elif lhs > rhs:
return -1
return 0
It looks pretty ... |
I wrote this wrapper around the UdpClient,using events for new datagrams:
Class EventedUDP
Implements IDisposable
Dim Client As Net.Sockets.UdpClient
Dim Endpoint As Net.IPEndPoint
Public Event RawDatagram(sender As EventedUDP, datagram As Byte(), ByRef handled As Boolean)
Public... |
I'm writing a small program that generates a file containing an adjancency matrix, it then reads from that file, constructs a graph and does something like a parallel depth-first search (dfs) on it.
How can I make the dfs part faster, because now it seems to be doing a lot of nothing (each thread just sets the nodes pa... |
/**
* Execute an external program, display raw output in real-time, and buffer output pipes (stdout, stderr) for further processing.
*
* @param string|array $cmd Command to execute (not escaped)
* @param string[] $output_buffers Buffers to capture
* @return int Exit status code
*/
function tee($cmd, &...$output_b... |
I wrote this program to convert binary to hex, it ignores other characters between the binary digits. I would like to receive any recommendations on how to improve it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char table[] = "0123456789abcdef";
int main(int argc, char* argv[])
{
int flip = ar... |
I am going through some of my companies EDI reports to see if I can make them faster. The query below runs in less than one second in our AWS RDS environment, but it takes ~55 seconds on a blade in the office, so there is room for improvement. I do not see any common performance culprits based upon Google searches, b... |
I am trying to implement a hash table in Objective-C. I did some testing and the implementation seems to work. I am using an NSMutableArray to store linked lists of entries. It also resizes when it gets almost full. I am using an NSString for a key and any object as a value. I store NSNull objects in an NSMutableA... |
I have written a class that is designed to be an automatically keyed Map in Java.
Here is my implementation:
import java.util.Collection;
import java.util.Map;
import java.util.Set;
/**
* A {@link Map} that is automatically keyed.
*
* @param <K> the key type for the map
* @param <V> the value type for the map
* @... |
I'm developing a middleware for my client and it's found that there are some delay when executing the process. We are currently investigating what's the exact causes of the issue, from architecture design to coding.
Here is part of the script we are calling, which is working, and I'm just wondering if it's optimized an... |
Right now, I've got this really ugly loop in my code that waits for a boolean to be true before the method can return. It's triggered when "Done" is clicked. I'm wondering, what is the proper way for me to delay this method's return until the button is pressed? How should I refactor this code so that it follows common ... |
My goal is to read from standard input, break up the input into words, case-insensitively, and produce a report to standard output, where each line is a word followed by a space followed by its count. The output should be sorted by words.
This is my code:
use std::collections::BTreeMap;
use std::io;
use std::io::BufRea... |
I have a table that name is Store , In Store Table , just one row can IsDefault=true at time . when I insert new Row , I check If user selected IsDefault , I update other row whice isDefault=true . I use this code :
public AddStatus Add(AddStoreViewModel storeViewModel)
{
if (Exists(storeViewModel.Name)) ... |
I'm implementing a lazy constructor in C++. The goal is that for a type T, lazy<T>(args...) returns a callable object which, when called, returns T(args...).
This is what I have done so far:
#include <functional>
#include <utility>
/**
* Returns an object of type `T` constructed from `args`.
*/
template<typename T, ... |
I wrote the following code for this problem. The problem is to find the longest palindromic substring.
I think it is correct and is working correctly for all the test cases I entered myself. Now, the code is producing a Time Limit Exceeded Error. I know that there exists Manacher's Algorithm which does it in linear tim... |
Let's say I following have code:
private bool ErrorLogExists(LogEvent logEvent, DateTime filterStart)
{
var startTimeFrom = logEvent.StartTime.TruncateMilliseconds();
var startTimeTo = startTimeFrom.AddSeconds(1);
return _existingErrorLogs.Any(x =>
x.Name == logEvent.Name &&
x.EventDateTime... |
I have the following input array:
$arr = array(
'water' => array(0, 1, 2, 3, 4, 5),
'apple' => array(1, 5, 3, 4, 0, 0),
'beer' => array(0, 0, 0, 0, 0, 0)
);
Now I want to know which element has largest sum, so I have the following code:
$arrWeight = array();
foreach ($arr as $key => $value)
{
$arrWeight[$key] = i... |
My goal is to learn a bit more about generic programming in C++. So, one of the trickiest things I've heard you can do is creating a Variant class. This took me a while and I needed to read and study a few implementations:
#ifndef VARIANT_HPP_INCLUDED
#define VARIANT_HPP_INCLUDED
#include <cstddef>
#include <typeindex... |
So, there is this king-of-the-hill challenge going on at PPCG SE to which I submitted my participation. I won't change it further in terms of behaviour, so I wanted to know what you think of the code.
The challenge
It is very well described in the original post, I'll just summarize the key ideas here.
Setup
A pile of ... |
The code snippet is what I want to do. Previously I use a different version of my code. But it is out of joint according to Python coding guidelines because I was assigned my lambda function to a variable. It was an obvious violation. Here is my violator code:
my_dict = {
'first_name': 'Jimmy Floyd',
'last_name... |
I want to improve my skills so i startet a very basic MVC framework. Its my first MVC based Framework.
Index
I rewrited all requests through index.php and the file looks like this:
<?php
namespace System;
use System\Core\App;
use System\Libraries\Config;
use System\Libraries\Database;
use System\Libraries\Registry;
... |
Custom class Image takes a 2-D array of 0's and 1's upon initialization. Method transform returns a modified array by modifying 0's adjacent to a 1, such that
[[0,0,0],
[0,1,0],
[0,0,0]]
returns
[[0,1,0],
[1,1,1],
[0,1,0]]
I've been working on method blur(n), which outputs an array that has been transformed n ti... |
Given two python lists a and b. These lists may intersect (It is possible that lists intersect more than once). An example:
a = [1,2,5,7,6,9,1,3,1,2,6,6,3,1,2,6,1,3]
b = [3,1,2]
There are 4 intersections:
[1,2,5,7,6,9,1,3,1,2,6,6,3,1,2,6,1,3]
[3,1,2] [3,1,2] [3,1,2] [3,1,2]
For each intersection I c... |
I have written some codes in java implementing simplest genetic algorithm. The code finds (or rather tries to) the maximum value possible for a user-defined number of bits. For example, for 16 bit chromosomes, the code tries to get 216-1. I have never had my code reviewed by any one good, so the thing I am looking for ... |
I have details of key decisions made by a business in a worksheet "Decision Record."
My data is laid out as follows:
I have written some code to create a timeline of these decisions using an XY scatter chart, like this one:
The code works fine, but as with most of the code I write, it doesn't look tidy to me. Perhaps... |
This is a builder pattern implementation to build immutable Person objects:
Person class
public final class Person {
// All are set to final to make Person Immutable
private final int id;
private final String name;
private final String surname;
private final boolean isOccupied;
// Constructor ... |
I want to let you look through my NetHandler which is basically the component which gets notified when a full packet arrived (not like tcp-packet but my own type of packets) and handles it.
First of all, the handle method which gets called from the networking
void NetHandler::handle(int id, char* data, int len) {
#defi... |
I've just finished writing my code to return the prime factors of a number and I feel the GetBestFactors function could be improved.
The GetFactors function was hacked together from the code found here:https://support.microsoft.com/en-us/kb/202782. This returns all the factors of a number in a collection.
The GetBestF... |
(See the next iteration.)
I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have:
StackMergesort.java:
import java.util.Collections;
import java.util.Random;
import java.util.Stack;
import java.util.stream.IntStream;
publ... |
Does this look like a proper implementation of a hash table in C++? Any errors anyone can find?
Thanks in advance (:
template <typename T>
class HashTable
{
public:
HashTable(int amount)
{
size = amount;
values = new T*[size];
for (int i = 0; i < size; i++)
{
*(values + i) = nullptr;
}
}
~Ha... |
I'm trying to follow the DRY programming philosophy and I am tired of running isset() and an if not empty statements for each time I want to check a $_GET[] variable.
I am working on a page that receives up to 4-5 GET parameters in the URL, so I wrote the following function to reduce repetitive code:
function getset( ... |
I am just getting into the world of javascript, coming from the world of classical inheritance. The following is a library I wrote to track when a webapp is idling and I wrote it like I write classical inheritance. But what I have heard about javascript is you have to completely forget how classical inheritance works.
... |
I am trying to complete this challenge. The user should enter a sequence of instructions, = to link two numbers, and ? to query whether two integers are linked. For example,
? 1 2
= 1 5
= 2 5
? 1 2
should produce
no
yes
I have tried following the algorithm given here to the letter, but I keep getting a judgment of "t... |
I am writing an ASP.Net MVC app which has a page that will display a standard table which will contain a person's hours for the week. The basic structure of the table would be a 7 column, muti-row table. The Header of each column would display the Day of the Week with the total hours worked that week. There would then ... |
From LeetCode medium 3. Longest Substring Without Repeating Characters:
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "w... |
I have an HTML form where I need to do the following
when value of Select Box changes to initial "Not Selected" value (where values of the option is 0), I am to highlight the select box, when it's non-0, restore the original coloring of the select
when I submit the form, and the Select box value is 0, do not submit th... |
I am trying to implement quadtree for my Barnes-Hut algorithm implementation. I am not sure that the code I've wrote so far is good implementation - it is dirty, and tend to be slow.
Of course I am also aware that the results might be correct, but I'd be glad if someone can take a look at that and give me a hints. Bec... |
I've been learning Haskell recently and I decided I needed to work on a (somewhat) realistic problem.
What I'm most interested in getting feedback on is how well I've used the tools in Haskell to accomplish the goal of converting Roman numerals to Arabic values. I suspect that my approach is more verbose than it needs... |
I'm a beginner and am self taught and was hoping I could get help from others more educated than me to show me what bad practices I might be forming before I go on further.
P.S. This program is just for me to learn, I'm not actually storing passwords with it.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
de... |
After my previous post, I decided to work on the project myself for a while (two weeks) to see how far I could get after reading a few of the really helpful answers to my previous posts. I read up on stuffs to learn a little more about the stuffs mentioned in the answers (MVC, interfaces, packages, etc) and read a lot ... |
For my project I have rewritten a small lib for a tree structure that was inspired by wangzuo's js-tree.
The reason was largely because I prefer to work with an array structure rather than nested objects.
Could you advise me if you see any bad practices?
I will work with React.js for an important project and if you not... |
I am starting to learn ASP.NET, and I am designing a page for an admin to login and do some stuff. I have the username and password for the admin stored in Web.config (Is that a good practice?).
Second thing, I am checking if the user filled the username and password fields, then I am checking if the values for the adm... |
I was trying to solve the Longest Common Subsequence problem on a HackerRank exercise.
It's quite simple and straightforward, just print out the length of the LCS. I submitted this code:
s1 = raw_input()
s2 = raw_input()
lcs = [[0 for j in xrange(len(s2)+1)] for i in xrange(len(s1)+1)]
for i, x in enumerate(s1):
... |
I am working with the following code:
import numpy as np
def sigmoid(x):
return 1.0/(1.0 + np.exp(-x))
def sigmoid_prime(x):
return sigmoid(x)*(1.0-sigmoid(x))
def tanh(x):
return np.tanh(x)
def tanh_prime(x):
return 1.0 - x**2
class NeuralNetwork:
def __init__(self, layers, activation='tanh'... |
I am novice at creating independent classes for user. I have seen many Reachability library for Swift, but I need to create my own class for that. Here is my code:
class SwiftReachability: NSObject {
let REACHABILITY_NOTIFIER_KEY = "reachability_notifier_key"
var backgroundQueue: NSOperationQueue?
var isCancelled: Boo... |
The below produces the output I want. Namely, it initially displays the first item on the list and the first expander link. When an expander link is clicked, it hides that link, unhides one more item in the list, and unhides the next expander link.
I'm wondering if it can tightened up. JQuery is a definite no-no.
w... |
I have made a small script for encrypting data. Now I'm wondering how efficient it is for normal users who aren't programmers and for people who are programmers.
I mean if you don't have this script there is no way to find out what the text is right?
function cipher(message, action) {
var text = message;
var encryp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.