• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Lonely1

Unconfirmed Member
Your fear is correct. Haskell doesn't memoize, it only thunks.

A where clause actually translates to a let form. You're creating a new data structure every time. If you want to cache the results, you'll need to refer to the same data structure ever time. I'll let you figure that one out :) if you need help, try googling "memoizing in Haskell". If you still need help, ask me in a PM!

Thanks. The simpler fix I can think of atm is to remove the where to something like:

Code:
invTranSamp x ls = geqS x ls
ls = cumDis ps

Is that right? But that feels patched-on and dirty :(

The solution I have is to just feed all the random points I need:

Code:
invTranSampL ps xs = map (\x -> geqS x ls) xs
   where 
   ls = cumDis ps

But I worry that that will waste lots of memory.
 

Ashes

Banned
I keep drifting in and out of programming. So this time round I've decided to try small projects. Just to keep me doing something.

First thing's first I want to create a script that would actually help fellow neogaffers. So I thought why not create a script that would collect all the posts with entries for the Creative writing thread?

It's a boring job. Basically the script would go through this thread

http://www.neogaf.com/forum/showthread.php?t=1274695

And output this:

Entries:
BearFlexington - Separation Anxiety
Cowlick - Age Before Beauty
Mike M - Dubious Dealings
Problem Attic - Science Fair
Tangent - Sitting on the Dock
Cyan - Untitled
Ashes - The Lady in the Tree
John Dunbar - In the Belly of the Behemoth
Nezumi - Lehrjahre
mu cephei - Enterprise
FlowersisBritish - Girl in the Chase

Court is now in session.

I kinda know python, but basically forget everything when I next start up the IDe a year later.

Notes:

Most of the entries will have a dropbox link with a pdf. So there's my starting point.

--

I'm guessing someone will be able to do this in one go. And that's super cool. But by doing this, do realise that I'm going to be peppering you with questions!!!
 

Quixzlizx

Member
Are there general guidelines to what web development languages are better to use for what types of apps? I want to code some small apps at work, but I don't know where to start. I'm eventually going to want them to interact with a SQL database.
 
I'm a bit stuck with some double precision float conversion I need to do in C#.

I have a value of 11.043055214723925, stored as a double. First, that's way too many decimal places, but I'm not sure if it matters yet.
I need to convert it to hex so it ends up being 0x4130b05b.
This is the code I have:
Code:
double d = 11.043055214723925;
byte[] array = BitConverter.GetBytes(d);
But I'm getting 0xb25246550b162640, which is too many bytes and way off the target. I want to match the results I'm getting here. I can always reverse the array if I get it in the wrong order.
 
I'm a bit stuck with some double precision float conversion I need to do in C#.

I have a value of 11.043055214723925, stored as a double. First, that's way too many decimal places, but I'm not sure if it matters yet.
I need to convert it to hex so it ends up being 0x4130b05b.
This is the code I have:
Code:
double d = 11.043055214723925;
byte[] array = BitConverter.GetBytes(d);
But I'm getting 0xb25246550b162640, which is too many bytes and way off the target. I want to match the results I'm getting here. I can always reverse the array if I get it in the wrong order.

The page you are looking at is for 32 bit single-precision floats, but you are working with a 64 bit double-precision float. Which is why your result is twice as long as you expected. You'll need to change your type from 'double' to 'float', then it should give you the expected result, I would think.
 

JeTmAn81

Member
I keep drifting in and out of programming. So this time round I've decided to try small projects. Just to keep me doing something.

First thing's first I want to create a script that would actually help fellow neogaffers. So I thought why not create a script that would collect all the posts with entries for the Creative writing thread?

It's a boring job. Basically the script would go through this thread

http://www.neogaf.com/forum/showthread.php?t=1274695

And output this:



I kinda know python, but basically forget everything when I next start up the IDe a year later.

Notes:

Most of the entries will have a dropbox link with a pdf. So there's my starting point.

--

I'm guessing someone will be able to do this in one go. And that's super cool. But by doing this, do realise that I'm going to be peppering you with questions!!!

If you're willing to try it in Javascript, I wrote this script that parses some data from GAF, though it's just thread titles and starters, not the contents of threads themselves:

https://greasyfork.org/en/scripts/7106-neogaf-hide-forum-threads/code

You'll want to concentrate on the GetAdditionalThreads function.
 

Ashes

Banned
If you're willing to try it in Javascript, I wrote this script that parses some data from GAF, though it's just thread titles and starters, not the contents of threads themselves:

https://greasyfork.org/en/scripts/7106-neogaf-hide-forum-threads/code

You'll want to concentrate on the GetAdditionalThreads function.

I know next to nothing about Java. But this is probably where I will jump to next following python. So thank you for the link.

my code is looking a mess right now - didn't even capitalise second words etc [really need to get into that habit]. But it kinda works. Here are the main functions of it..

Code:
def cleanuppost5(p):
	post, postend = getnexttarget(p)
	username = extractname(post)
	link = posturl(post)
	title = "title"
	entryline = username + " - [url=" + link + "]" + "title" + "[/url]" 


def printAlldropbox(page):
	while True:
		post, postend = getnexttarget(page)
		if post:
			if "dropbox" in post:
				print cleanuppost5(post) 
			page = page[postend:]
		else:
			break

def getnexttarget(p):
	poststart = p.find("<!-- / post")
	if poststart == -1:
		return None, 0
	postend = p.find("<!-- / post", poststart + 1)
	post = p[poststart:postend]
	return post, postend

def extractname(p):
	if 'color' in p:
		userBeforeStart = p.find('color')
		userNameStart = p.find('>', userBeforeStart+1)
		userNameEnd = p.find('<', userNameStart+1)
		username = p[userNameStart + 1:userNameEnd]
		return username
	else:
		userBeforeStart = p.find('href')
		userNameStart = p.find('>', userBeforeStart+1)
		userNameEnd = p.find('<', userNameStart+1)
		username = p[userNameStart + 1:userNameEnd]
		return username

def posturl(p):
	neogaf = "http://www.neogaf.com/forum/"
	check1 = p.find("postbit-post")
	showpoststart = p.find("showpost", check1)
	showpostend = p.find("amp", showpoststart + 1)
	neogaf2 = p[showpoststart:showpostend]
	poststart = p.find("post", showpostend + 1)
	postend = p.find('"',poststart+1)
	neogaf3 = p[poststart:postend]
	return neogaf + neogaf2 + neogaf3

Right now the result is this:

>>> printAlldropbox(pageall)
Cowlick - title
Mike M - title
Problem Attic - title
Tangent - title
Ashes - title
John Dunbar - title
Nezumi - title
mu cephei - title
FlowersisBritish - title


----

So lots done and lots left to do.

# get title - no idea how yet... probably try to get people to put in the first line of the post... or something
# get posts that were missed - 90% of the links are dropbox, so it only printed those. Need to get the two posts that don't have dropbox links.
#getpagesource - I'll get to this at the end

edit -
Putting title in the title box works fine with new code. :)
So pretty much set up to do what I want, if everyone puts title in the titlebox and tags their post with #entry. Awesome.
 
