instruction stringlengths 71 71.9k |
|---|
I have a one function to calculate all the possible widths plus the margins for the gutters.
In this same function, the grid extensions such as the pull, pushand offset functions are also calculated.
@function calculate-one-column() {
$a: 100%;
@if ($gutter-width-px > 0px) {
$a: ($a - ($gutter-width-procent * ... |
I want to calculate the ratio of intersection between two intervals; the length of the intersection divided by the length of the shorter interval.
If two intervals do not intersect, the ratio is 0. If one interval is fully contained in the other, the ratio is 1, otherwise it is a number between 0 and 1.
These interval... |
I have a function that iterates through a block, tests each value against a given function and is placed in a block associated with the product of that function.
CATEGORIZE items test
An example:
categorize [
"Aardvark" "Bison"
"Antelope" "Baboon"
"Anaconda" "Basking Shark"
] [first item]
Results in:
[
... |
I have the following MATLAB Code which I want to optimize.
It's related to an image matrix (2D) which I want to filter.
Though it is MATLAB code, the same problem would arise in C code.
The problem is that I'm trying to access neighbors of the pixel which might cause problems at the boundaries of the image matrix.
vWei... |
Whenever I needed something similar like a "Class" in JavaScript, I wrote it like this:
function Point(x, y){
var self = this;
self.x = x;
self.y = y;
self.dist = function(){
return Math.sqrt( (self.x*self.x) + (self.y*self.y) );
}
}
var p = new Point(10, 20);
p.x = 30;
alert(p.dist);
I de... |
I wrote this program:
#include <stdio.h>
#define printS for(i=0;s[i];i++){printf("%c",s[i]);}
int i;
char s[] = "Hello World!\n";
void main()
{
printS;
}
It outputs exactly what I want it to but I have no clue if this would be acceptable to use if I were working for a company.
Would this be considered a poorly wri... |
I have to generate the unique key having a length of 8, which should be comprised of some set of characters:
{B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z,2,3,4,5,6,7,8,9}
Now I have written a program that will generate it, but I am not sure it will generate the unique key. Could you please review it?.
static string[... |
For a homework assignment, I made a web page that has a text area. The user inputs some text, hits the analyse button, and the output is supposed to be a list of the frequency of words of a given number of characters.
For example, "one two three" would be two words of three characters and one word of five characters.
I... |
This was my first attempt at making a C++ calculator. The user basically inputs an expression (I'll use \$1+1*(9*(11-1))\$ as an example) and the program searches for and creates a vector for parentheses (which is a class I made which records its position in the string).
String:
[1][+][1][*][(][9][*][(][11][-][1][)][)... |
In JavaScript, any function is basically an object on which you can call (function(){}).toString() to get it's underlying code as a string.
I'm working on a function aimed to do the job in PHP. The intended goal is to convert code from PHP into other languages, such as JavaScript.
It looks like this so far:
function ... |
I'm trying to make my ASP.net Web API methods asynchronous. This method is in the Business Logic layer of my N-tier. I'm waiting for the result from my 1st task and use it on the 2nd task, but I think I'm doing it in a wrong way. Can you please give me advice or feedback regarding my code?
public async Task<DTOUser> ... |
import java.util.Arrays;
public class BinarySearch {
// this class should not be instantiated
private BinarySearch() { }
// searches for the integer key in the sorted array a[]
// @param key the search key
// @param a the array of integers, must be sorted in ascending order
// @return index of key in ar... |
I'm using this code in an app that has hundreds of daily users. The code works, and passes all of the test cases I have.
Occasionally some users report a problem that I don't get right to the bottom of, and there is a possibility it is related to this PermaDict. Can you see anything I may have missed in terms of robus... |
I have a Makefile that is used to automatically process some image files. The basic idea behind this is
copy everything from col-noborder and col-rewnew to col
use ImageMagick convert to copy the files from col-addborder to col and add a pre-defined border
use ImageMagick convert to copy the files from col to bw while... |
I have a function to load the resource identified by a <script> element's src attribute.
I need it to:
Be as universal as possible.
Work on file-to-file requests (from file:// to file://), if the browser allows to.
This is the code I have so far:
var asyncGetContents = function(node,listener){
var hasRun = false;
... |
I had asked earlier for review of parts of my JS file earlier and review of the complete JS file of my project. Now I have made changes as per the suggestions. Here are the files. I would like to get a review of the structure and organization of the code. I have broken down the earlier single file into multiple files n... |
I made a class that connects to my DB and inserts some values. Is it secure or how can I protect this further from injections? The object declaration will come from variables with POST from a form, after being validated, ofc. Just want to know if this is secure.
That, and also, should I make a method for every query I ... |
I often write different applications in C++ using different libraries, and sometimes it takes a lot of time to find where are the *.dll files to distribute. I use Dependency Walker but it still takes a lot of time to look in the GUI. I wrote a PowerShell script that will find all used libraries and do something with th... |
This is my Cython code for an FDCT function (invoked here):
from __future__ import division
import numpy
cimport numpy
cimport cython
FLOAT64 = numpy.float64
ctypedef numpy.int_t INT_t
ctypedef numpy.float64_t FLOAT64_t
cdef inline FLOAT64_t **cosine = [
[
3.535534e-01, 3.535534e-01, 3.535534e-01, 3.535... |
I did two methods to determine if an unordered_set is a subset of another unordered_set, using hashing, and the built-in includes().
I want to see if using a hash function will improve the run time, but I've noticed that there is no really big different in their time, so I start wondering, if what I did is the right id... |
I wanted to have a way to be able to static_cast to the proper derived type pointer of a base class to simulate a virtual call. Here the virtual call is for a reference counting base class:
template<typename TDerived> class ReferenceCounting
which should call the destructor of the TDerived type if the reference co... |
Since one month, I'm learning Erlang and I like it so much.
Today, I wrote an algorithm to solve a problem.
Some time ago, I used two nested for loops in C# to solve it but, solving the same problem in Erlang, I asked myself if there is a better way to write something similar to the two nested for loops I used before.
... |
The purpose of this is to prevent a re-entrant function call in a single thread, e.g. prevent the situation where func() calls bar() which calls func().
This is currently not used in any multithreaded code (and does not plan to be).
struct TranLock
{
static int count;
bool failed;
TranLock() { failed = count; i... |
I am new to programming, and am using Python to take wind data and simulate future wind profiles. The code as written takes a while to execute and I was hoping someone could suggest ways to make my code more efficient...
from __future__ import division
import pandas as pd
import numpy as np
import matplotlib.pyplot as ... |
This code builds template .cpp, .c, .h and .java files based on a file name and #include, import lines provided at the command line. The file opens after creation.
I am looking for a review of this code and seeing if there is anything that can be more efficient.
/* .cpp Example:
* template awesome.cpp iostream vec... |
It's been a while since I've been properly grilled about my code.
I had this Idea which should probably never make it into production code but still I couldn't find anything seriously wrong with it at a glance...
All your comments are welcome.
#ifndef BITFIELDMEMBER_H
#define BITFIELDMEMBER_H
/************************... |
So I have recently tried to load an image and save it, but remove all of a certain color. I'm running the program and it is running really slow, is there a more efficient way to edit an image? My code is pasted below, or at least all that is relevant.
for x in range(50):
im = pygame.image.load("horse%s.bmp") % (x)
... |
Let's say you have two lists of vectors:
v1s = [a, b, c]
v2s = [d, e, f]
I am interested in generating the following result:
angles = [angleBetween(a, d), angleBetween(b, e), angleBetween(c, f)]
Here is my function to do this (it uses vector dot products in order to calculate the angles):
import numpy as np
def... |
I have code that needs to exit gracefully. To simplify things, I am presenting an example based on the answer given here.
Since I need to handle a few signals, I thought of putting this logic in a function:
def set_signals():
original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, exit_grac... |
I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable.
Language: Java7
private int pathsDFS(int currentDepth, int maxDepth, Airports s, Airports e, Predicate predicate) {
int counter = 0;
if (currentDepth > maxD... |
I am trying to write a jQuery Plugin from a piece of JS code I had written. What this plugin does is it converts a select box into a map of Australia where I can select individual states. It's working perfectly well. However, I'd like to know how I can write it with OOP principles like SOLID etc. can someone review my... |
I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename.
import os
import shutil
path = (r"C:\user\reports")
filelist = [ f for f in os.listdir(path) if f.endswith(".xml") ]
for f in filelist:
x = os.path.join(path, f)
os.r... |
The script creates a simple app with a GUI containing an input field and a button to select a folder. On startup a default value is set to the input field. If the user types a value or selects a folder, the new value is stored and validated. If validation fails, the input field value is appended with the error message ... |
I've written a piece of code which combines given letters in groups of n letters, and writes all the combinations in a text file. This is my first attempt and I wonder if there is an optimal way to do this.
letter_input = raw_input(' Type in letters: ')
number_input = int(raw_input(' Letters per word: '))
split_lette... |
Following is the string: (I'm getting that from config file so its not constant):
string sequence = "Concat({ACCOUNT_NUM},substring(FormatDate(yyyyMMddHHmmss,DateNow())
,2,12), GetLast(GetNextSequence(seq_relation),1))";
It contains multiple custom methods and I want them somewhere in the same order as they appear in ... |
I've had a bit of help designing the header for a website here: http://jsfiddle.net/gxLt5/21/
It looks and works exactly how I had hoped. That said, I do feel like the code is a bit grotty, and I'm sure there is a more elegant solution to achiving the same result.
Could anyone please give me some feedback on the HTML ... |
I have this fiddle http://jsfiddle.net/L7zuT/ where I'm working on a small part of a big event program. The functionality is ok, the part of the problem would be the large JavaScript lines needed with the full event program. Is there any way to implement it with DRY (don't repeat yourself) or a better approach for a si... |
Rationale: I often have the requirement to own object instances, while preserving polymorphic behavior (i.e. own the object and hold it by pointer, or reference).
This is usually expressed as a pointer (most of the times, std::unique_ptr<T>), but when the pointer is stored in a std:: container, client syntax becomes tr... |
This is my solution to this question from Hackerrank.
Given N (<= 100000), find the largest N-digit number such that:
The number has only 3 and 5 as its digits.
Number of times 3 appears is divisible by 5.
Number of times 5 appears is divisible by 3.
If no such number exists, produce -1.
Please guide me. Is there a... |
I recently built a way to automagically dismiss firstResponders for an app I'm building. Is there a more efficient way to approach this?
- (void)resignFieldStackRespondersExcept:(id)fieldException
{
for (id field in self.fieldStack) {
if ([field isKindOfClass:[fieldException class]] ||
([[field ... |
I managed to make a perfectly even cross with for loops.
I'm trying to make this cross easier to code. I have to keep it with for loops, but it's too long to implement.
public class CroixDemoAmmeliore {
public static void main(String args[]) {
int e = 5;
int i;
int j;
int k;
... |
What I would like to do is have a method call like:
Database.Modify.InsertOrUpdate<ADDRESS>(address,
() =>
{
var result = ctx.ADDRESS.Where(o => o.JURIDICAL_ADDRESS == "Y")
.OrderByDescending(o => o.ID)
.FirstOrDefault();
return (result != null ? result.ID : 0);
},
() => ctx.ADDRESS.Add(address)... |
I have a search function on my website. In addition, elsewhere I have a place where users can submit categories for their posts. I want the categories to have an uppercase first letter and the rest lower case. I know there far more complex ways to secure a user input string, but do you think that as a fairly basic func... |
I need a code review on my Abstract Factory pattern written in Java.
Find the two enums AnimalType.java and DietType.java below.
package com.patterns.abstractfactory.three;
public enum AnimalType {
TERRESTRIAL("\nLeave on land and breath with lungs.\n"), AQUATIC("\nLeave in water and breath with gills.\n");
private ... |
I have been struggling with a regular expression involving path names. Immediately, this is a bit troublesome, owing to the embedded / in the pattern, but braces to the rescue.
First the convention I have imposed:
Every path in the set looks like:
/ifmxdev/files/file.0123
but that top directory can take a suffix, fo... |
I've previously posted a question about simplifying a query to count votes with a distribution system. One of the contributors, @200_success, pointed out that it calculated the surplus redistribution based on the second favored candidates original votes rather than their second rank on the winners ballots.
How do I sim... |
I'm pretty new to web development with JS and was wondering if anyone can tell me how I can improve my code. I just feel like when it comes to maintainability my code would be very difficult to update. Can someone advice on some best practices or maybe how they do it?
JavaScript
Here is a typical onready jQuery functio... |
I would like your comments on my code in C++ (C++98 + Boost)
I have written some code to use the functors with the boost::range::for_each algorithm.
My main problem was to add some "external" parameters to the functor that are not in the vector on which I am using a for_each loop.
In main() we have:
std::vector<Pe... |
I recently started developing my first serious project in PHP, a MVC completely build by myself, which is quite a challenge, when being new to OOP.
So the main struggle of the whole project has, and is, my router. It's really important, so I want to have a... great?... router, that just works - but without compromising... |
The questions from hackerearth:
Geeko is in worry now because an exam is coming up and he has to know
what rank he can get on exams. So he goes back into the the school records
and finds the amazing pattern.
He finds that if a student is having a current rank \$n\$, then his rank on
the final exam will be the co... |
It's a string problem I have been making on Hackerrank. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out".
C programs are allowed 2 seconds on this site and somehow my program is taking a fraction beyond 2 seconds. How am I supposed to re... |
I'm new to MVP. In a presenter I have following code. Here what am I trying is to create a list of Model objects (in this case IAttendance objects) and to show them on a DataGridView in the View.
Every time an attendance is entered on the View, AddAttendanceObjectToGrid() method on the presenter will be called to add t... |
I've written some JavaScript code:
app.get('/offers/', function(req, res){
var funcGetOffers = utils.funcGetOffers;
var options = {top_sort: true};
funcGetOffers(function(offers){
res.render('offers', { offers:offers });
}, options);
});
app.get('/api/get_offers', function(req, res){
va... |
As part of an Academic project I wrote the following code, according to the algorithm (verbal). When I checked the rest of the article I notice that the efficiency should be \$O(n^2)\$ and I wrote \$O(n)\$.
I know that I didn't finish and that there is much to do. I'm putting my code and article here and wishing to g... |
To learn some Data.Map and Control.Monad.State, I have written the following code, which should count the occurrences of Char8 in a given file.
module Main where
import Control.Monad.State
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Map (Map)
impo... |
char * reverse_string(const char *s1)
{
int count = 0;
char *output;
char *o;
while(*s1 != '\0')
s1++;
s1--;
output = new char[strlen(s1)];
o = output;
while(*s1)
*output++ = *s1--;
if(*s1 == '\0')
cout<<"yes";
return o;
}
int main()
{
const char *s1 = "hello world";
char *result;
result = reverse_strin... |
During our internal code review process, my following code raised some eyebrows:
public class MySuperUtil {
public static List<Long> updateAndSubtract(List<Long> first, List<Long> second) {
List<Long> updated = updatePlaceholdersWithLargestIds(second, first);
Collection<?> difference = CollectionUti... |
I need to search through a string array to find every occurrence of "Parameters Table", and between each "Parameters Table" and the next, get another string from a specified index (that remains constant). I have been doing this like so:
public List<string> findlistOfNames(string[] arrayToLookForNames)
{
List<string... |
I've got this here screen manager system and while it works rather well, I do worry on how practical it all is.
The application creates a screen manager class then enters a message loop which calls the update, render and handle input methods of the screen manager.
The screen manager has a vector container of unique_ptr... |
Using the VS2012 code analyzer i see the following code has a pretty low Maintainability Index(40) but i cant seem to think of a better way to design it. Does anyone have suggestions on cleaning this up?
This code is part of a search screen for a web app I'm developing. They have several text fields they can use as we... |
I've created a rudimentary example of the issue I'm inquiring about: Object slicing. I followed a post on Stack Overflow which provided a similar template - and for all intents and purposes, this works. I was just wondering if this would get me into a trouble longer down the line? Is there anything here that jumps out ... |
Here is the function (along with its support functions):
def findAnglesBetweenTwoVectors(v1s, v2s):
dot_v1_v2 = np.einsum('ij,ij->i', v1s, v2s)
dot_v1_v1 = np.einsum('ij,ij->i', v1s, v1s)
dot_v2_v2 = np.einsum('ij,ij->i', v2s, v2s)
return np.arccos(dot_v1_v2/(np.sqrt(dot_v1_v1*dot_v2_v2)))
def calcula... |
This is a draft implementation of a function called COMBINE. It's not intended to be a complex formatting dialect, just a replacement for REJOIN that has a better name and more useful behavior. Its purpose is laid out pretty thoroughly in this blog entry:
http://blog.hostilefork.com/combine-alternative-rebol-red-rej... |
Per Learn You a Haskell, I implemented a simple command-line program, Todo, that accepts 1 of 3 arguments: view or add or delete.
Please review my code for Haskell idioms & overall quality.
-- view, add and delete tasks
-- borrows delete from previous LYAH exercise
import System.Environment
import System.Directory
impo... |
I want to know what needs to improve with my application. Maybe there is a better way instead of what I am using currently.
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="MyApp">
<head>
<meta http-equiv="x-ua-compatible" content="IE=9" charset="UTF-8"/>
<title>Angular JS</title>
<script src="lib... |
This is a script that I use to add a set of form fields on clicking an Add More button:
<script>
$(document).ready(function() {
var InputsWrapper = $("#InputsWrapper");
var AddButton = $("#AddMoreFileBox");
var x = InputsWrapper.length;
var FieldCount = 1;
... |
I'm working on a Talent Buddy challenge . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the most suited username based on the query. This whole functionality should run under 2 seconds for arrays which do not ex... |
I have to determine if an N sized list of coordinates defines a closed, exact rectangle.
I start with the question "How do I check if a list of coordinates is in the shape of a rectangle?"
The answer is:
First and last element in cordX and cordY have to be equal.
Difference between another key should be equal to 1.
... |
I completed some bit manipulation exercises out of a textbook recently and have grasped onto some of the core ideas behind manipulating bits firmly. My main concern with making this post is for optimizations to my current code. I get the hunch that there are some functions that I could approach better. Do you have any ... |
It is a simple semaphore in Java. Although it passes all their tests with flying colors, I'm still not sure it's correct.
For example, the last thing I wasn't sure about was mLock.lockInterruptibly(); vs mLock.lock(); in the method called aquire(). And I ended up using lockInterruptibly() because if the thread calling ... |
Am attempting to recreate a common feature, where a user can type several items in to a textarea, separated by commas and newlines and then submit them, i.e. for multiple record entry.
The data does not come from a CSV file and is manually entered.
// data looks like this in the textarea:
Widget 1, 4, 10
Widget 2, 1.... |
I am trying to make a nice set of items, which are equally spaced from each other.
On example below, I set buttons between empty textview. Every button and text view has height = 0dip and weight=1. And it looks pretty nice. However, is there a way to clean up the layout file?
<LinearLayout
android:layout_w... |
Please review:
/// Fetch a value from the `map` or create a new one from the `fun` (memoization).
/// Example: \code
/// flat_map<string, Frople> fcache;
/// Frople& frople = getOrElseUpdate (fcache, id, [&]() {return Frople (id);});
/// \endcode
template<typename M, typename K, typename F>
inline auto& getOrElseUp... |
We are using the Aspose PDF library to work with PDF files. Aspose requires the license to be set once per process. Accordingly, I have created the following common static method that sets the license. Any code that needs Aspose will call into this method.
public class ConfigurationService
{
private static bool isA... |
In my program, I have entities that I call "blobs", because they have a blobby shape. Blobs are polygons. If I have two blobs, then their information array would look like:
>>> blobs
np.array([ [ [x1, y1], [x2, y2], [x3, y3] ], [ [x1, y1], [x2, y2], [x3, y3] ] ])
Each entry along axis 0 represents one blob. Each entry... |
Is there any way of improving this code? (Here's a JSFiddle with an example and comments)
Example: A hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a greeter has received.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pre>
[]___
... |
I have a cookie where a number is stored.
When I want to add "1" to the stored number and then overwrite it, I use this php code:
$temp = $_COOKIE['mycookie']++;
$_COOKIE['mycookie']=$temp;
Is it the best way to do that?
|
I have been translating a solution from C# into VB.Net, because I know more VB and wanted to understand it better. I have a version up and running that replicates the C# performance with small input files; however with an input file over ~8MB the memory usage skyrockets and it will keep chugging until it consumes all m... |
I'm working on a little django quiz taking app. Currently I'm making it's models. So far I've got Quiz, Question, Answer, and Response designed as follows:
from django.db import models
from npage.mixins import TranslatedModelMixin
from django.contrib.auth.models import User
# Create your models here.
class Quiz(model... |
I'm trying to figure out a way to do the exercise 3.20 in the C++ primer book
I have to create a program that reads input into a vector then use that data to create 2 outputs:
one is the sum of each adjacent number
one is the sum of the first and last number moving inwards (as in the 2nd and 2nd last, 3rd and 3rd last... |
I didn't write this but I noticed it in our codebase at work.
var data = object && object.attribute && object.attribute.data ? object.attribute.data : {};
I get that the programmer is trying to check that the variable object.attribute.datais defined before using it, but is seems like so much repeated code. What's the ... |
I am implementing a flood fill algorithm using Python and NumPy. I have written the following fill function which works fine:
def fill(self, data, xsize, ysize, x_start, y_start):
stack = [(x_start, y_start)]
while stack:
x, y, stack = stack[0][0], stack[0][1], stack[1:]
if data[x, y] == 1:
... |
I've written a simple class which should:
get 10 top cars and 10 top bicycles from database
write them into 2 different arrays
It works, but I'm trying to find a simpler or clearer solution.
class TopVehicles extends Connection {
private $sql1 = 'SELECT model, price FROM vehicles WHERE type = \'car\' ORDER BY pri... |
The code that I am sharing here for you to review today, is a segment of a JavaScript library that I am going to write as time goes by for fun. It is only the two functions in the following code:
/*jslint browser: true, indent: 8 */
/*global console */
/*
Sorts matrix like from something like this:
... |
I had a ugly problem and wrote an ugly query.
Query creates a cache that is used to get person id when I have {full_name, id_code?, birth_date?}. By question mark I mean that it is perfectly valid for person not to have {id_code, birth_date} entered.
var searchvalue1 = String.Format("{0} {1}", ma.code, ma.name);
var s... |
I've taken a crack at implementing Simple Diff in Rebol (versions 2 and 3). Simple Diff works by finding the longest common sequence in two series, then recursively applies itself either side of this sequence until there is nothing further in common. It returns a block containing additions (+), omissions (-) and match... |
The test
PublicQuestion_ComplexTest
is taking around 1600ms (1.6 seconds) to run, but used to take 92ms. I have a feeling this is because of recent code changes that include .Count() in many places within these 2 functions:
RemoveSmallerLengthNumberListsThatContainSameNumberCombinationAsLargerLengthCombinations
and
... |
Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome.
/*ask the user for 10 numbers
store them in an array
print them "your numbers are:"
print them "Average"
print them "Max"... |
Given a suffix array for a word, check if a pattern (consecutive chars) exists.
Example:
A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false for "ameyp".
This algoritm is case sensitive.
I'm looking for code-review, best practices and optimizations.
public final class Suf... |
I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, but can often make no sense when I need to switch on the enum type but I don't want the enum itself to know anything ab... |
I have created a class that will manage my session. I am hoping to acomplish a class that will secure my site from all known attacks (ie. fixation, precedent, and capture.)
The idea is to
Change the session storage engine from files on the servers to a database.
Create a random session id and not relay on PHP to gener... |
I have a project which should be thought of split into two layers: an IO layer which consists of sensors (input) and effectors (output), and a core layer which contains logic for determining which actions are desired from particular observations. The IO layer is dependent on the core layer, and the core layer is ignora... |
I am testing a quicksort implementation. Arrays of random size with random data are passed to quicksort and the return time is averaged out. The user is prompted to enter values for
minimum length of array
maximum length of array
maximum value in array
minimum value in array
if the user wishes to see the sorted and un... |
I am trying to solve as many issues as possible with my Database Class and bind statements as far as possible without actually doing it in the front-end. The goal is to do all of the heaving lifting for PHP Developers and Web Designers as possible to make their job even more easier than other PHP frameworks.
The Databa... |
I want to see if this is as streamlined as possible. Most of the logic is accomplished through methods in the model. The controller does one of four things:
redirects new users to registration
sends locked users to reset password
logs the user in and redirects them to where they should go
fails the login and allows... |
I have the following function which converts an integer (such as 103) to its string representation ("one hundred three"):
NumberToString = (function ()
local floor, abs, num, tens, bases = math.floor, math.abs, {
[0] = '',
'one',
'two',
'three',
'four',
'five',
... |
I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list.
This is what I came up with:
public static class LinqHelpers
{
public static TListType IndexOrDefault<TListType>(this List<TListType> lis... |
I have the below mentioned function written in plpgsql which is working fine. I want someone to review it and let me know how can I improve its performance.
This function takes data from staging table and inserts into target tables. Before it inserts, it checks for the existing records, and if any records exist, it doe... |
I posted this code in an answer earlier today, but thought it was worth seeing if somebody could suggest further improvements:
#include <numeric>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
template <class InIt, class OutIt>
OutIt adjacent_sum(InIt begin, InIt end, OutIt result) {
... |
Please evaluate this function. It takes a list [a] and an Int, i.e. the index, and returns a new list with the selected item at the top of the list. Note that it returns Maybe [a] to account for bad indexes.
pushToTop :: [a] -> Int -> Maybe [a]
pushToTop [] _ = Just []
pushToTop xs i
| i >= length xs || i < 0 = No... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.