Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 407 408 [409] 410 411 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 818352 times)

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6120 on: July 24, 2014, 12:02:53 am »

I found Allegro really easy to do stuff in, and also handles sounds and stuff.
Logged

PsyberianHusky

  • Bay Watcher
  • The best at being the worst at video games.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6121 on: July 24, 2014, 03:08:22 am »

So, anyone have any experience with webscraping?
Logged
Thank you based dwarf.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6122 on: July 24, 2014, 07:30:14 am »

A little bit, but it usually ends up being pretty frustrating to do.  Just be extra careful if you're trying to use regular expressions to parse out HTML: regular expressions aren't powerful enough to describe HTML completely and can make it extremely difficult or impossible to scrape out some things.  For simple stuff it's probably fine, but for complicated things you'll need a DOM parser.

Date functionality? Hmm, maybe some of the libraries recommended here could be of use?

Hmm, yes, those do look like they would fill in pretty much everything PHP's standard library provides that we'd need.  I'll have to look into it some more when / if we start using Node.js.
Logged
Through pain, I find wisdom.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6123 on: July 24, 2014, 08:36:18 am »

A little bit, but it usually ends up being pretty frustrating to do.  Just be extra careful if you're trying to use regular expressions to parse out HTML: regular expressions aren't powerful enough to describe HTML completely and can make it extremely difficult or impossible to scrape out some things.  For simple stuff it's probably fine, but for complicated things you'll need a DOM parser.

Don't reinvent the wheel (unless you want to). Coming from the Python world, we've got Scrapy, BeautifulSoup, and a bunch of other libs that do web scraping (former) and DOM parsing (latter). Your language of choice probably also has something.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #6124 on: July 24, 2014, 08:54:47 am »

Working through some Katas, I think I've come up with the most needlessly recursive Roman Numerals Decoder:
Code: (scala) [Select]
def detokenise(numerals : String) : Seq[Int] = numerals.map(_ match {
    case 'I' => 1
    case 'V' => 5
    case 'X' => 10
    case 'L' => 50
    case 'C' => 100
    case 'D' => 500
    case 'M' => 1000
    case _ => throw new Error("")
})

def calculate(values : Seq[Int]) : Int =
    if (values.size == 0)
        0
    else if (values.size == 1)
        values.head
    else {
        val max = values.max
        val pre = values.takeWhile(_ != max)
        val post = values.dropWhile(_ != max).drop(1)
        max - calculate(pre) + calculate(post)
    }

def romanToInt(numerals : String) = calculate(detokenise(numerals))


val testPairs = Seq((1,"I"),
      (2,"II"),
      (4,"IV"),
      (5,"V"),
      (9,"IX"),
      (10,"X"),
      (900,"CM"),
      (1000,"M"),
      (3497,"MMMCDXCVII"))

testPairs.foreach(a => {
    val actualResult = romanToInt(a._2)
    println("%s: Expected: %s, Actual: %s".format(a._2, a._1, actualResult))
    assert(a._1 == actualResult)
})

Turns out you can replace the calculate with
Code: (scala) [Select]
def calculate(values : Seq[Int]) : Int =
    values.foldRight((0, 0))((currentValue : Int, previousAndTotal : (Int,Int)) =>
        if (previousAndTotal._1 > currentValue)
            (currentValue, previousAndTotal._2 - currentValue)
        else
            (currentValue, previousAndTotal._2 + currentValue)
    )._2

Or even just implement it as a reverse for-loop. Oops...Well, wouldn't be too bad if the first solution wasn't based on the pseudocode I came up with during an interview earlier today. Not even trying to 'show off how I can do recursion' or anything, that first one is just the in-code version of how I did the calculations in my head.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6125 on: July 24, 2014, 10:15:46 am »

A little bit, but it usually ends up being pretty frustrating to do.  Just be extra careful if you're trying to use regular expressions to parse out HTML: regular expressions aren't powerful enough to describe HTML completely and can make it extremely difficult or impossible to scrape out some things.  For simple stuff it's probably fine, but for complicated things you'll need a DOM parser.

Don't reinvent the wheel (unless you want to). Coming from the Python world, we've got Scrapy, BeautifulSoup, and a bunch of other libs that do web scraping (former) and DOM parsing (latter). Your language of choice probably also has something.

A good point.  Pretty much anything I ever post here related to web development is going to be coming from a PHP or JavaScript perspective since those are the languages I use in my day job.  PHP has stuff for DOM parsing built into its standard library, but I don't think it has any sort of web scraping stuff directly.  There are probably plenty of libraries for it, but I've never used any.
Logged
Through pain, I find wisdom.

Kirbypowered

  • Bay Watcher
  • Proficient Dabbler
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6126 on: July 24, 2014, 11:24:13 pm »

Okay, I have arrived at a familiar point today. After a little over half a month of fiddling, frustration, an absurdly long power outage, and ceaseless distractions, I can now get a little '@' to move around a terminal. Now with 100% less screen flashing! It feels like I've been on pause for this whole time, but I have admittedly learned a lot of useful stuff since then.

Now then, time to start putting something together...
Logged
THE WINTER MEN COME DOWN THE VALLEY AND KILL KILL KILL.
I'm voting for the Plaid Acre up next on COLORS AND MEASUREMENTS weekly.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #6127 on: July 30, 2014, 11:36:36 am »

I know someone who did some web-scraping stuff for his coursework that used node.js clusters, so it's doable in node.js too. Google reveals tutorials.