Ucchedav&#257;da;217703942 said:
The page you are looking at is for 32 bit single-precision floats, but you are working with a 64 bit double-precision float. Which is why your result is twice as long as you expected. You'll need to change your type from 'double' to 'float', then it should give you the expected result, I would think.

Right, it's so obvious now. Casting to float got the results I was expecting.
Thanks.
 
I need help figuring out this problem.

So I need to sum up columns of numbers in a text file (using Bash script).

An example would be:

1 2 3 4 5
5 4 3 2 1
1 1 1 1 1

Output would need to be: 7 7 7 7 7 (all the columns add to 7).

So my idea is to declare an array. Then iterate over the lines in the text file, and increment an index.

On first pass my array would be [1, 2, 3, 4 ,5]
on second pass of the loop it should be [6, 6, 6, 6, 6]

I'm having some trouble though because i don't know how to do past the first loop.
Adding to the array on first pass is easy. You can just do this:

Code:
declare -a colArr
while read line
do index=0
sum=0
for n in $line
do colArr[$index]=$n)
index=$index+1
done
done < test_file
#for i in ${colArr[@]};do echo $i;done

Adding the second+ time requires you to access the element. So instead of colArr[$index]=$n you'd need to do like: colArr[$index] = $(($(colArr[$index]) + $n)).

