I'm working on a small final fantasy type game. I have this for a tile map. I was just wondering if this is a good way to do this or if anyone has any suggestions, I would love to read them.
import com.stardust.main.gfx.Assets;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
impo...
In playing around with this, I noticed a few things I didn't particularly like:
This picture represents the first problem. Setting the background color fills in the entire rectangle, but should probably only fill in the circle. We can fix this as such:
Add a private variable to hold the v...
Create a new Objective-C file in your project, and when Xcode asks, say yes to creating the bridging header.
In this new Objective-C file, add the following the the .h file:
NSString *compileDate();
NSString *compileTime();
And in the .m implement these functions:
NSString *compileDate() {
...
Step 1 is fixing your indentation so that someone besides the compiler can make sense of your code. — nhgrif32 secs ago
I tried to tackle #17 problem on project euler:
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters w...
This is an implementation of the Berserk vulnerability (for research purposes) that should work per python documentation, but does not. Could someone help me fix it?
#!/usr/bin/python
import hashlib
import math
N = "c5ddc7decb1beede4ebb96742e4279eb120b9c8b44472c0d0bb39da95a10cf72b630dbea181...
I finally converted my horrific HTML regex parsing:
if (
$info =~ /
Platform\sType<\/td>\n\s+<td><b>(.*?)<\/b>(.*?)<\/td>.*
Codeset<\/td>\n\s+<td><b><i>(.*?)<\/i>.*
Status<\/td>\n\s+<td>\n\s+<div(?:.*?)">(.*?)<\/div><br>.*
Instance\sID<\/td>\n\s+<td>(.*?)<\/td>.*
Instance...
In my data structures and algorithms class, we were introduced to the splay tree, a BST with the additional property that recently accessed elements are quick to access (because they stay at the top of the tree until a different element is accessed).
I know that std::map uses a BST; I heard it's...
My question might bring negative votes because i have not attached any code here. but i have no option other than to ask this. I recently developed a PHP Framework. Their is still few things left out of which below 2 are the main ones.
Dependency Injection
Namespacing
The Framework code can b...
I have a "cumulative" lookup array for a custom collection view layout.
The idea is that I have an array of rectangles, each with an index. The index is not unique. I need to create a lookup table, such that given a cell index, it returns the accumulated height of all rects lower than that inde...
I admire the average response time on CR... I posted on other SE sites and this has been unanswered and unvoted for 2 days, and this unanswered since Oct 31... Kudos, Code Reviewers!!
To make a point in another topic, here's one take of the 'simplest possible sieve' that can sieve up to 2^64; the idea being to make things so brutally simple that we can trust the thing to be right and can use it to verify other, more complicated implementations.
The code here works perfectly f...
A while back I was asked the following question in a phone interview, and to be honest it stumped me. After many long nights of rolling the problem around in my head I think I came up with a decent solution
The Question:
Given a list of intervals like:
[(5, 7), (11, 116), (3, 6), (10, 1...
I highly recommend a meta on this proposal. While I'm interested in the concept of this as a community-challenge of sorts, it's broken code. You know this code isn't ready for review. — RubberDuck55 secs ago
I don't know about that ^. Like, at all... I VTC'd until it can be discussed.
I don't think it belongs here. Maybe there's room on PGG for a new spot-the-bug, but this doesn't belong here.
I'm pushing myself to learn pure JavaScript, so this morning I wrote a equal heights script in jQuery and then converted it to JavaScript - It works but I'm using two for loops. Is there a better more efficient way to write this code, maybe finding away to remove the second for loop?
I've create...
@ RubberDuck and rofl: most posters are using Code Review as a 'debugger service' for crappy, broken code but my post is not doing that. Also, there's no danger that the two bugs that are subject of the 'STB' will confuse naive readers looking for code to copy, since the fixes are bound to get posted one way or another. Also, a lot of sieve code that gets posted here and on StackOverflow is of exceedingly poor quality.
Hey, I'm fine.
Needed some time to figure out how this works... Haven't chatted in a decade or so.
I'm just concerned a bit. I understand what you're doing and it's interesting, but our rule of thumb is that the code must work the to best of the OP's knowledge.
They just post them as 'spot the bug, please', and don't put a big sign on it saying "+50 to spot the bug", and don't put the question forward as a game.
No, I mean here on CR too.
We close about 60% of all questions as 'spot the bug'.
Yep, put people seeing an STB without a bounty would simply not be interested.
The bounty draws people's eyes and ensures quality. Make it a minimum +100, whatever.
Thanks, people. I'll think about making a proposal on Meta, with emphasis on having to stake bounty. For now I've got to go offline, shopping and stuff. Cheerio!
You seem to be missing the point here though. What you are doing is something like: going to a water-color painting convention and saying... I have this piece of marble I would like to carve in to a statue-of-david. Here's $1000000 for you to put down all your water-colors, and pick up a chisel.
Wouldn't people enjoy reviewing some non-crappy code for a change, plus knowing that the solution will be revealed shortly? Like Gotcha of the Week, elsewhere... (was it Herb Sutter? forgot)
I have a private method in a class. I would like to extract it to a base class, but still only allow it to be called privately. What's the correct scope to do that?
I am trying to delete a character from existing string to create a palindrome.
If the string formed after deletion is not a palindrome, then print NO
If the existing string is already a palindrome , then print YES
This is what i have written, and it works for certain test cases
can someone provid...
Let's say that I have the following code:
String word1 = "bar";
String word2 = "foo";
String story = "Once upon a time, there was a foo and a bar."
story = story.replace("foo", word1);
story = story.replace("bar", word2);
After this code runs, the value of story will be "Once upon a time, ther...
this is my first question here, I was not sure if it's more appropriate here or in the stackoverflow area.
My code works fine, I would like to know if I chose the best strategy to implement my code, or if It can written better (more fast, more clear, best use of design pattern, etc).
In my andr...
I have got an array with object where each object contains information about school and business area like this:
[
{School : "School name 1", Business Area: {lookupValue: "Business area 1"}},
{School : "School name 2", Business Area: {lookupValue: "Business area 2"}},
{School : "School ...
I have a simple master-detail storyboard like so:
Which results in this table view (selecting cells leads to detail view):
However when I change the size classes option at the bottom to play around with iPhone-specific stuff, the table view disappears from view in the storyboard and doesn't...
I am working on multithreading project and I am using ZeroMQ socket to send the data as a byte array. Below is my example which works fine but opting for code review to see whether it can be improved by adding a wrapper class for using ZeroMQ socket as some sort of socket manager?
public class ...
I have a very huge GSON coming from a URL which I am trying to serialize it on the fly as shown below with the code and it works ok.
private static final Type listOfMetricsType = new TypeToken<List<HostClientMetrics>>() {
private static List<HostClientMetrics> loadMetrics(String url) {
List<...
I have a lot of similar fields that shout by created in similar way.
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
is_friend = serializers.SerializerMethodField('get_is_friend')
# ...
def get_is_friend(self, obj):
user = self.cont...
I mean: BUT WHY?
That's what we're left asking. Matt's answer is correct in that renaming the method will fix the problem, but we're still left asking why.
The answer is because Swift actually remaps convenience methods to constructors.
So while we'd have to call the method like this in O...
This coding style is confusing.
Let's unravel the line of code in question:
self.currentDog >>> getWalks >>> getWalkAtIndex >>> setUpCell
What's happening here? To make sense of this, we essentially have to read this backwards.
What are we doing? We're setting up a cell.
With what informa...
The best option in this specific case is probably, as DPlusV suggest in the first line of his answer:
var screenRect: CGRect = self.window!.bounds
This will crash if self.window is nil, but given that in this specific scenario, we're in didFinishLaunching, if self.window is somehow nil, we've ...
I'm new to both concurrency programming and Go.
I've written a small server side script that gets the title and ratings of a book for a given ISBN. I've to optimise performance by using a cache and I've also added a check to ensure that two requests for the same book do not get sent to the Good...
I did code for Newton Raphson for logistic regression. Unfortunately I tried many data there is no convergence. there is a mistake I do not know where is it. Can anyone help to figure out what is the problem.
First the data is
y=c(rep(0,60),rep(1,55))
X=sample(c(0,1),size=3450,replace=T)
Z=t(...
A python script for automatically extract an archive file in a subfolder:
#!/usr/bin/env python3
// sub7z.py
import subprocess
import re
import os, sys, pathlib
class Counter:
counter = 0
def getCount(self):
self.counter = self.counter + 1
return self.counter
class Z...
Reffering other "Stack Exchange" Sources, I've been told that the only way of swapping BGR to RGB involves buffering. While this isn't true, I could just perofrm a quick C-SA algorithm on fseek or bmp buffer byte offsets. I wrote a fast implementation of fwrite, that swaps the first byte with the...
I have a javascript code but i'm non-javascript guy.This code take id and gives url.
For exampe for this id lWA2pjMjpBs it gives
http://dl8.downloader.info/dym_down.php?id=1ee49b508e4780975007a958dacec586
Here is the javascript code:
$(document).ready(function(){var Complete=false;var URL=doc...
The typeof() macro allows a few things.
First of all, personally, I've created a code snippet with this sort of thing. Instead of having to type out:
__weak MyClass *weakSelf = self;
each and every time I want to set this up, substituting MyClass for the appropriate class, I can instead just...
This can be prevented by adding some auto-layout constraints so that your web view will always take up the same portion of the screen no matter the device it runs on.
With the web view selected in interface builder, open up the constraints menu and add the appropriate constraints:
Note that I...
This code is code written on a whim to help $someindividual asking for such a thing on $somechatmedium; what is needed is a way, in Java, to provide an Iterator over Path objects which must only be directories, recursively, and where the number of returned instance number in some sufficient quant...
A python script for counting lines of an compressed file:
#!/usr/bin/env python3
import gzip, bz2, zipfile, os, sys
def openZip(zfile):
f = zipfile.ZipFile(zfile)
firstFile = f.filelist[0].filename
if firstFile.endswith("/"):
raise Exception("This zip file contains a direct...
The JSON standard uses double quotes for key names and string values, such as the following:
{"one":1,"two":"two"}
However, the current project I am working on requires JSON-encoded objects to use single quotes instead of double quotes. (In this case {'one':1,'two':'two'}). Right now, there is...
The code snippet below, receives data from a form, formats and inserts into the database.
This code snippet is located in a controller and the insertion is done in a 'repository' to manipulate data that entity laravel in my project.
Wonder if there are improvements to be made in this code for a g...
I am just dabbing by toes in the basics of python and for a simple text game I plan to make, I was just wondering how you could get a random number output by (random.randrange(1, 10) could be used to activate a part of a function.
So if it output "1" it would output a set of dialogue correspondi...
I have a very huge GSON coming from a URL which I am trying to serialize it on the fly as shown below with the working code.
private static final Type listOfMetricsType = new TypeToken<List<HostClientMetrics>>() {}.getType();
private static List<HostClientMetrics> loadMetrics(String url) {
...