Currently refactoring the heck out of my coursework ReST API so it's actually workable, I ran out of time so basically wrote it as a giant mess lost in callback hell. Moving all the callbacks over to Q promises definitely cleans things up, and plays pretty nicely with Typescript and Webstorm too :)
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #6128 on: August 06, 2014, 11:45:19 am »

So I have an interview in a couple of days for a Junior/Grad job, and they're looking for "Javascript/HTML/CSS now, capable of transitioning to a server-side project in a few months". Now, I like to think I have a wide range of skills and could do that, but my web frontend is a little rusty (HTML5 was new the last time I made a serious website from scratch).

I know the tools and language, but I'm not a web designer so I've not had much call to do anything practical with it, so anything I do when playing around is basically the "Geocities GIF spam" of HTML5, just using as many fancy things as I can to make something hideously beautiful. I can do katas, ask me to make something happen on a web page and give me access to documentation and I can do it, but it's not something I can just reach for on the same level that I can C# or C++.

Anyway, the first part of the interview is a technical test, predominantly on Javascript but with a little HTML5. Now, the issue is what they mean by Javascript. Because it could be:
Javascript the language, aka. ECMAScript
Javascript the DOM glue
Javascript the JQuery/Bootstrap glue
Javascript the Virtual Machine for the Internet

Probably not the last one, and my hope is it's predominantly the first one since I know the most about the what-not-to-do with Javascript, but my knowledge of the DOM isn't by-heart (seriously, ain't nobody got time for that) and my JQuery/Bootstrap usage has been fairly basic, JQuery for input events for games, Bootstrap for drop-down menus. So got some revision to do it seems :)
« Last Edit: August 06, 2014, 11:49:24 am by MorleyDev »
Logged

Sheb

  • Bay Watcher
  • You Are An Avatar
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6129 on: August 06, 2014, 11:51:48 am »

Well, good luck!
Logged

Quote from: Paul-Henry Spaak
Europe consists only of small countries, some of which know it and some of which don’t yet.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6130 on: August 06, 2014, 05:40:15 pm »

I'd probably expect JavaScript as the language.  They're probably (hopefully) mostly interested in you not doing terrible things with the language and may want proof that you know how to do stuff with JavaScript without asking "Where's jQuery?  Or that little dollar sign function?"  Hopefully it won't be an endless stream of obscure and completely esoteric questions about scope and when things become undefined or why adding two things together produces NaN, a number, an object or something else when you're adding things that have no business being added together in the first place.

I'd call BS if they're expecting you to know DOM stuff without having a reference.  As you pointed out, nobody bothers memorizing that, or really even working with it directly anymore.

Anyway, yeah, good luck.
Logged
Through pain, I find wisdom.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6131 on: August 10, 2014, 05:55:13 pm »

Protip: if using an API like OpenCL which loves using void* along with size_t, create a wrapper class for those. It will save you so much trouble when you might otherwise pass in something along the lines of:
Code: [Select]
void API_Foo( void*, size_t );

void SomeIntermediateFunction( void* MyBuffer, size_t Size )
{
    ... otherstuff ...
    API_Foo( MyBuffer, Size );
    ... otherstuff ...
}

void* MyBuffer = (void*)SomeData;
size_t Size = SomeDataSize;
SomeIntermediateFunction( &MyBuffer, Size );

OR

void* MyBuffer = (void*)&SomeData;
size_t Size = SomeDataSize;
SomeIntermediateFunction( MyBuffer, Size );
Especially when said api likes making types along the lines of:
typedef _cl_mem* cl_mem;
And thus literally everything silently turns into a void* when you turn your back.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #6132 on: August 10, 2014, 08:56:13 pm »

Turns out the tests were more just establishing baseline knowledge. Was all pretty trivial, more about filtering out people who don't know the basics and sizing up people who do. Oh well, never any harm in rereading Effective Javascript :P
« Last Edit: August 10, 2014, 09:35:35 pm by MorleyDev »
Logged

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6133 on: August 12, 2014, 12:05:33 pm »

I've found some link about a x86 decompiler into LLVM intermediate code. AFAIK it isn't yet released, but I wonder if it might be of some help for people to port DF to some new architecture (like x86_64 or ARM) or maybe even producing a more optimised exe or something.

http://www.phoronix.com/scan.php?page=news_item&px=MTc1OTQ
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6134 on: August 12, 2014, 05:07:30 pm »

OK, so I want to set up a clock class that stuff all over my game can use, without me having to pass it around as an argument all the time. Here's what I got:

clock.h
Code: [Select]
#ifndef CLOCK
#define CLOCK

#include <SDL.h>

class clock
{
private:
int ticks;
public:
clock();
int get_time();
int update();
};

static clock gm_clock;

#endif
clock.cpp
Code: [Select]
#include "clock.h"

clock::clock()
{
ticks = 0;
}

int clock::get_time()
{
return ticks;
}

int clock::update()
{
ticks = SDL_GetTicks();
return 0;
}

I call the update function in every loop of my main game loop, and the ticks seem to update properly. However, when I call get_time() from an animation (which is in a completely different cpp file), the ticks are stuck at 0. I'm guessing that I misunderstood the static thingie, but if that's not how I do this, then what is? Can I have a global clock class like this, or am I doomed to stick it into my main game class and pass it around wherever it's needed?
« Last Edit: August 12, 2014, 05:10:31 pm by DJ »
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...
Pages: 1 ... 407 408 [409] 410 411 ... 795