I can't use that syntax on the first pass (i think) because then I'd be trying to access a nonexistent value. Unless bash script defaults it to 0.

So what's the best way to handle this? Simply declare a variable called firstpass (or something) and just iterate at the end of the first for loop? Then use an if statement?
 
Is there something equivalent to modulo in bash? If not, you could have a row counter that subtracts a factor of row length to simulate it.

I'm not sure how that would work?

edit: My method worked, though the syntax in my example is off.

I get the accurate sums of the columns.
 

Koren

Member
Out of curiosity, do you need pure Bash?

I'd say it's work for awk (or perl)
Code:
awk '{for(k=0;k<NF;k++) s[k]+=$k;}; END {for (k in s) printf "%d ",s[k];}' filename
 

Koren

Member
If there's some SQL-gurus here, I'd like some insight...


I'm thinking about creating a set of tables to store the timetables of a bus network. There's a catch, that's not for an actual use, but I still want something usable for the same kind of usage.

Mostly, I need to be able to:
- given a stop name, listing all lines that go there
- given a time, a stop name, a line and a direction, get the next time the bus will stop there
- list all the following times and stops of the previous bus, till the end of the line


Here is my current take on this:


1) A table that store bus stops names

TABLE STOPS
int StopID
char[30] Name

where primary key is StopID


2) A table that stores times

TABLE TIMES
int LineID
int BusID
time Time

where primary key is LineID, BusID


I would use BusID not to identify a bus (again, I won't actually use it in real world, so I don't need bus management), but only a single "travel" of a bus: the BusID would change when the bus reverse at terminus.


