[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 28
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>52921519

What are you working on /g/?
>>
first for averaging 2 ints with patented algorithms
>>
>>52926442
You're right.
Though according to this https://stackoverflow.com/questions/28320454/can-xor-of-two-integers-go-out-of-bounds XOR cannot produce trap representations.
>>
File: parens.png (11 KB, 652x516) Image search: [Google]
parens.png
11 KB, 652x516
Oh my god, it's matching parens.
>>
Second for copyright and software patents are evil and cancer.
>>
>>52926512
looks cool
>>
File: gayparens.png (6 KB, 399x241) Image search: [Google]
gayparens.png
6 KB, 399x241
>>52926530

it's gay.
>>
Postgres is making me want to kill myself.
Takes like 50 seconds to find a value matching x, ordered by y (in a table with like 30M rows but still) even though its indexed
>>
>>52926500
The patented algorithm filled by the russian at USA is for abs without branching.
Compute the integer absolute value (abs) without branching

int v; // we want to find the absolute value of v
unsigned int r; // the result goes here
int const mask = v >> sizeof(int) * CHAR_BIT - 1;

r = (v + mask) ^ mask;

Patented variation:

r = (v ^ mask) - mask;

On March 14, 2004, Keith H. Duggar sent me the patented variation above; it is superior to the one I initially came up with, because a multiply is not used. Unfortunately, this method has been patented in the USA on June 6, 2000 by Vladimir Yu Volkonsky and assigned to Sun Microsystems. On August 13, 2006, Yuriy Kaminskiy told me that the patent is likely invalid because the method was published well before the patent was even filed, such as in How to Optimize for the Pentium Processor by Agner Fog, dated November, 9, 1996. Yuriy also mentioned that this document was translated to Russian in 1997, which Vladimir could have read. Moreover, the Internet Archive also has an old link to it.

https://graphics.stanford.edu/~seander/bithacks.html
>>
>>52926581
Write your own DBS
>>
>>52926581
Indexed by what.
>>
is this real? https://www.youtube.com/watch?v=Er6R5R06Q8I
>>
>>52926571
>define
>>>>>>>>"""""""""""""""""define""""""""""""""
>not defun
This is heathenry.
>>
>>52926625
I've got a multicolumn index on x and y.
If I have a query with ORDER BY x ASC it takes 1ms, but with ORDER BY x DESC it takes for fucking ever.

I'm going to try CLUSTER, even though it probably wont be finished until next fucking year.
>>
>>52926606
Once again, assembly is the way to go.

absvalue: ;fastcall ecx
mov [esp-04h],ecx
fild dword[esp-04h]
fabs
fist dword[esp-04h]
mov eax,[esp-04h]
ret


Everyone already recommends learning it, why haven't you, /g/?
>>
>>52926510
please try reading the standard and using reason
can you xor two values and get 1000..0000? that can be a trap on ones' complements and sign-magnitude implementations
can you xor two values and get 1111..1111? that can be a trap on 2's complement implementations
how can you compare that value to anything afterwards if it's a fucking trap?
>>
>>52926633

When I say ""lisp"" what I really mean is Scheme, the ultimately superior successor to the original burning garbage heap that was Lisp.
>>
>>52926756
>LISP

>Lets
>Input
>Some
>Parentheses
>>
REMINDER TO UPDATE YOUR PORTFOLIO!

What kind of nifty things have you written but not yet published documented for future job applications? Add them now.
>>
What was the first personal project that gave you some self-esteem as a programmer?
>>
>>52926756
>Scheme
>superior
bwahahahaha, sure thing; wake me up when the figure out the R*RS clusterfuck
>>
>>52926786
>What kind of nifty things have you written
>What was the first personal project that gave you some self-esteem as a programmer?
Could you guys stop reminding me that I've been programming for a decade but I still haven't done anything worth a damn?
>>
>>52926786
i'm working on a kernel. you want to help here's my github:

https://github.com/torvalds
>>
>>52926792
A Linux shell in C, lost in some hard drive formatting.
>>
>there is a post-compile tool which allows inline IL in C#

this could be fun.
>>
>>52926792
In elementary school, one of the teachers asked
>A cow costs $10, a pig costs $3 and a chicken costs $0.50. A farmer buys 100 animals for $100. What does he buy?

This was before Google, obviously.

I solved it with programming and got a chocolate bar.

Now I'm a greasy fat programmer.
>>
>>52926792
I wrote a program that read several RSS feeds for anime series and then downloaded them from some IRC bots using XDCC. I original wanted it because the halls of residence at university had really slow torrent speeds for most of the day and XDCC was A LOT faster.
It was in C, and I didn't use any libraries (besides POSIX stuff).

Looking back on it, it's pretty shitty, but it was rewarding writing something non-trivial that could actually solve a problem of mine.
>>
>>52926756
>"""hygenic""" macros

fucking garbaged
>>
>>52926756
>scheme
>ever
>>
I'm the guy from a couple threads back (>>52916537) who was having issues linking with libFLAC in Visual Studio. It turns out that I needed to define FLAC__NO_DLL before including the header file (FLAC/stream_decoder.h) to stop getting the error as described in FLAC/export.h.
>>
>>52926878
>>52926882

litreally kill you are selves.
>>
>>52926786
Nothing.

I made a text editor with basic read/write capabilities in C++ but that's pretty much it. I tried to make a calculator and couldn't figure it out. I tried to make a blackjack cli game but got so bogged down by the method I just didn't find it fun anymore.
>>
>>52926786
I develop all my personal projects in public on GitHub, and I add the 2 or 3 that I think are most impressive or relevant to my resume.
>>
>>52926863
Looks like there's 100s of solutions, so what kind of an answer was he expecting?
>>
File: 1439235371751.png (51 KB, 792x600) Image search: [Google]
1439235371751.png
51 KB, 792x600
>tfw java master race

pic related, it's me while succeeding in the IT world while you keep masturbating to traps and C fizzbuzz.

>but loonix and C will keep me employeed, /g/ays told me.
>but muh ASM and C
>muh performance
>>
File: ZXWdeeS.jpg (179 KB, 619x406) Image search: [Google]
ZXWdeeS.jpg
179 KB, 619x406
>tfw jew master race

pic related, it's me while succeeding in the globalized world while you keep masturbating to meritocracies and hard work.

>but if I save my money i'll have more, /biz/ told me
>but muh job and education
>muh stable life
>>
>>52926934

8 cows, 8 pigs, -8 chickens.
>>
>>52926935
But you are gay anon. You lost.
>>
>>52926934
Ten cows.
>>
>>52926735
>spilling to memory
>using slow fpu instructions
bro, can you even into performance?
fastabs: ;fastcall ecx
mov eax, ecx
sar ecx, 31
xor eax, ecx
sub eax, ecx
ret
>>
>>52926935
>webshit
>succeeding
m8...
>>
Help my /g/, I need to implement pthreads in C and am completely lost.

Do you guys know any good tutorials or resources to learn this?
>>
File: dpt.png (550 KB, 1500x1800) Image search: [Google]
dpt.png
550 KB, 1500x1800
>>52926461
REMINDER to ignore TROLL posts that contain:
> gcc compiles this wrong code!!! (posts some retarded shit, compiles with g++)
> java can't compare these Integers with ==
> average of two ints in C
> fizzbuzz
> buzzwords
> go has no generics
> haskell is useless
> lisp brackets are unreadable
> GC is shit, use a real language
> programming literate
> anime ops
> non-anime ops
> posting new thread to early
> anime is gay
> trap ops
> non-trap ops
> osgtp anarchy politics
> osgtp black women
> tripfags in general

also, don't forget to post this in the next thread.
thanks.
>>
>>52927065
*me
>>
>>52927065
https://en.wikipedia.org/wiki/POSIX_Threads#Example
>>
>>52927078
>> osgtp anarchy politics
>> osgtp black women

I implores you to remove this from the list.. fucker.
>>
>>52927102
post it yourself in the next thread then, faggot
>>
Does anyone in this entire fucking thread have the v2.0 ideas pictures or not?? I've been asking for like two weeks and nobody's fucking responding. I saw it posted once, didn't save it, and now it seems as if it's lost forever.
>>
>>52927185
v2.0 of what?
>>
>>52927236
>v2.0 ideas pictures
Gee idk.
>>
>>52927253
I don't know what are you talking about, look at this: https://codefights.com
>>
>>52926935
>succeeding
Interesting choice of words; you willingly became a monkey.

Oh well, it's still a living, isn't it?
>>
>>52927102
back to /o/, fucker
>>
>>52927043
>>52927324
what's the (supposed) alternative, according to the elite computer scientists of 4chan?
>>
I was wondering what /dpt/ thought about C Primer Plus for learning C as a first language?
>>
>>52927397
Go, the new systems programing language.
>>
File: 1429792631140.png (378 KB, 1450x1080) Image search: [Google]
1429792631140.png
378 KB, 1450x1080
>>52927253
>>52927185
You're clearly fucking stupid because even not knowing what the fuck you're talking about I found it in a few seconds. If this is the level of your intelligence you probably shouldn't be attempting these exercises.
>>
>>52927406
first language ? you want to talk in C?

don't you mean first programming language?
>>
>>52927416
what?
I'm talking about the alternative to becoming a code monkey.

>>52927406
K&R, there is a reason is one of the most suggested books out there... after that, pick any "advanced C" book, or something
>>
>>52927429
>programming challenges v2.0
>"v2.0 ideas pictures"
k
at least you googled it...
>>
>>52927454
Isn't that more for people who already have a programming background?
>>
>>52927467
Is that not right? I can't fucking tell because you're being so vague about what you want while still expecting anyone to help you.
>>
>>52926792
I'll only have self esteem when I can get a job as a programmer.
>>
>>52927338

Never in your life.
>>
Java dog retard back again

I got most of my program to start working (Thank you /dpt/) but I'm having troubles on something

Array of a class called Kennels, each Kennel has a reference to a class called Dog that describes a dog by int height and int weight, Kennels is stored in a class called Info which also references a new Dog class for each new Kennel added

I have something like

for(int i = 0; i < kennels.length; i++){
if(infoDog.equals(kennels[i].getDog()){
System.out.println("Duplicate dog");
}
}


to catch if the user puts in a duplicate Dog

It doesn't catch it though

if I print infoDog and kennels[i].getDog(), it prints the same thing
if I change kennels[i].getDog() to kennels[i].dog it still doesn't work

Any noticeable reason why? If they both print the same values, and the debugger shows them both having the same values, while being two different references, then why isn't it equal?
>>
>>52926756
as it should be
>>
>>52927648
You said infoDog also stores information on the kennel? It may be including that in the equals function whereas you're specifying just the dog from the kennel.
>>
File: 1454898359648.jpg (84 KB, 500x446) Image search: [Google]
1454898359648.jpg
84 KB, 500x446
When writing an interpreter, how is one supposed to deal with nested loops?
Do I have to write a stack or something?
>>
File: First code.png (33 KB, 932x994) Image search: [Google]
First code.png
33 KB, 932x994
Im trying to learn how to make
https://www.youtube.com/watch?v=R8O8Y6xP79w
I dont see anything wrong with it the code in comparison, so whats the deal?
>>
>>52927648
you need to override .equals() in Dog to check the things you want to check against for equality. right now it's probably checking against hash codes and shit.
>>
>>52927692

infoDog is just a new Dog that gets created every time the user wants to add a Dog, it passes height and weight to the Dog reference in each Kennel

I should have mentioned that infoDog is just a Dog too, like
Dog infoDog = new Dog(height, weight)
, which then gets passed to a kennel as long as there is no other dogs with the same description in any other kennel like
kennels[numDog] = new Kennel(infoDog) 


>>52927728

Isn't equals just a way of checking if two strings output the same thing? Dog or Kennel.getDog() is basically just a string of height + weight

So I basically need to define what I'm actually checking to be equal?
>>
I've just started programming, and am using java as my first language. I'm trying to make an example program for learning purposes that will take a day of the week, and check if it's a weekday or weekend; simple stuff. I've been doing it with a load of if/else if statements, but have been told there's a way to do it in 1-3 statements. How would i go about doing this? Thanks in advance
>>
>>52927785

>Isn't equals just a way of checking if two strings output the same thing?
equals() is a method in every Object to check if it is equal to another Object. i think the default behavior checks to see if they both refer to the same object in memory. or you can override it to use different criteria to check for equality, such as the same fields or whatever.

>So I basically need to define what I'm actually checking to be equal?
yes
>>
>>52927848
Not 100% on what you want to do but you'd only need one if, else.

if (saturday || sunday) {
weekend;
} else {
weekday;
}
>>
>>52927941

>i think the default behavior checks to see if they both refer to the same object in memory

ah fuck this makes so much sense

my previous issue was that i couldn't figure out why the fuck completely different inputs were triggering the if statement, anon informed me that i was actually just dealing with the same reference in memory and anytime a user edited Dog, it was also editing every other Dog in the array (since they're the same object in memory)

thank you
>>
>>52927971
>anytime a user edited Dog, it was also editing every other Dog in the array
lol

you're welcome
>>
>>52927727
Does my text not turning blue or orange mean anything?
>>
>>52927848
String dayToCheck = System.in.readLine();
String[] weekdays = { "monday", "tuesday" ... }
if (weekdays.indexOf(dayToCheck) > 4) {
/* weekend */
} else { /* weekday */ }


Basically this gives you an array (read up on them if you are unfamiliar) like this:
0: "monday"
1: "tuesday"
2: "wednesday"
3: "thursday"
4: "friday"
5: "saturday"
6: "sunday"

Then this:
weekdays.indexOf(dayToCheck)
is a reverse lookup, so you go from for example "thursday" to 4.
>>
>>52927958
>>52928003
import java.io.*;

public class Assignment_1_JoshKeel{ //Class Start
public static void main (String args[]){//Main Start

String DayInput;
DayInput="";
//Keyboard Link Start
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
//Keyboard Link End

System.out.println("What day is today? ");

try{
DayInput = reader.readLine();
}
catch(IOException e){
}
if(DayInput.equalsIgnoreCase("Monday")){
System.out.println(DayInput + " is a weekday.");
}
else if(DayInput.equalsIgnoreCase("Tuesday")){
System.out.println(DayInput + " is a weekday.");
}
else if(DayInput.equalsIgnoreCase("Wednesday")){
System.out.println(DayInput + " is a weekday.");
}
else if(DayInput.equalsIgnoreCase("Thursday")){
System.out.println(DayInput + " is a weekday.");
}
else if(DayInput.equalsIgnoreCase("Friday")){
System.out.println(DayInput + " is a weekday.");
}
else if(DayInput.equalsIgnoreCase("Saturday")){
System.out.println(DayInput + " is the weekend.");
}
else if(DayInput.equalsIgnoreCase("Sunday")){
System.out.println(DayInput + " is the weekend.");
}
else{
System.out.println("That is not a day");
}
}
}

This is what i had earlier, having trouble comprehending, sorry. I appreciate the help
>>
>>52927712
Yes. A pushdown automaton (which is used to parse context-free languages) requires a stack.
>>
>>52928042
Ganbarimasu, Josh-kun
>>
File: su.png (93 KB, 1920x1080) Image search: [Google]
su.png
93 KB, 1920x1080
How do I only draw the outline?
Can I make use of sin and cos to go a sort of bresenham approach?
>>
>>52928042

As a fellow beginner java student here's what I would have gotten

import java.util.Scanner; // Scanners are useful 

public class Assignment_1_Anon{
public static void main (String args[]) {
Scanner userScan = new Scanner(System.in) // Declares a new scanner for your users to use
System.out.println("What day is it today?: ");
String day = userScan.nextLine();
if(day = "Saturday" || day = "Sunday"){ // the operator " || " is an OR operator. If day is saturday OR day is sunday, then do this, etc
System.out.println(day + " is a weekend");
} else {
System.out.println(day + " is a weekday.");
}
}
}


"If else" is exactly that, if the conditions in the if statement were not meant, it will do whatever is inside of 'else' instead. I don't know if there's a better way to get inputs than scanners though. I'm sure there are millions of better ways to do this though.
>>
Has anyone ever created a lossy text compression? Because I just thought of it
1) Strip page of punctuation and all non alphabetic characters
2) Get count of all characters and order them by occurrence
3) Assign most common characters prime numbers starting with 2, 3, 5... going all the way up to 101
4) Go through each word and multiply the prime numbers as much as you can without hitting the int limit.
5) Null for new word and double null for new sentence

So at the end of it, you can't tell the order of the letters. But you can use prime factorization to find out the letters. But if you want, you can get a lookup table with every single correctly spelled word being used. And then compare the word to those.

For example, it could be something like
Feeling
f=53
e=2
e=2
l=31
i=11
n=13
g=59

53*2*2*31 = 6572
11*13*59 =8437

Then it can be stored into 2 16 bit integers, the equivalent of 4 chars, saving 3 bytes. Then you can decode it using prime factorization and the map you used to encode it

6572 = 2*2*31*53
8437= 11*13*59

Decoded: eelfing

And if you want to fix everything, you can just get a lookup table of all words You can just look to see which word has the letters eelf in the first four letters, and ing for the next three.
>>
>>52928190
>I just thought of a compression algo-
STOP
>>
>>52928233
lossy text compression*
I'm doing it for the shits and giggles.
>>
>>52928190
>lossy text compression
So it's completely fucking useless?
>>
>>52928257
Pretty much.
Shits and giggles.
>>
>>52928268
Also, I forgot to mention
>using prime factorization
So it's not only useless, it's hard to compute.
>>
>>52928190
Neat. post code?
>>
File: su.png (101 KB, 1920x1080) Image search: [Google]
su.png
101 KB, 1920x1080
>>52928125
Well that was easy.
>>
>>52928042
>catch(IOException e){
>}
Never do this by the way.
catch(IOException e){ e.printStackTrace(); }

is a lot better. If you just leave the catch block open, sometimes you will have errors that you can't see because they just disappear out into the void.

Here you go, a working version:
http://pastebin.com/SVsdPND8

It probably contains a lot of syntax you haven't seen before, but that's because java is shit.
>>
>>52928129
if (day.equalsIgnoreCase("saturday") ||
day.equalsIgnoreCase("sunday") {
...
}


don't compare strings with '==', use the String compare methods.
(as a side note, you used '=' not '==' so that was incorrect anyway)
>>
>>52928282
Prime factorization of a maximum of 65535? With knowledge beforehand that it'll only be 26 specific primes? All you have to do is loop through 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,61,67,73,83, and 101
>>52928326
Haven't finished it yet. Wrote the concept on paper, currently writing it in C++
>>
>>52928129
>if(day = "Saturday"
Ignoring the typo (you meant == not =), you should be using day.equals("Saturday") instead of == when comparing strings.
>>
>>52928190
>1) Strip page of punctuation and all non alphabetic characters
What about numbers?

>Decoded: eelfing
That's very lossy;
Fellini
feeling
felling
filling
fleeing
gelling
gigging
ginning
legging

Also you lost the capitalization of F.
Essentially nothing is preserved.

I like the idea though.
>>
>>52928362
>>52928381

Oh right, my bad
>>
File: alsbspwl.jpg (19 KB, 260x325) Image search: [Google]
alsbspwl.jpg
19 KB, 260x325
Been thinking about checking out this book for learning assembly? Is this the best one there is for Linux x86 assembly?
>>
>>52928393
>That's very lossy;
Oops, I didn't account for letter usage.
>>
>>52927648
>>52927971
Hello Java, my old friend...

.equals() will default to ==, so it will just check to see if the objects are identical i.e. the same instance in memory.

Strings have .equals overridden to compare the actual string outputs, with == actually checking for identical references.

You could literally look up the java implementation of String.equals() and use that for your Dog class.
>>
>>52928430
The best is the Intel x86 manuals (4 volumes full of information, from 16bit to 64bit, extensions and more).
>>
>>52928444
You sure that's the best way to learn assembly?
>>
>>52928436

Yeah, I just made a new class in Dog like so

    public boolean isEqual(Dog dog) {
boolean equalDog;
if (weight == dog.getWeight() && height == dog.getHeight()) {
equalDog = true;
} else {
equalDog = false;
}
return equalDog;
}


Obviously not the best thing but I'm about to head off to bed
>>
>>52928393
>Numbers
The concept than be applied to any group of characters Just add more and more primes. I'm keeping it simple to lower case alphabet.

>lossy
Not really
6572 will always be before 8437. So the letters calculated for 6572 is before 8437. Meaning you have two sections
eefl and ing
You can take only get two words from these two sections. Feeling and Fleeing.
>>
>>52928476
>boolean equalDog;
You don't need this, it's clearer and more concise to just return true; } else { return false; }

It doens't really matter of course but just for future reference.
>>
>>52928500

Ah, didn't know I could do that, thanks
>>
>>52928190
>5) Null for new word and double null for new sentence
so 4 (8) bytes of separation?
>>
>>52928190
This is retarded.
>>
>>52928536
You can even do
return (weight == dog.getWeight() && height == dog.getHeighty());

But in this case I think it lessens readability.
>>
>>52928476
return weight==dog.getWeight() && height==dog.getHeight();

Or

You're trolling me. I can't tell.
>>
>>52928611

I just started learning
>>
>>52928476
The reason I mentioned the Java implementation of .equals() is because of a nice shortcut it uses.
It first checks for
if (this == passedObject) 
which compares the object you are calling the method on with the object passed as a param.
That way, if the references do match, you don't even need to check the contents, since they must be identical anyway.

Also it's a good idea to put a null check in your method, may save you a lot of pain later on.
>>
>>52928625

The snippet I posted isn't the full thing, it only checks if there's a Dog in the Kennel if Dog isn't null in the first place, so there shouldn't be any null values to check in the first place afaik
>>
>>52928589
Well I'm using 16 bits for the numbers. So just 2 bytes for a space and 4 bytes for new sentence. I might just make space and new sentence primes by themselves to save space.
What I might do is use substrings as primes as themselves. For example if "fee" is used often in a list of words, i won't use 53*2*2, instead I'll push characters like z up and make fee something like 73
>>
File: sideye.jpg (11 KB, 287x285) Image search: [Google]
sideye.jpg
11 KB, 287x285
>>52928624
don't worry about optimizing your code in this manner when you're learning
>>
>>52928740

I'm not that guy but I need to ask, do you guys often return the evaluation of the expression instead of using if statements as a way of optimizing your code?
>>
>>52928790
>as a way of optimizing your code?
Practically never.

I do it when it improves readability, which is usually when it's something simple like returning either true or false. Sometimes I just return a ternary statement (return 1 == 1 ? true : false;) but lots of people don't like that for readability's sake.
>>
File: Ca8jlVIWcAUmeP8.png (424 KB, 600x650) Image search: [Google]
Ca8jlVIWcAUmeP8.png
424 KB, 600x650
>python used to plot in the gravitational waves discovery paper

where were you when python won?
>>
>>52929003

Python has been used for scientific computing for some time now.
>>
So uh, I feel dumb for not knowing python and knowing so many other languages... What's a good book to read to learn that? Don't mind reading through the whole thing.
>>
>>52929140
You can't learn python. You just write C without the parens and curly braces, then google the thing you need and import it.
>>
>>52929003
Yeah with SciPy and NumPy, C libraries.
>>
>>52929167
https://github.com/scipy/scipy/blob/master/scipy/interpolate/src/_interpolate.cpp
>>
>>52929167
https://github.com/scipy/scipy/blob/master/scipy/fftpack/src/zfft.c
>>
Alright fellas, for the two of you guys that work with C# let's talk LINQ.

Lambda Expressions or Query Sintax?

I just made a little masterpiece using query syntax, but I'm curious about Lambda expression with the "=>" looking so cute and whatnot.

Is it one of those things you can pick one over the other or is it one of those things that each have it's own use?
>>
>>52929160
Really? That simple? I only skimmed through some of it a while ago, it still looked pretty foreign.

I wouldn't mind a book to gloss through, either way...
>>
>>52929140
the python docs, they have lots of documentations, tutorials, etc.
don't ask dpt, there is some "elite computer scientists" ITT who hate python. better ask #python @ freenode.
>>
File: tfw feel 3.jpg (24 KB, 600x238) Image search: [Google]
tfw feel 3.jpg
24 KB, 600x238
i just want to play a .wav and be able to loop it and then make it stop looping in java but i'm too stupid
>>
>>52929250
Meh, alright... I don't plan on using it at all, I mainly write in C and assembly. I just want it under my belt.
>>
>>52929265
http://stackoverflow.com/questions/2416935/how-to-play-wav-files-with-java
https://www.google.com/search?q=java+play+wav&hl=en
>>
>Look at my github.
>It's literally 3 languages: Python, Processing and Js.
Okay volafile, I need to shake it up. Give me a language and give me a project.
>>
File: 1455046201086.gif (2 MB, 360x240) Image search: [Google]
1455046201086.gif
2 MB, 360x240
>>52929267
>I mainly write in C and assembly.
>>
>>52929003
Scientists and programming don't together too well...

Except computer scientists...

..

WAIT
>>
>>52929352
Java interpreter in C#.
>>
>>52929352

Linux kernel in haskell.
>>
>>52929355
I can't RE applications with Java or C# :/

I guess I'll search google for a book on Python, then.
>>
>>52929352
i can't give you a project that you'll enjoy for sure but a good way to find a project is to see what you wish you had when working on code to help you simplify your life
think simple build systems or code generation tools, maybe just a git plugin to help you do some simple task, or whatever will help you out

for languages, try learning something you haven't used anything like before so that you can expand your knowledge of programming to not only different languages but also different types of programming. maybe learn something lower level (C, Rust, C++, D).
>>
>>52929338
you know as well as i do that i already googled it, so logically it follows that you're just trying to be snobby
>>
>>52929434
If you already know how to code in one language, the best way to learn a different language is to literally do what I said here: >>52929160

Just pick a project, use python and do it.
>>
>>52929511
I don't even want to, though. I just want to have the knowledge of it for the future. I really, really don't mind enjoying a big ol' book.
>>
I'm working on the number to text converter at 89 here >>52927429
and I had a small question. Which of these two forms of sorting teen and uniquely named numbers is considered more correct?

if num < 20:
if num < 13:
# unique numbers from 1 - 12
else:
# numbers ending in teen
else:
# other numbers

# OR

if num < 13:
# unique numbers from 1 - 12

elif num < 20:
# numbers ending in teen

else:
# other numbers

The first seems to avoid an unnecessary check if num > 20, but the second seems more readable and might reduce overall complexity in larger checks.
>>
>>52929355

I do 90% of my programming in C, C++, and Ruby, and just sort of dabble in everything else. I can do Java, C#, Python, whatever, but I'll be rusty at any of them, because I don't use them for much.

>>52929352

Java and Bash. Take either Linux Deploy, Lil' Debi, or any other Android chroot application, and make them stop being broken as fuck on Lollipop and above. Termux is suffering.
>>
>>52929580
The second is more readable, and actually better, however you need to change one thing. Your checks should go in the order of num > 20, num > 13, else. The reason is that you want to optimize for the statistically most likely option, and num > 20 covers 80% of your numbers. So for 80% of your calls to this function you'll only need the first if check.

In any case, optimizing for performance at this level is really not that important. Write for readability ONLY. Run the program. If it's too slow for your liking then start looking at optimizations.
>>
Does your gf program with you?
>>
Give me some algorithmic interview questions.
>>
>>52929684
Reverse a binary tree
>>
File: jo8inmkj.jpg (57 KB, 667x420) Image search: [Google]
jo8inmkj.jpg
57 KB, 667x420
I've been trying to figure out how to not get negative numbers for my subtraction of times. It has to be read in (hours, minutes, seconds)

>I'm not allowed to convert to seconds and redistribute
>I'm not allowed to use if/else statements (that would make it "too easy")

I've been working on it for an hour and I still keep getting negative numbers when I subtract times. I've no idea what to do.
>>
>>52929582

That's acceptable because C++ and Ruby are modern. C and ASM are not.
>>
>>52929684
traveling prostitute problem
what is the shortest distance between several locations when you need to hit them all and then return to home?
>>
>>52929676
My right hand, yes.

>>52929684
Write a depth first search of a weighted, directed graph.
>>
>>52929710

Use a 24 hour time system?
>>
>>52929690
B-but I just did that one.
void reverse(struct Node *tree) {
if( tree->left )
reverse( tree->left);
if( tree->right )
reverse( tree->right);
struct Node *tmp = tree->right;
tree->right = tree->left;
tree->left = tmp;
}
>>
File: cooper.jpg (137 KB, 500x374) Image search: [Google]
cooper.jpg
137 KB, 500x374
>>52929672
Clever, I'll remember that.

I get that optimisation isn't always necessary, even while working with micro-controllers, but when pretty code is the difference between getting a job and not, I'm going to learn all I can.
>>
>>52929729

Can't do that either. Has to be a 12 hour system because "murica".
>>
>>52929731
reverse a binary tree without mutation.
>>
>algorithm is patented with C code
>use it anyway in closed-source software
>nobody will ever fucking know
I just don't understand software patents

what about
>implement it in the same language, in an open-source program
>reverse the order of the arguments
does this mean you can use it?
>>
File: wtf_jpg.png (10 KB, 528x528) Image search: [Google]
wtf_jpg.png
10 KB, 528x528
can someone tell me why this doesn't output the info in 3 columns but instead looks like pic related.

while (index < SIZE && names[index] != "No Value")
{
// Create a 16 character column and output the contact names
cout << setw(16) << names[index];

// Create a 20 character column and output the contact addresses
cout << setw(20) << address[index] << endl;

//create a 10 character column and output the contact phoneNumbers
cout << setw(10) << phoneNum[index] << endl;

index++;
}
>>
>>52929501
what's the problem, then? you could have started from there...
>>
>>52929710
>sec6
>min6
I assume this means you have sec1, sec2, sec3... etc? How horrifying...
You need to use division. If you subtract 61 seconds, you want to subtract 61/60 (rounded to 1) minutes.
>>
do you people like this music?
https://youtu.be/PoZSJ6q5j_s

>>52929785
remove the 1st endl?
endl, I assume, means "end line"
>>
>>52929785
>C++
>iostreams
>5 (fucking five what the fuck) spaces for tabs
>weird GNU-ish extra indent level for braces
>>
Why is this woking
#!/bin/bash
check=$( xset -q | grep timeout | cut -c 13-15 )
if [ $check = "600" ]; then
xset s 6 &
notify-send -t 3000 -i weather-clear-night 'Display OFF' &
else
xset s default &
sleep 1s && notify-send -t 3000 -i weather-clear 'Display ON' &
fi


and this isn't
#!/bin/bash
check=$( rfkill list | sed -n '5{p;q}' | cut -c 16-18 )
if ( $check = yes ); then
rfkill unblock wifi
else
notify-send fuckyou
fi
>>
>>52929803
>>52929803
Well I needed to take first seconds entered and add it to second seconds entered, then get the remainder and carry it into minutes to add to minute 1 and 2, etc. Then make new integers for the subtraction part.

>you need to use division
is that not what I'm doing in the temp integers? to carry the rest of the seconds? I'm trying to make sure that if hr,min,sec is negative, it becomes zero without using if statements.
>>
>>52929869
>$check = yes
Is yes supposed to be a string?
So
$check = "yes"
>>
>>52929832
That worked, for some reason I didn't see that and I kind of copied a program that was meant for something else and just modified it to do what I needed for this assignment
>>52929853
that's mostly cause I copy pasted an existing code provided from the class im taking and modified it to do what I needed it to do and I don't feel like putting much effort into making it look pretty
>>
first for keygen
https://www.youtube.com/watch?v=c17k4LfLkaE
>>
>>52929879
>I'm trying to make sure that if hr,min,sec is negative, it becomes zero without using if statements.
This doesn't sound right. If you have 2 minute and 0 seconds, subtracting 1 second should give 1 minutes and 59 seconds.
>>
>>52929956
>first for keygen
also last for keygen
>>
>>52929969
I'm not sure how to do this without using an if statement though.
>>
>>52929992
I can't do it off the top of my head, but it's definitely possible using a combination of modulo and division. I'm too lazy to get a pen and paper and figure it out, so I'll leave that to you. Do it on paper but make sure you go step by step, figure out how you would do it in one case (like 2 minutes minus 1 second), then check if the same procedure works for other numbers and if it does, you've got yourself an algorithm.
>>
in java: i see people do stuff like
 f = new File("c:/java test.txt"); 
to create a new file. but what if i just know the file is in the same location as the .classpath, bin, src, etc, and i know the file name? how do i do it then?
>>
>>52930049
I literally copy pasted your post into google and got this thread which has the answer:
http://www.java-forums.org/eclipse/24008-file-handling-problem.html

However for a better, more direct answer:
http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java
>>
>>52930099
will my application always initialize there?
>>
>>52930126
The second answer, i.e.
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + s);

Will always get the path from which your program was launched.
>>
is it possible to make basic audio plugins or vsts with something like python?
>>
>>52929777
if it's something like video compression, they can tell even if it's closed-source
>>
>>52929910
yes but it returns a row of infinite = yes
>>
>Tfw I have mastered programming practice problems but I am too scared by starting my own programming projects
>>
>>52930189
fill the algorithm with some function calls. The signature no longer matches. Profit.
>>
>>52930189
yeah but no one needs to reimplement already-available video compression
I'm talking about shit like the averaging two ints code someone mentioned earlier, which is apparently patented
>>
>>52930449

Feel free to do it, but don't come crying to us when the FBI are rappelling down into your bedroom.
>>
>>52930170
alright, thanks man
>>
>>52930503
>but don't come crying to us when the FBI are rappelling down into your bedroom.
Oh shit, I already used that averaging code in the kernel to my OS. Should I buy a dildo so I can stretch my anus on my own terms?
>>
>>52927727

When you see those red squiggles it means that there is a missing library missing in that file. Also in the Animating method there is a typo when you are using the second float.

instead of
void Animating(float h, float, v) {...}
it should be
void Animating(float h, float v) { ... }
>>
>>52927727
You need to add this to the top of your script:
using UnityEngine;
>>
I really fucking do despise checked exceptions. Thank you based Hejlsberg for not forcing them on me.
>>
>>52930556
>>52930605
Ive got it all working after restarting and rewriting the whole thing again
I thought the red Squigles was just it not regestering in the english language like any other problem
>>
>>52930610
> Not programming in glorious Java

Pleb
>>
>>52930650

C# is Java: The Good Version, imo.
>>
>>52930170
how do i append the name of my file to that? right now i have
         Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
s += "\TitleTheme.wav";
and it's telling me invalid escape character because of the \. the full section of my code is
        Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
s += "\TitleTheme.wav";


try {
File mainTheme = new File(s);
AudioInputStream stream;
AudioFormat format;
DataLine.Info info;
Clip clip;

stream = AudioSystem.getAudioInputStream(mainTheme);
format = stream.getFormat();
info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
}
catch (Exception e) {
// do something i guess
}
>>
File: Capture.png (23 KB, 707x573) Image search: [Google]
Capture.png
23 KB, 707x573
Anyone know of a way to change the input/output prompts (the
In[1]:=
,
Out[1]:=
things) in Mathematica's CLI? Long story short class I'm taking allows the use of Matlab on exams but no other programs and I want to disguise my use of it.
>>
>>52930659
Java is better for real men who can actually program and who actually want to make real money
>>
>>52930678

Right, and I'm the queen of England.
>>
>>52930671
>and it's telling me invalid escape character because of the \
Yeah to insert a \ you need \\
>>
File: shit.png (20 KB, 626x603) Image search: [Google]
shit.png
20 KB, 626x603
First year comp sci student here, Ive already got a few years of C++ experience so I decided to do extra on my homework

also >single threaded always runs faster than multithreaded on my laptop's i7
why is this???
>>
>>52930710
>literally memeing in your programs
get a fucking life dude
>>
>>52930704
alright thanks i made the change you gave me and it solved that but i'm getting an exception thrown. can you see where i'm going wrong?
>>
>>52930710

Because multi-threading is complicated and doesn't guarantee a speed increase.
>>
>>52930710
my guess is the overhead of creating the threads is more expensive than the parallelism benefit.

try a more expensive problem.
>>
>>52930710
>>single threaded always runs faster than multithreaded on my laptop's i7
>why is this???
I'm guessing
>Overhead from actually creating the threads is greater than the speed benefits. Try more complicated multi-threaded problems.
>I don't know if Java puts locks around stuff and maybe it's not as multithreaded as you think? Unlikely, though.
>Green threads
>I don't know otherwise
>>
>>52930739
Do this and tell me more about the exception:

catch (Exception e) {
e.printStackTrace();
}
>>
>>52930736
thats not even the worst part. i've had to remove this part after some really harsh feedback

        // Pretend we are loading some slow Java stuff
for (int i = 0; i < 8; i++)
{
if ((i == 0) || (i == 4))
{
// Clear the line
console.printf("\r ");

console.printf("\rStarting multithreaded Sums of Multiples Calculator program");

}
else
{
console.printf(".");
}

try
{
Thread.sleep(2000 / Runtime.getRuntime().availableProcessors()); // Just for laughs
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
>>
Is there a way to preload images to a web page to reduce load times? I am tasked to load a huge amount of images onto the page, but I am given lots of restrictions by my team lead.

I cannot:
> Lazy Load
> Use Local or Session storage
> Use multiple AJAX calls and memoize
> Use zip and extract on the page

I can only think of having the server cache images in CSS and then extract the background image on the page load. I'm pretty sure this is also a bad hack. Is there any good performance techniques /g/ knows about.
>>
>>52930795
Can't HTTP headers hint the browser to cache them?
>>
>>52930795
For a project I did I converted the image to base64 and embedded it into the css.
>>
>>52930782
java.io.FileNotFoundException: C:\Users\Dell\workspace\TrumpQuest\TitleTheme.wav (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at general.GameStart.main(GameStart.java:40)

thanks for helping man
>>
>>52930671
[catch (Exception e) {
// do something i guess
}[/code]
yikes
>>
>>52930863
>>52930782
holy shit

it was the space btw

but it's working now

it's playing an 8 bit song i made myself. this is amazing i'm pissing my pants right now. i feel like an actual game developer
>>
>>52930863
>java.io.FileNotFoundException: C:\Users\Dell\workspace\TrumpQuest\TitleTheme.wav (The system cannot find the file specified)

Well, there you go.
>>
Hi, guys I am new to programming and I was wondering which programming language should I start with first. I was recommended by my professor to start with the HTML programming language
>>
>>52930885
Start with C++ if you can handle it
>>
>>52930863
>java.io.FileNotFoundException: C:\Users\Dell\workspace\TrumpQuest\TitleTheme.wav
Just to verify, that's the path you loaded the program from right?
Anyway it can't find the file "TitleTheme.wav" so double check your spellings and such.

By the way, this is why you never leave the catch block empty, like I mentioned here: >>52928358
>>
>>52930885
I recommend the json programing language.
>>
>>52930885
the csv programing language is really popular
>>
>>52930885
i think you should start with C++. with java it's really tempting to use an IDE but it auto-corrects stuff a little too much for a new person in my opinion
>>
>>52930792
Post the entire spec so I can also do this. I feel like writing some C.
>>
>>52930833

I will need to check if that is viable. I believe you are correct the header will handle caching, but I am not sure if it may work before hitting the page. I will check that out.

>>52930853

I had no idea that was possible. I will bring that up at stand up.
>>
>>52930933
https://css-tricks.com/data-uris/
>>
>>52926863
5 cows, 1 pig, 94 chickens
>>52926934
there's actually only one solution that doesn't involve negative or fractional animals.
>>
>>52930710
>also >single threaded always runs faster than multithreaded on my laptop's i7
another guess: because your CPU runs at a higher frequency when running single thread applications. try monitoring it...
>>
>>52930957

Thanks. <3
>>
>>52930959
10 cows is $100
9 cows, 3 pigs and 2 chickens is $100
You are wrong QED.
>>
>>52930710
Multithreading is only ideal for big applications really
>>
>>52930987
he bought 100 animals
>>
>>52930987
10 != 100
14 != 100
Read the problem again.
>>
>>52931015
>>52931021
You're right, my bad.
>>
Learning C, just have a quick question.

So I'm running Sublime Text 3 in Ubuntu. When I compile my program, the Fahrenheit to Celsius converter in The C Programming Language 2nd edition, it makes an executable of course. However, it shows up in Sublime, which I don't want, so I hid it. However, what the hell is going on in that file? It's like a bunch of random numbers and letters and 0's and shit.
>>
>>52931216
you really don't know what an EXE is?

this is b8
>>
>>52931216
https://en.wikipedia.org/wiki/Binary_file
>>
>>52931216
you have to read about the ELF file format... google it. btw, if you learn assembly, it'll become relatively easier to learn it.

>>52931239
>Ubuntu
>EXE
>>
>>52931048

Same.
>>
Dunno If this thread is best or sqt is better for this question but I figured you guys would know better.

I have a Java array of Point (basically an array of objects). I want to store this array in an SQL database, which I can do using a blob. My problem is getting this array back out. There seems to be no way of converting the blob back into an object array, only a byte array (which also cannot be converted into an object array).

I reckon I'm trying to do something that can't be done, it's just that this is the best method because I need to be able to retrieve the array specific to a username (which a database seems best for as files would get messy).
>>
File: img2html.png (109 KB, 959x841) Image search: [Google]
img2html.png
109 KB, 959x841
>tfw you're so bored you write an image to html converter
>>
>>52931319
You need to make Point implement Serializable. What you are looking for is called data serialization.
>>
File: smallptfont.png (133 KB, 1045x780) Image search: [Google]
smallptfont.png
133 KB, 1045x780
With small pt font, this thing actually gets a pretty good result. That said, the result is 2mb worth of HTML.
>>
File: contempt.jpg (30 KB, 524x336) Image search: [Google]
contempt.jpg
30 KB, 524x336
>>52930890
>recommending Sepples
>>
File: pic2.png (1 MB, 1178x615) Image search: [Google]
pic2.png
1 MB, 1178x615
22 god damned megabytes of html. 2pt font.
>>
>>52931319
that is not the correct way to use sql
>>
>>52929199
I've always found the lambda syntax to be clearer than the query syntax.
>>
>>52931815
neat! how does it work? something like
for pixel in image: 
print(<span style="...">O</span>
...
>>
>>52932121

Essentially, except it's in C#.
>>
>>52932143
post code
>>
should I learn C if I plan on learning C++ and Java?
>>
>>52927727
string indexed axises instead of using enumeration
what the fuck unity
>>
>>52931723
You probably prefer java, tard
>>
>>52932273
Learn C++. Write C later. Why?

>C++ is just C with classes!
AVOID THINKING THIS SHIT

http://programmers.stackexchange.com/questions/48401/learning-c-properly-not-c-with-classes
>>
>>52932351
So should I start with a highly recommended book (C++ Primer 5th Edition as an example) or use online resources? If online resources, which do you think are the best to start with?
>>
*p++ is *(p++)

what is ++*p? ++(*p)?
>>
>>52932437
https://stackoverflow.com/questions/18481740/pointer-expressions-ptr-ptr-and-ptr
>>
>>52932351

>C++ is just C with classes!
The fact that proper C++ is not written at all like C is why I recommend C first. You learn what programming is like without the abstractions, and then you learn what abstractions are available, and what they're doing under the hood. As opposed to learning C++ first, and learning how to program it like C first because you need to learn how raw pointers are before you learn what a smart pointer is and why the fuck it works. If your first experience with C++ is with all of the C parts, you might think that's how it's supposed to be programmed. But if you learn C first and then C++ second as a completely different language, you already know the C parts and can approach C++ completely differently.
>>
>>52932483
cool thx
>>
>>52930795
Use HTTP2
>>
>>52926571
you should only color the background for the innermost paren group that encompasses the cursor, and just the font itself for the rest
>>
>>52926756
nice subtle gc joke
>>
>>52926792
when i figured out that writing an emulator is pretty simple, then i started writing a lot of VMs and interpreters/compilers.
>>
>>52927078
>no benchmarks
You fucked up, anon.
Thread replies: 255
Thread images: 28

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.