instruction stringlengths 71 39k |
|---|
I wanted a good way to move objects back and forth between Lua and C++, and I didn't want to use anything like LuaBind or the other available libraries I could find, so I instead wrote this. It's designed to be similar to the normal Lua API, which has functions like lua_tostring or lua_tonumber, but I wanted to make it... |
How do I improve this code for reading an epub file? The code is as follow:
package org.example.mymenu;
import java.awt.print.Book;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
//import java.util.List;
//import org.example.mymenu.Book;
/... |
The following code is mainly concerned with the conversion from byte/bit stream to numericals such as int, unsigned int, short int, unsigned short int, float, and etc. These functions are heavily used in my image data decoding program. I feel an insufferably slow when dealing with bigger image. Would please help me im... |
I'm trying to emulate the default behavior of an ItemsControl in a ContentControl--Bind Content to an object property and use the correct DataTemplate based on that object's type.
I've tried to Reflector dotPeek at the implementation of the ItemsControl to see how it works, but I've reached a dead end. Consequently, I... |
There is Three Validation Group A,B and No Group.
How to get validation result of only the specific validation group.
If Group A and No Group is not valid but all of group B is valid, i would like to get result as valid.
I have read the article validation in depth but don't find the straightforward solution.
http://msd... |
<div class="minipassbox" style="margin-top: 5px;">
<?php
for($i = 1; $i <= 3; $i++) {
$marginRight = ($i < 3 ? "margin-right:4px" : "");
echo "<div style='width:56px;float:left;{$marginRight}'>";
echo "<label for='param_... |
Following is the code which finds the social network of a friend (i.e. friends of friends and so on). Friends definition is, ff W1 is friend of W2, then there should be Levenshtein distance equal to 1. It is working fine with a smaller dictionary, but is taking a lot of time with a bigger dictionary.
Need some code rev... |
I'm making a pong game with SFML and in the process made a function that takes a Time, Speed, Angle of movement, buffer for the movement on the X axis, and buffer for the movement on the Y axis.
I then implemented this function into my custom mySprite class, more specifically into its update() function which updates i... |
So I have started a PHP framework called ExCx and I haven't really had much experience in the professional development business.
I was just wondering if my structure/layout/methods are up to scratch?
EDIT: Forget the URL, added that.
Normally I remember to omit the closing php tag...
In tandem with this I am building a... |
I've been playing around with Python off and on for about the past year and recently came up with the following 68 (was 62) lines. I think I'll try making a calculator out of it. I'd really like to know what readers here think of its attributes such as coding style, readability, and feasible purposefulness.
# notes: se... |
i have this code that is suppose to work with at starting the minimum number of threads, say 5. when it starts the first five threads, it automatically replaces any thread that is finished making sure that there is always five threads working.
the problem here is that, am finding it difficult to manage where am suppos... |
I wrote program which simulates the work of the restaurant. It works but I would like to change it because I think there is better solution.Thanks for your suggestions.
Client.java
public class Client implements Runnable {
private Restaurant r;
public void makeOrder() throws InterruptedException {
sync... |
I have the following class that processes a Bitmap to place a fisheye distortion on it. I've run my app through TraceView and found that virtually all the processing time is spent looping through the bitmap. One developer has suggested not using float as this will slow things down where graphics are concerned. Also, us... |
I am fairly new to PHP, and would love to have my code reviewed to see what I am doing wrong and ways to improve it. The code works fine, I just feel like there's an easier way to do this.
This is the PHP code at the top of my page - and then the HTML is below it, but I will only paste the PHP code. What the page is,... |
Over the last months I have been writing a jQuery plugin called Better Autocomplete (Code on Github). It originated from another project, a Drupal module called Linkit, but I decided it should be a standalone plugin. I have spent a lot of time refactoring the code, mainly to make it more generic and flexible for multip... |
I have a file containing one long line:
"name surname" <name.surname@example.com>, 'name surname' <name.surname@example.com>, name surname <name.surname@example.com>, "'name surname'" <name.surname@example.com>, surname, <name.surname@example.com>, name <name.surname@example.com>
Note that that's 6 different forms.
I ... |
Here is my program which creates a linked list and reverses it:
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *list=NULL;
struct node *root=NULL;
static int count=0;
struct node *create_node(int);//function to create node
void travel_list(void);
void create_list(... |
I'm using this pattern for the first time and wanted to check if this is the correct implementation.
class.validator.strategy.php
abstract class ValidatorStrategy
{
abstract public function check( $name, $val );
}
class.text.validator.php
class TextValidator extends ValidatorStrategy
{
public function check(... |
I would like your thoughts on my database structure. I am kind of a rookie but I am trying. All of your suggestions, alternatives, ideas, additions are welcome. Thank you.
CREATE TABLE `buy` (
`PurchaseID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`PurchaseTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDAT... |
I'm currently reviewing some standard pieces of code I use a lot in projects.
Currently I'm using the following functions for password hashing.
function generate_salt($length = 20){
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
'0123456789``-=~!@#$%^&*()_+,./<>?;:[]{}\|';
$str = '';... |
I tried a Yahtzee kata in Python the other day. I'm not particularly experienced in Python (C# is my main language) so I'd be interested in any feedback as to how I could have done things better. In particular, I wonder whether my Count and HighestRepeated methods could be a little more elegant.
import unittest
#helpe... |
I've knocked together a few lines of python to read in stats for a service (haproxy), and store them in an array (to do some analysis on later). It basically takes a multiline output, and splits it into multiple subarrays. This is how I've done it - can anyone offer improvements for me?
def build_array():
servi... |
I'm creating a function that converts a title, to a URL slug. I'm not all to familiar with regular expressions, but I've done my best. Can you see any problems or improvements with the following function below?
The only thing allowed in the slug is letters, numbers and - charchaters.
function slugify($input) {
// C... |
So I'm developing a webpage using MVC which will be mainly JavaScript driven.
Instead of using global variables, and global functions, I would like to do it right this time. I don't want to use something to complex, because the team and I are new to large JavaScript applications. I tried implementing the Module pattern... |
new MethodExecuter()
.ForAllInvocationsCheckCondition(!Context.WannaShutDown)
.When(shouldRun).ThenInvoke(x => x.Methods(new Action[] { B.Process, A.Process }))
.When(shouldRun).ThenInvoke(x => x.Method(B.Process).Repeat(100))
.Invoke(x => x.Method(C.Process));
I deliberately do not say any... |
I'm testing some methods for checking if an area of the screen changes, can you see any problems with how I'm doing this, and is there a better way for me to do this?
the _memoryImage2 will not change in the final app, it will be a read only array that I will check the memoryImage against.
namespace ScreenShot_BoundsTe... |
I caught a whiff of a code-smell emanating from one of my tests, in a scenario akin to the following:
[TestFixture]
public void CarPresenterTests{
[Test]
public void Throws_If_Cars_Wheels_Collection_Is_Null(){
IEnumerable<Wheels> wheels = null;
var car = new Car(wheels);
Assert.That(... |
I have created a "Wizard" using JavaScript and based on people's answers you get taken to certain results divs. It works the way I want, but this code is VERY repetitive. Is there a way to clean up this JavaScript code?
Demo can be seen here.
$(".hidden").hide();
$(function() {
$("#start_button").click(function(){
... |
I am trying to take advantage of the reflection built into RouteValueDictionary to add values to the query string of a URL. This is what I came up with. It seems to work, but I thought I would post it to see if anyone has any suggestions. It also uses the super-secret HttpValueCollection returned by ParseQueryString(),... |
I have the following code block which I'd like to refactor into a method, I just don't see a good way to get the following code into a method which doesn't have multiple responsibilities. Here is the code block:
int maxResults = pageable.getMaxResults(userPrefs);
int firstResult;
if (pageData.isLastPage()) {
int ... |
I started working on a jQuery port for this Form Dependency Manager script. It works fine, and I added a few extra options too.
The problem is speed. If you create dependencies between 20+ form elements on a page you get the PC to run really slow. Firefox is throwing that "script is too slow" message. This is probably ... |
What would your preferred loop type be for a case like this:
StringBuilder sb = new StringBuilder();
for(Integer id : idList) {
sb.append("?,");
}
In short: In dependency to the size of a List i want to add stuff to a String. The above example produces a "unused variable" warning.
I'm thinking of these alternative... |
I have a custom PropertiesByValueComparer and am fairly happy how it behaves for simple classes. I haven't included comparing by fields yet. Is there anything that is blatantly fail about this, or do you have other recommendations?
public class PropertiesByValueComparer<T> : IEqualityComparer<T> where T : class
{
p... |
using System;
using System.Web.UI.WebControls;
namespace RideShare.Web
{
public partial class UserOrganization : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
// Fi... |
This method runs in just under two minutes. I would like to optimize it to run in less than 15 seconds. Using a LAMDA filter on my list before iterating it's elements and removing one conditional statement in the method shaved off 30 seconds. Any ideas to improve performance?
c# .net 4.0
[SecurityCritical]
[S... |
Please critique my login and signup validation php files..
login.php;
<?php
session_start();
require("connect.php");
$email = $_POST['emaillogin'];
$password = $_POST['passwordlogin'];
$email = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);
if(empty($email))
{
die('{... |
I have a big string resource (basically the "about" text of the application) which contains styles (such as <b>, <a> etc.). The string resource is written on multiple lines, like this:
<string name="about_text"><big><b>About</b></big>\n
Lorem ipsum dolor sit amet and all that stuff...\n
\n
More stuff.</string>
Now, ju... |
I've written some Javascript code with jQuery to display a dialog box on a web page that "floats" in the corder of the page.
(1) It has the following features: the dialog follows as the user scrolls the page.
(2) If the user holds down the [Ctrl] key, the dialog is hidden so that it doesn't obscure content.
I know that... |
I've just released a jQuery plugin that conditionally displays elements based on form values. I would appreciate any suggestions on how to improve both the code and its usefulness.
Here's the demo page
Would this be useful to you?
What other functionality should I include?
Any refactoring or structure changes that I s... |
Okay, I'll try and keep this as short as I can. First, I need to keep various options available to the user:
if ($c_verb eq 'on')
{
if ($c_enabling) ##if need eq, add || '' at declaration.
{$category_id = 'xcomp';}
elsif ($c_subject)
{$category_id = 'subj';}
elsif ($c_object)
{$c... |
This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation?
PS. This implementation is fully lambda expression based. If I can make fixpoint::fix a real member function it will be simpler than this.
//As decltype(variable)::member_name is invalid currently,
//th... |
I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a custom allocator type. The following code outlines what I mean:
template<typename int_type, class alloc = void>
class uses... |
So I have this array:
$arr = ('a' => 343, 'b' => 34, 'c' => 65, 'd' => 465);
which could also be
$arr = ('a' => 343, 'b' => 34, 'c' => 65);
Can the following code be improved into one line?
if(isset($arr['d'])) $something = $arr['d'];
unset($arr['d']);
|
I want to be able to do /contacts/Matt%20Phillips and /contacts/1 and have both of them return a contact. The way I did that was to try and parse an int from the captured parameter and call the Id method instead of the byName method like so:
[WebGet(UriTemplate="{param}"]
public Contact SingleParam(string param... |
Is this the best way to get access to the parent scope when dealing with complex objects literals?
I find this a bit ugly, and obviously the best solution would never be involving calling it by name directly, but by saving the state of the previous scope. I tried it with bind() but didn't get it to work properly.
var o... |
This is my first attempt to write a simple C++ program:
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
class Book {
public:
char title[30];
Book(char *tit) {
strcpy(title,tit);
};
char *gettitle() {
return title;
}
};
int main() {
Book mi... |
I need to write some JavaScript code that will take a JSON string, parse it, and return the names of the most-deeply nested properties. For example, for this input:
var json =
"{\
foo: {\
bar: 'something',\
baz: {\
jack: 'other',\
},\
bob: {\
bill: 'hello',\
bilbo: 11,\
baggins: {\
fi... |
After realizing that I was spending a lot of time getting the latest version of Chromium, I figured I would throw together a quick script. Over time, I wanted to make the script more efficient, cleaner, and pythonic. Here is what I came up with:
from zipfile import ZipFile
from os import rename, remove, path
from shuti... |
It's somewhat odd that Java's collection framework has no iterator for recursive data structures. Since I needed something like this, I wrote my own. First off, I need recursive elements:
public interface RecursiveElement<T>
{
public Iterator<T> getChildrenIterator();
}
And then an Iterator:
public class Recursiv... |
I often argue with the voices about the correctness of having assignments within an if statement (or equivalent), meaning having this:
if($thing = someFunction()){
//do stuff
}
Instead of this:
$thing = someFunction();
if($thing){
//Do stuff
}
A part of me says its a bad practice because:
If read quickly (by s... |
From SICP:
Exercise 3.64. Write a procedure
stream-limit that takes as arguments a
stream and a number (the tolerance).
It should examine the stream until it
finds two successive elements that
differ in absolute value by less than
the tolerance, and return the second
of the two elements. Using this, we
... |
I have a simple implementation for a LRU cache using LinkedHashMap.
I want it to be as generic as possible.
This is not for production use, just practice, so I don't care
if its thoroughly robust as far as it
is correct. However, I will welcome
any comments, especially the ones
which might make this better with
si... |
I have developed a test app that works by getting webpages source and processing it. I have up to 100k URLs in queue and want to use a maximum of 25 threads. Please help me check if the code is good or point out any faults you might find.
Public Class frmMain
Public Delegate Sub AddItemDelegate(ByVal Item As String... |
var AgeConvertor = {
Age: function (formattedDate) {
var now = new Date();
var yearNow = now.getFullYear();
var monthNow = now.getMonth() + 1;
var dayNow = now.getDate();
// Calculating in days
var ONE_DAY = 1000 * 60 * 60 * 24;
var ONE_MONTH = 1000 * 60 * 60 * 24 * 30;
... |
I have a bunch of simple interfaces like this one (pretty enough formed, but not guarantee)
package com.example.sources;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.ImageResource.ImageOptions;
import com.google.gwt.re... |
I have an experimental script that makes an animation of a ul list element background-position, when the list element is hovered. Is there another way to manage this task or just optimize this code?
I want to make a menu that has elements with an animated background and have an idea about rotoscope style design or som... |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun read-sim-file (filename)
"Reads file.
File is presumed to be the output from a simulation.
Returns lines from the simulation as a list of strings
We throw an error if TRAP ET is detected.
Lines with DBG_INT are ignored."
(let ((file-text-list (split "\\n"
... |
Can someone please review this simple code for printing all paths in a matrix from bottom left to top right? If an element is 1, it is a "wall" and you cannot take it.
Possible steps: up and right
// Prints possible paths from bottom left to top right
public static void findPath(int n, int i , int j, int[][] mat... |
Can someone please review this code for me? I have not implemented all the methods for simplicity.
/**
* Implements a blocking bounded queue from a given non-blocking unbounded queue implementation
*/
abstract class DerivedQueue<E> implements Queue<E>
{
DerivedQueue(Queue<E> queue, int size)
{
if(queu... |
I've written the following SQL to count the number of times the name 'Cthulhu' turns up for each tag on Stack Overflow (original here):
select t.TagName, count (*) 'Tainted'
from Posts p, Tags t, PostTags pt
where p.Body like '%cthulhu%'
and (pt.PostId = p.Id and t.Id = pt.TagId)
group by t.TagName
order by Tainted DES... |
I have a list of checkboxes styled using JQuery UI as buttons. Each have a data-price attributem containing a price in this format: data-price="40.00", data-price="25.00" etc.
When the user "checks" a box, I am adding it's data-price to the totalPrice var. Every time another box is clicked, it's own data-price is added... |
I wrote the following code to insert records into a database. The user selects the rows from the RadGrid and the insert command is executed when that user clicks the button. I've been spending a lot of time trying to make this work (nothing currently happens when I click the button). However, I just realized my appr... |
I've created this (very) contrived example that demonstrates how we currently organize page specific JS in our app. Basically each page has a matching JS file that uses the module pattern to enclose page specific behaviors. Each module has an init() function that takes control IDs and wires up events, etc.
This has wor... |
I've written the following C# code to insert rows (that a user enters from a web application) into a SQL database. How does this code look? Is there a better, more efficient way to accomplish the task?
public void UpdateDeviceStatus(string[] deviceId, byte[] status, string userId, string[] remarks, DateTime dateTurni... |
I'm trying to implement the Strategy Pattern into my current code base. I would like to know if i'm going in the right direction on this?
IOracleDB.cs:
/// <summary>
/// Strategy
/// </summary>
interface IOracleDB
{
DataSet DatabaseQuery(string query, OracleConnection oracleConnection);
DataSet DatabaseQuery(st... |
I have started learning HTML. Here is one of the very basic HTML pages I have written. I would appreciate advice about how to write code especially regarding indentation.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3... |
How would I make this code look less ugly?
// we are looping over an array of images
// width is a parameter passed to the current function
//
// the resulting string looks like this: "30px 0"
// (it's a tool that returns coordinates for a CSS sprite)
// when iterating over the first item, we don't need
// to add "-"... |
Follow-up to: Waiting for a lock to release with Thread.Sleep()?
I've found the time I tried to rewrite my WaitForLock-Method to utilize the Quartz.NET Scheduler which I've been using for some months now for other stuff. It got a little bit more complicated but at least it now misses the dreaded Thread.Sleep() comple... |
I wrote this program to do a simple Caesar shift by a user inputted key, and then deshift.
I'm really enjoying it, but I've run out of ideas on improvements! Can you think of anything?
def decrypt():
a=raw_input("Give me the word to decrypt:")
number=input("What was it shifted by?")
b=list(a)
str(b)
... |
I am trying to learn by doing. Here is the first problem that I have solved. I have actually not done it perfectly. The table header should cover both the text and the image but it is only above text. If you can help me out with the design I will be thankful.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E... |
It's been pointed out (see the first comment) that my makefile rebuilds all source files regardless of changes made.
# Variables #
TARGETS := libAurora.a libAurora.so
# The names of targets that can be built.
# This is used in the list of valid targets when no target is specified, and when building all targets... |
Earlier this year, before I learnt about Code Review Stack Exchange, I gave this answer in response to a question about how to combine ASP.NET, jQuery, and JSON:
I keep thinking that there must be a better way to handle the JSON than just using escaped string literals, but I'd like to know for sure.
urlToHandler = 'ha... |
Here is a problem I solved. Please review this.
<!DOCTYPE HTML>
<html>
<head>
<title>BLA| Welcome </title>
</head>
<body>
<h1 align="center">Meet Jack</h1>
<img src="http://www.htmliseasy.com/exercises/jack.gif" alt="Meet Jack"> <br/>
<p> He is Jack.He is an o... |
How can I improve upon this integer class that I wrote? I am/will be using this for some calculation intensive crypto algorithms, mainly POLY1305AES. I might even write RSA using this. I know that there are more efficient algorithms for at least the algebraic operators, but I will rewrite those when I learn them.
Right... |
I have an OpenClose class which just represents the hours of operation of a business by the opening and closing time. It takes the opening and closing times as arguments to its constructor, and each is a datetime object.
The data is coming from an external source in a string, formatted like "HH:MM (AM|PM)-HH:MM (AM|PM)... |
I'm building a web application and is trying to make my code reusable. I've decided to create components that can be used outside this project.
Now I'm trying to create a simple DI container, one class, and I would like some help checking it out. I'm thinking to do something like this:
class Container
{
protected s... |
For every word there are 2^n different ways of writing the word if you take into account upper/lower case letters. Eg for "word" we can write;
word
Word
wOrd
WOrd
woRd
WoRd
etc
I've written this code to calculate all the combinations. Is there any way I can improve the performance? Profiling tells me that this method... |
I have searched for method to find and replace strings sequence in binary files without any luck. The main requirement was that method should not load all file in memory but rather use chunks. I am new in c# and code may look not "polished" but it works fine. Maybe someone will have ideas how this code could be improve... |
I wonder if there is any way to write the followig in a few lines instead of using all cases. Both CategoryType and AnimalSpecies are Enums.
private AnimalSpecies GetAnimalSpeciesBasedOnCategoryType(CategoryType categoryType)
{
switch (categoryType)
{
case CategoryType.Reptile :
return Anima... |
I'm using an ObservableCollection in a WPF app. The source of the data doesn't provide changes. It provides snapshots instead. The method I wrote to update the ObservableCollection works but it seems inelegant. Is there a better way to do this?
public static void UpdateMarketOrderList(
O... |
This code kinda hurts my feelings -- everything else in my code is done in neat one-liners, exploiting algorithms and, sometimes boost::bind, except for this piece. To say nothing about awkward if(b!=a).
Is there a better way to do the task?
#include <iostream>
#include <list>
using namespace std;
int main()
{
int... |
I have the following code, but it's too slow. How can I make it faster?
<?php
class Ngram {
const SAMPLE_DIRECTORY = "samples/";
const GENERATED_DIRECTORY = "languages/";
const SOURCE_EXTENSION = ".txt";
const GENERATED_EXTENSION = ".lng";
const N_GRAM_MIN_LENGTH = "1";
const N_GRAM_MAX_LENGTH = "6";
public function ... |
I am always tired of the very verbose syntax in Java for creating small maps. Arrays.asList(T... a) is very convenient, and therefore I want something similar for a map.
public class MapUtils {
public static <K, V> MapBuilder<K, V> asMap(K key, V value) {
return new MapBuilder<K, V>().entry(key, value);
... |
We have some required services down temporarily when our server start. So we need some reconnection logic for them until they are finally up.
There is a requirement to have also syncronious way for that.
Here is my generic implementation for that via a single background thread:
public class RunUntilSuccess {
private s... |
I've been using this variation of the Repository pattern for over a year now:
public interface IReadOnlyRepository<T, in TId>
where T : AbstractEntity<TId>
{
T Get( TId id );
IEnumerable<T> GetAll();
}
/// <summary>
/// Defines a generic repository interface for
/// classes solely in char... |
For my project, I needed a way to instantiate different object types during runtime using "string names", for this I designed a generic factory that is created for each object hierarchy type (currently there are two different hierarchies that need the factory).
We want the factory to be simple to use and simple to regi... |
I've only been writing php for a couple of months, and I've never really had anyone to look at any code I have written. I've written this class, that returns an email address from a database, based on a set schedule. I feel like a lot of the time, I'm doing things the long way, or just the wrong way. So I would really... |
I'm working on a project for an image recognition software. The software takes an image and returns a set of labels (a label is just a string of text) which describe the contents of that image. Each returned label is also associated with a confidence value which quantifies how certain the algorithm of its label assignm... |
Assuming I have 5 arrays, all just indexed arrays, and I would like to combine them, this is the best way I can figure, has anyone found a more efficient solution?
function mymap_arrays() {
$args = func_get_args();
$key = array_shift($args);
return array_combine($key, $args);
}
$keys = array('u1', 'u2'... |
The source code, or rather the concept I'd like to get reviewed is what now allows me to do the following during reflection:
object validator; // An object known to implement IValidation<T>
object toValidate; // The object which can be validated by using the validator.
// Assume validator is IValidation<string> and t... |
I have a live chat database and I am trying to get an idea of how many concurrent chats staff are taking. I'm not sure of the best way to report it so I have decided to get a list of chats for a given period then for each one display a count of chats that overlapped that one in some way.
I am querying 2 tables across a... |
I have built a website using HTML and CSS. Actually I wanted to learn by implementing real world examples. I have built a site like Google. The search box does not work(I actually did not wanted to go further in the form action part and also did not wanted to use any search engine) and I have not copied anything from t... |
I just watched a Khan Academy video on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:
unsorted_list=[45,99,1,-22,7,3,294,10,36]
def insertion_sort(unsorted):
for i in range(1,len(unsorted)):
for j in range(i):
if u... |
I have a little project going on and so far I'm not really having any problems.
But since I haven't internalized all of Python's core features yet, I'm pretty sure my code offers pretty many subjects to optimize.
Please point out anything that could be done better. For example, I'm feeling uncomfortable with the method... |
I have created a data structure to handle some audio data I am generating (simple sine wave right now). It had some errors in it due to some misunderstanding of my ancient C knowledge that has been fixed by my cousin. I am wondering if there may yet still be more issues.
I have considered turning this into a C++ class,... |
I've been focusing on my PHP skills lately but have been shifting to JavaScript. I'm familiar with the bare-bone basics of jQuery. I'm not as familiar with JavaScript as I'd like to be. I'm a solo-developer so I'd just like somebody to take a look at this and point out any mistakes or things I could be doing better.... |
So this isn't EXACTLY my code but it is close enough to show what I have. Also the naming is only for this site so if its not really clear forgive me. Its much clearer in the actual code.
class Member(models.Model):
team = models.IntegerField(default=0)
match = models.ForeignKey(Match, null=True, blank=True)
... |
In a web game there is a ranking of the top points games played of the month:
// QUERY
SELECT * FROM game
WHERE date >= date_sub(CURDATE(),INTERVAL 1 MONTH)
ORDER BY points DESC limit 0, 20
But, in that case one player can be the top 1,2,3... so I have changed the query to add a distinct, and then only appears one gam... |
As you can see, the following is pretty ugly and seems to be unnecessarily long.
Is there a shorter/neater way to do this?
function addNewRow(body, id){
var myRow = document.createElement("tr");
myRow.id = id+'';
var c1 = document.createElement("td");
var c2 = document.createElement("td");
var c3 =... |
I'm creating a JavaScript/WebGL based game and would like you all to take a look at the current entity component system which I created for it. I've used it once before on another project, and while I was very happy with the results, there were parts of it I did not feel 100% good about.
In particular, sometimes a com... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.