So, here are my questions (I know it's mostly a matter of preferences, and that all solution could work):

In my current take, two buses on two different lines can share the same BusID. I could use different BusID over all the lines, so I wouldn't need both LineID and BusID in TIMES, as long as I add a third table that link BusID to LineID (or use some digits of BusID to store the line, such as 5007 for the 7th bus in the 5th line). Would this be better?

Would you add a ROUTE table to be able to get all the stops of a line more easily? (I mean, I can get the route by retrieveing the timetable of a given bus in TIMES... although in real situations, several buses (such as the first or last one) won't do the complete route, so choosing the right "bus" may be tricky)

I can use the parity of BusID to get the direction (A to B or B to A) in the line... Would it be better to explicitly use an additional boolean column (and then, in primary, or not?) Or use different LineID for both directions?

Any other advices?
 

Kalentan

Member
Not sure if I'd call myself "knowledgeable", but I did work a bit with a derivative language called Racket in college, so I may be able to answer basic questions.

Well I've been trying to figure out how to find how many numeric atoms exist in the top most layer of a list. So I'm kind of stuck because I assume I need to figure out how to remove the non-numeric atoms and then use the length function to give me a count.

So for example the list: (5 2 (A 2) 4 5 A B C (B 4)) would be equal to 4.
 

Pokemaniac

Member
Well I've been trying to figure out how to find how many numeric atoms exist in the top most layer of a list. So I'm kind of stuck because I assume I need to figure out how to remove the non-numeric atoms and then use the length function to give me a count.

So for example the list: (5 2 (A 2) 4 5 A B C (B 4)) would be equal to 4.

That is one approach you could take, and would probably be pretty simple if you have a "filter" function available.

One other approach you could use is iterate through the list and use an accumulator to keep track of the count.
 

Koren

Member
Well I've been trying to figure out how to find how many numeric atoms exist in the top most layer of a list. So I'm kind of stuck because I assume I need to figure out how to remove the non-numeric atoms and then use the length function to give me a count.

So for example the list: (5 2 (A 2) 4 5 A B C (B 4)) would be equal to 4.

My lisp is rusty, and my approach (rather functional) may not be in the spirit of LISP, but what about

Code:
(defun isint (elem)
  (cond ((integerp elem) 1) (t 0))
)

(defun countnumeric(lst)
  (reduce (lambda (cnt elem) (+ cnt (isint elem))) lst :initial-value 0)
)

(setq lst (list 5 2 (list 'a 2) 4 5 'a 'b 'c (list 'b 4)))

(write lst)
(princ " has ")
(write (countnumeric lst))
(princ " numeric atoms.")

?

(the first function return 1 for a numeric value, 0 for anything else, and the second one reduce the list to an integer using + and the previous function)
 

Ashes

Banned
Feels like Beautiful soup would be cool to know.

Today, I'm writing up the part of the code where I get the web page source.
 
Ok so I have an interview for an internship. It is at a tech company, with the potential to become a full time position.

The internship itself is customer/technical support oriented, but the person who did my phone screen made it sound like they do move people from there over to soft dev stuff.

I'm nervous. I've been so busy with work and school I didn't pour nearly as much time into practicing code as I should have. I have knowledge of most of the data structures. I think I need to review them a bit. Definitely need to review heaps and heap sorting. Need to review merge sort (and maybe bubble sort and quick sort). Need to go over some coding problems.

But the interview is Tuesday. I doubt I can cram that much shit in. Especially since I still have work + school work + school.

I'm praying that they ask really basic shit, and since it is a customer service/tech support oriented position I get "implement fizz buzz" questions. Please god.
 
If the internship is for tech support I wouldn't expect technical coding quotations. Was programming mentioned in the posting?

Vaguely. It did sound like at first I'll be doing very little coding. Though the person I spoke to during the phone screen made it sound like there's opportunity to do so.

So there might very well be no technical coding questions. But I feel like it is best to prepare for that just in case. For what it is worth, the internship posting required the student to be enrolled in a Comp Sci/Comp Engineering program.

Also what should I wear? Suit with no tie? The person described it as a very casual office. Mentioned that people wear jeans. But I know you're supposed to dress nicer for interviews. Is a suit overkill?
 

JesseZao

Member
Vaguely. It did sound like at first I'll be doing very little coding. Though the person I spoke to during the phone screen made it sound like there's opportunity to do so.

So there might very well be no technical coding questions. But I feel like it is best to prepare for that just in case. For what it is worth, the internship posting required the student to be enrolled in a Comp Sci/Comp Engineering program.

Also what should I wear? Suit with no tie? The person described it as a very casual office. Mentioned that people wear jeans. But I know you're supposed to dress nicer for interviews. Is a suit overkill?

The rule of thumb is one step up, but I don't think a suit would be considered overkill. I say just wear something appropriate that you are comfortable in.



In other news: It's hard for me to deal with nuget after using npm for a while. I'm starting to develop the front ends of my .Net MVC apps with React and the overhead/configuration is just obnoxious compared to how easy using node for the server side is. Once I set it up, using C#.Net as the backend will be nice, but there isn't a lot of help/support out there for ReactJS.NET yet. Realistically, I should just make the .Net backend a web service and develop the React Views completely separate, but alas I wanted to try something difficult "because."
 

JeTmAn81

Member
The rule of thumb is one step up, but I don't think a suit would be considered overkill. I say just wear something appropriate that you are comfortable in.



In other news: It's hard for me to deal with nuget after using npm for a while. I'm starting to develop the front ends of my .Net MVC apps with React and the overhead/configuration is just obnoxious compared to how easy using node for the server side is. Once I set it up, using C#.Net as the backend will be nice, but there isn't a lot of help/support out there for ReactJS.NET yet. Realistically, I should just make the .Net backend a web service and develop the React Views completely separate, but alas I wanted to try something difficult "because."

So from what I can tell you don't actually need to install any React packages for .NET. You can just download the two main JS files and reference them accordingly (bundling them would be good). Working with React in MVC shouldn't be too different from working with it anywhere else.
 

JesseZao

Member
So from what I can tell you don't actually need to install any React packages for .NET. You can just download the two main JS files and reference them accordingly (bundling them would be good). Working with React in MVC shouldn't be too different from working with it anywhere else.

I could, but I figured I'd give the package a try first. It has server-side rendering and transpiling, but I need to add something like Webpack to get module support (I can't go back to ES5 now...).

I'm more interested in exploring other build systems for now. Eventually I want to use TypeScript. It'll be a lot better once I can get a bare bones project template setup. I'm also trying to avoid jQuery.

Basically, React rules and I want to have experience using multiple back-ends with it.
 

JeTmAn81

Member
If there's some SQL-gurus here, I'd like some insight...


I'm thinking about creating a set of tables to store the timetables of a bus network. There's a catch, that's not for an actual use, but I still want something usable for the same kind of usage.

Mostly, I need to be able to:
- given a stop name, listing all lines that go there
- given a time, a stop name, a line and a direction, get the next time the bus will stop there
- list all the following times and stops of the previous bus, till the end of the line


Here is my current take on this:


1) A table that store bus stops names

TABLE STOPS
int StopID
char[30] Name

where primary key is StopID


2) A table that stores times

TABLE TIMES
int LineID
int BusID
time Time

where primary key is LineID, BusID


I would use BusID not to identify a bus (again, I won't actually use it in real world, so I don't need bus management), but only a single "travel" of a bus: the BusID would change when the bus reverse at terminus.


So, here are my questions (I know it's mostly a matter of preferences, and that all solution could work):

In my current take, two buses on two different lines can share the same BusID. I could use different BusID over all the lines, so I wouldn't need both LineID and BusID in TIMES, as long as I add a third table that link BusID to LineID (or use some digits of BusID to store the line, such as 5007 for the 7th bus in the 5th line). Would this be better?

Would you add a ROUTE table to be able to get all the stops of a line more easily? (I mean, I can get the route by retrieveing the timetable of a given bus in TIMES... although in real situations, several buses (such as the first or last one) won't do the complete route, so choosing the right "bus" may be tricky)

I can use the parity of BusID to get the direction (A to B or B to A) in the line... Would it be better to explicitly use an additional boolean column (and then, in primary, or not?) Or use different LineID for both directions?

Any other advices?

IMO the route is your top-level entity.

ROUTE

ID
BusID
StopID
Datetime

I'm not sure if you even need lines, or at least lines would really just be subsections of routes. But the route is the main logical entity of a transportation system.

I can't think of a good reason for having two unique vehicles with the same ID. I'd use a unique BusID for each.

Edit: routes could also just be collections of lines in sequence.
 

Koren

Member
IMO the route is your top-level entity.

ROUTE

ID
BusID
StopID
Datetime
Thanks for your advices... I was thinking the same (I've written stupid things in my post, there is obviously a StopID in the TIME table, or you couldn't store the times...), it's nice to have a confirmation I'm on track...

I'm not sure if you even need lines, or at least lines would really just be subsections of routes.
Well, the line is mostly a way to simplify requests, since real people will use line numbers...

Edit: routes could also just be collections of lines in sequence.
Now, that's an idea I haven't studied... Linked lists in SQL... It make a lot of sense, although getting the full route will require a lot of requests. Is this fine for a SQL application?
 
I just spent a good chunk of my day today fixing code merged into our baseline from a branch that wasn't updated properly.

Make sure to properly update your branches please.
 
I'm having trouble with bash.
Code:
midpoint=$(($(head -n 1 test_file | wc -w) /2 + 1))
echo "midpoint = $midpoint"
while read line
do
sortLine=$( echo $line | tr " " "\n" | sort -g | tr "\n" " ")
echo $sortLine
echo $(echo $sortline | cut -d ' ' -f $midpoint)
done < test_file
The purpose of this is to get the middlemost number of a sorted line in a file.

So lets say I have a file containing

2 5 1 9 8
6 5 3 2 8

This script will get the midpoint (3 in this case, proper behavior)
Sort the line to give
1 2 5 8 9 (this is working)
and then it should cut and echo out the 3rd number of this line (5 in this example).
Then move on to the second line and repeat.

The cut command isn't working properly for me. Instead of a number it is just echoing a complete blank. Maybe a space?

edit: got it working, nevermind. Small syntax error.
 

digdug2k

Member
God I hate the people I work with now. Like, I get it, you hate virtual functions. You're worried about us needing sometime in the future to render 100,000 times more than we have any plans for. You're insane. i get it. But that's what fucking review is for. Tell me "Ooh, I'd really prefer to not make something virtual if we don't really need to. Maybe we can do X instead". Shit like "You obviously didn't read that comment I made on a wiki page 3 months ago when you weren't on this team that's so far behind schedule you had to be brought in to fix it" or the even more helpful "doesn't match design" (how? I copied and pasted the line above this one and changed three letters. I really don't care what we do. Just tell me wtf you want!) just make me hate you.
 
So what kind of computers do you guys use for your workstations? I have a Mac that's nearly four years old and only has 4GB of RAM. Needless to say, it's incredibly inefficient. What specs do you guys usually hover with?
 

Kieli

Member
I hate that more and more companies are assigning homework that takes a weekend to a week to do, and job candidates are more than willing to indulge the companies in this matter.

Why? Why would you devalue not only yourself, but the whole profession by doing work for free?
 

upandaway

Member
So what kind of computers do you guys use for your workstations? I have a Mac that's nearly four years old and only has 4GB of RAM. Needless to say, it's incredibly inefficient. What specs do you guys usually hover with?
I honestly wish I was working locally on my computer even if it was weak and sluggish. All the development environments here are remote and it's such a pain in the butt. Sessions fall, servers go on maintenance, VNC eating up useful keyboard shortcuts, it's the worst.
 

Figments

Member
I dunno why, but I feel like trying to learn Rust while at the same time attending classes for C++ at my uni is just stupid crazy.

I dunno. Having fun with Rust, though. Studying up on graphics APIs to see if I can build a game engine with the language. Probably stupid, considering I'm not that experienced.
 

MasterMiller

Neo Member
"Writing a software" was a childhood dream of mine that I never got around to doing it despite trying a few times back then - started with a book about C++ thicker than my neck :)) - , but last summer I started learning HTML and CSS just for fun and it sparked my interest in coding again.
I started with JavaScript but switched to Python and switched again to Java. learned the fundamentals of Java and i have made some Command line apps mainly for personal use and they are pretty simple ones. even read the Think Java book, it really helped in some areas.

but now I'm stuck, I don't know what to do next or what area I should focus on.
so i'm open to any advice regarding my current situation like is there any books i should read or things like this...

this is important for me because I'm thinking of starting a career so any advice is appreciated.
 
"Writing a software" was a childhood dream of mine that I never got around to doing it despite trying a few times back then - started with a book about C++ thicker than my neck :)) - , but last summer I started learning HTML and CSS just for fun and it sparked my interest in coding again.
I started with JavaScript but switched to Python and switched again to Java. learned the fundamentals of Java and i have made some Command line apps mainly for personal use and they are pretty simple ones. even read the Think Java book, it really helped in some areas.


but now I'm stuck, I don't know what to do next or what area I should focus on.
so i'm open to any advice regarding my current situation like is there any books i should read or things like this...

this is important for me because I'm thinking of starting a career so any advice is appreciated.


Effective Java and Clean Code are great resources. Effective Java might seem a little advanced at times but it's a resource that will be useful for beginners to experts.
 
"Writing a software" was a childhood dream of mine that I never got around to doing it despite trying a few times back then - started with a book about C++ thicker than my neck :)) - , but last summer I started learning HTML and CSS just for fun and it sparked my interest in coding again.
I started with JavaScript but switched to Python and switched again to Java. learned the fundamentals of Java and i have made some Command line apps mainly for personal use and they are pretty simple ones. even read the Think Java book, it really helped in some areas.

but now I'm stuck, I don't know what to do next or what area I should focus on.
so i'm open to any advice regarding my current situation like is there any books i should read or things like this...

this is important for me because I'm thinking of starting a career so any advice is appreciated.
Pretty much every developer needs to know javascript these days. Also databases and SQL.
 

Koren

Member
Pretty much every developer needs to know javascript these days.
Really? Most of those I know aren't versed into JS, as far as I know. There's a huge need in anything lossely related to internet, and I know node.js can be used for many other things, but isn't there plently of fields where it doesn't matter?
 

JesseZao

Member
Really? Most of those I know aren't versed into JS, as far as I know. There's a huge need in anything lossely related to internet, and I know node.js can be used for many other things, but isn't there plently of fields where it doesn't matter?

It's probably true in the sense that a lot of entry level jobs will be some sort of web dev position.
 

Koren

Member
It's probably true in the sense that a lot of entry level jobs will be some sort of web dev position.
No doubt... I'm sure a good 2-digits % of developpers deal with JS.

I was reacting with "pretty much every". I don't even think there's a majority there...
 
Top Bottom