/dpt/ - Daily Programming Thread

What have you been working on, Sup Forums?


Previous:

Other urls found in this thread:

raw.githubusercontent.com/google/code-prettify/master/src/lang-lua.js
msdn.microsoft.com/en-us/library/windows/desktop/dd319331(v=vs.85).aspx
en.wikipedia.org/wiki/Range_of_a_projectile
formulas.tutorvista.com/physics/projectile-motion-formula.html?view=simple
wolframalpha.com/input/?i=y² = -x + 20
yourlogicalfallacyis.com/special-pleading
en.wikipedia.org/wiki/Euler_method
twitter.com/SFWRedditImages

Which looks better to you?

Which looks better to you?
int sort_freq(const void *a, const void *b)
{
struct freq *x = (struct freq *)a;
struct freq *y = (struct freq *)b;
return x->count - y->count;
/* ~~~ */
return (*(struct freq *)a).count - (*(struct freq *)b).count;
}

the first one looks better and is easier to debug because you can add or remove code around it.

Trying to improve. Feedback?
local lines = { -- would normally be accepted as arguments
{
{x = 1, y = 1}, -- point 1
{x = 7, y = 3}, -- point 2
},
{
{x = 2, y = 6},
{x = 5, y = 0}
}
}

for i, line in pairs(lines) do
line.m = (line[2].y - line[1].y) / (line[2].x - line[1].x) -- slope (m)
line.b = line[1].y - (line.m * line[1].x) -- y-intercept (b)
end

local intX = (lines[2].b - lines[1].b) / (lines[1].m - lines[2].m) -- intersection point x value
local intY = (lines[1].m * intX) + lines[1].b -- intersection point y value

print("The lines intersect at (" .. intX .. ", " .. intY .. ").")

"--" indicates a comment which Sup Forums doesn't recognize as a comment, just to clear that up

>Implying /dpt/ is tech illiterate
First time projecting this right

iirc lua is the only language to do this, so it might not be obvious

Haskell uses --, and everyone in /dpt/ knows Haskell.

>projecting
Haha so you're tech illiterate.
Or was this a joke?

To produce the things you want and not the things the 'best' people want.

There's also no clear rules for who's the worst or who's the best.
But you can of course be fairly certain you're not either.

>Github: Major Service Outage
REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

This is why you self host and mirror to bitbucket.
Github.com removed the fun joke Sup Forums made remember?

>everyone in /dpt/ knows Haskell
wrong

I am the best in my little zone of influence, though.

I'm intimately familiar with my company's network and all of the databases, as well as how to access the various APIs of web services we use. I know our server IP addresses by heart, as well as credentials.

I know our larger code-bases like the back of my hand and am able to fix things quite quickly because I'm familiar with those clusterfucks.

Currently, no one else in the world can serve my purpose quite as well as me, and it would take them some time to learn our business needs, our infrastructure, our data, and how to communicate in our odd culture.

Ada does as well

Also the script behind the code blocks is fully capable of language-specific syntax highlighting, just moot/gookmoot are too lazy to add something like [ code=lua ]

Aside from a given language and "soft skills" (ie, not being an aspie), what should someone looking to go into software development be proficient in? Git? Agile/TDD/other? Scripting languages? How proficient in a given scripting language?

>To produce the things you want
Then shouldn't programming be seen as art instead of science?

Also, I think if you're not ahead you're an hindrance.

How to use the industry-standard IDE for your language and its metaprogramming features.

Good networking knowledge.

SQL.

Also, there's a metric fuckton of soft skills that are really goddamn important, like how to write an email to a client or coworker with the correct tone and specific information.

>Then shouldn't programming be seen as art instead of science?
it is

Is there any OOP language to program closest to bare metal but not C++?
Rust and Go are not applied.

Yes programming is a craft. Not a science. Doesn't matter what computer scientists think about it because we work with a canvas (hardware) and real world constraints (input latency and all kinds of stuff). We don't use some computation ether to run our theoretical time complexity algorithms.

It's a sick view which luckily not all computer scientists hold but the less experienced ones are prone to.

D

>close to bare metal
>a mental model based on a hypothetical abstracted reality meant to fit the programming ideals of people who didn't give a shit about actual software
Choose one and only one.
OOP is not compatible with low level programming or even well performing programs outside of trivial examples.
Also the guy who made up OOP doesn't think C++ is OOP iirc. So maybe you're not even close there.

Testy fjdhdhdh

Ada has a powerful facilities for embedded systems.

objective pascal
there's might be OOP in the C derivates that aim for parallelism like chapel and such.

C

regarding The highlight script is Google's prettify, so you can just add this module:
raw.githubusercontent.com/google/code-prettify/master/src/lang-lua.js

then change the class of the HTML generated from the code tag from "prettyprint" to "prettyprint lang-lua"

and do PR.prettyPrint() to refresh

>OOP is not compatible with low level programming
I meant as close as possible.
Let's say, Java isn't a variant (if it's not some Java CPU, lol) to be closest to the bare metal.
But still, aren't objects just structs packed with functions and unreachable internal variables?
If not, what's a good language to practice actual OOP?

Is there a way to "fix" this? What about haskell?
I'm guessing the CS field to be too modern/hyped thus not having sufficient time to get the benefits of hindsight. I hope it changes for the better

does haskell even have a weighted graph package? i'm trying to do dijkstra in it and i think i'm going to have to make my own

How can I dynamically determine information about the environment my programs run on?

Things such as processor, supported instruction sets, operating system, system calls, etc

>does haskell even have X
no

Depends on the language, but there's probably a library for it

How are those libraries implemented?

>objective
not a typo?

Low level programming means you care about the operations and data representation of the machine to some extent. It's a fussy line. OOP's goal is entirely counter to that.

The closest to a compromise that seems OK to me is C++ or D. Where D is clearly preferred as a language (but available tools are lacking).
>a good language to practice actual OOP
Now I'll draw a clear distinction. Now we're talking not low level languages. OCaml and scala are the two you'd consider primary contenders.
Some people really like the idea of UML. And I can see how from a pure OOP standpoint they'd be very good at this. The representation and presentation seems superb. It jives very well with the philosophy of OOP people. And is very suitable for OOP programmers.

If I were you, and you're set on OOP, I'd learn UML and make programs using it as much as possible. Usually it doesn't compile straight to binary but you have to specify small portions (the 'implementation') of the program in another language. Pick whatever you find is suitable. Then eventually move on to programming languages designed around OOP thought like the examples given.

I'd imagine if you just want to get hired to an OOP position you'd just learn to use C++ or java though. Probably java. I'm not sure.

Why is C so shit?

You shouldn't have say that. Now I know that you're a code monkey.

Not sure we want them to.
There's value in CS as a theoretical subject. Its like how base research may be difficult to digest into technical products (like theory of relativity for GPS) but it's certainly valuable.

My general disgust is from my experiences. Not the practice of CS.

I know Intel has some instructions for their assembly language that you can use to get information about the processor and what instruction sets it can support, so the language could write wrappers around those (I don't know about other architectures). For querying other things I'm not too sure.

Usually through OS api.
For instance
msdn.microsoft.com/en-us/library/windows/desktop/dd319331(v=vs.85).aspx

don't listen to them. they're "code artisans" who program in java and html

Writing a database query, JSON and HTML LRU cache. Trying not to produce mutex soup.

Well java and html obviously aren't platform specific as imply programmers do.
Stop being retarded.

making a little game

the spider at th bottom (pic. rel) travels the distance deltaY with an animation

this works fine

but now I want to make it jump vertically in a parabola motion (purple arrow in pic rel)

how would you calculate the formula for that parabola if he is at position x=30 and if y movement is deltaY ?

I don't get how classes work.
how do you make a class for something like this in java? christ self-teaching is shit
public class FractionClient
{
public static void main( String [] args )
{
Fraction r1 = new Fraction( 2, 3 );
Fraction r2 = new Fraction( 5, 7 );

System.out.println( "The numerator of fraction #1 is " + r1.getNumerator( ) );
System.out.println( "The denominator of fraction #1 is " + r1.getDenominator( ) );

System.out.println( "\nFraction #2 is " + r2.toString( ) + "\n" );

if ( r1.equals( r2 ) )
System.out.println( "Original fraction #1 and #2 are identical" );
else
System.out.println( "Original fraction #1 and #2 are different" );

r2.setNumerator( 2 );
System.out.println( "\nSetting denominator of fraction #2 to 0\n" );
r2.setDenominator( 0 );
System.out.println( "\nSetting denominator of fraction #2 to 3\n" );
r2.setDenominator( 3 );

if ( r1.equals( r2 ) )
System.out.println( "Original fraction #1 and modified fraction #2 are identical" );
else
System.out.println( "Original fraction #1 and modified fraction #2 are different" );

}
}

there's no purple on that pic
also can't you just use sine/cosine with variable radius overtime

en.wikipedia.org/wiki/Range_of_a_projectile

How would I read the longest and shortest string/word out of a .txt file using java?

I got

import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class WordData
{
public static void main (String [] args) throws IOException
{
File inputFile = new File ("words.txt");
Scanner scan = new Scanner (inputFile);

while (scan.hasNext())
{
word=scan.nextString();

System.out.println("The longest word is" + )
System.out.println("The shortest word is" + )

forgot to add the arc span
parabola goes from (30,0) -> (250, deltaY/2) -> (30,deltaY)
pic rel

looking for formula

A parabola rotated 90 degrees is not mathematically a function.

formulas.tutorvista.com/physics/projectile-motion-formula.html?view=simple
Just rotate this.

>A parabola rotated 90 degrees is not mathematically a function.
Nice meme:
wolframalpha.com/input/?i=y² = -x + 20

What are some language features you just recently discovered?

>mfw struct copy in C

Anyone ever make a web scraper? I'm making one now for craigslist using node and cheerio. So far I've got it making objects for every listing on the page, gonna be making a word matching function now to determine if the individual listing matches one of my target items

s => {
const w = s.split(" ").sort((a, b) =>
a.length - b.length)
return [w[0], w[w.length - 1]]
}

That's not a function. A function is in the format of f(x) = x

>node

It is, if the domain is the y-axis instead of the x-axis.

But the y-axis is the range, not the domain.

>What have you been working on, Sup Forums?
doing homework in python atm.
Seems to work. Now just gotta make it pretty

Please don't use an anime picture next time

yourlogicalfallacyis.com/special-pleading

task was pic related with euler method
en.wikipedia.org/wiki/Euler_method

n should be 10^1, 10^2, 10^3, 10^4, 10^5

I just plotted the graphs for 10^1 and 10^5

/dpt/ am I making a huge mistake by using a template cover letter for every job application and going in bulk, or should I only send out a few applications but personalize each one?

I feel like I do better when I have a chance to show off my wit, but I can't be sure

It's not like anime picture is used for OP.

2017 is almos tupon us, programming anime soon

anyone here tried devving with electron?
i dont really like JS or the webstack in general but i wanna see why a lot of big companies are jumping onto the bandwagon

Electron is terrible, it's stupid slow.
Unless you're already knee-deep in webdev shit, it has no redeeming quality

The whole idea is that you have this entire industry full of millennials who only know ruby and javascript, so they started writing desktop applications wrapped around a web browser (chromium).
This has the added benefit of being highly portable without needing to bog yourself down with a native framework, like Qt, gtk or SDL2.

Javascript has no business being used as anything other than interactivity on websites, I can't even imagine writing a whole application in it.

>Javascript has no business being used as anything other than interactivity on websites
Wrong.

Electron is web designers meming about being programmers. Ignore and avoid.
>why a lot of big companies are jumping onto the bandwagon
Because it's a bandwagon. Managers want to be hip and trendy.

REMINDER that JAVASCRIPT is NOT programming, it is NOT used by programmers to make REAL programs

why?

>I can't even imagine writing a whole application in it
It's Hell.

hi aspie, forgot to make your meds?

>What have you been working on, Sup Forums?
I cracked expensive (5-6 digits) software for personal use.

Took me 1 day to write a crack and 2 extra days to realize the reason it wouldn't work even with the crack is I had installed it incorrectly...

They were using a licensing/DRM scheme called FlexNet which was embedded as a library in ~60 different files, so I wrote a patching tool just to apply the crack.

I hadn't really cracked anything serious before, so I'm pretty proud of myself.

Anyone know how I can debug a None type error for my regex in Python?

I've created a script which parses a html doc with Bs4 (Beautiful Soup), there are 112 items I want my regex to match, it matches all of them and after it prints the last one, it throws me a None error and I don't know why. I've added a counter so that each iteration of my for loop, I can count how many times it iterates through the loop and its 112. How do I find out what's cockblocking it?

I'm not looking for help with my code, just how to debug

>Python
>type error
kek

>FlexNet
Is that Solid Edge?

That CLion?

Is there a more efficient/elegant way to clamp in java?

Using x and y instead of [0] [1] for vectors is a bad idea.

why does a clamp function return a boolean

>boolean clamp

wew, euler method is pretty accurate

Nah, I'd rather not say the exact name since AFAIK I'm currently the only source for a cracked version, but basically it's a pretty big systems designing software suite.
The thing is ~5GB installed.

Qt Creator w/ Flat Dark theme.

Because i want to know if it's within the range or not

How so? Vector2s are fine to use surely?

Google has reminded me of the definition of a clamp. What would this be called instead? does it have a name?

>tfw accidentally found an entrypoint to a vulnerability that allowed me to bypass the security of an online game trough IDA and Ollie just because I wanted the sound to be in 44KHz
Felt good for a week, no wonder so many people crack software and create cheats for people, both money and the great successful feeling of breaking trough some companies hard work to create a secure enviroment.

if I copy an object in C++, does it re-run the constructor?

myObject obj(69);
myObject obj2;
obj2 = obj;


I'm writing on my phone so I can't test this

Line two runs the constructor, line 3 runs the assignment operator (operator=).

If you did "myObject obj2(obj)", then it would run the copy constructor only.

ideone

Saddest thing about JS is that it has an absolutely terrible threading model. The language itself is fine but the implementation is botched up.

Node's "async I/O" is really cooperative multithreading. If you use any of the libraries written by these hipsters, you're trusting that they don't suck at programming. You're also forced to segment work into bits and pieces and manually schedule them into the ridiculous single-threaded event loop.

Really, the only thing that's asynchronous is the I/O. Code is still very much synchronous. And they still don't have threading support. Even the browser has somewhat fixed this; v8 has already implemented web workers and is working on being able to send arbitrary javascript data between threads. Node is generally just sitting around while people generate hordes of absolutely unmaintainable code thats either callback hell or continuation-passing style code.

inRange?

How do I create a new line in a Javascript alert?

Also, I notice that Firefox claims to be version 50-something, but navigator.appVersion tells me it's 5. Do I divide by 10 to get the real version number?

This is much better than my withinRange, thanks for the brevity user

>How do I create a new line in a Javascript alert?
You insert an '\n', obviously
Are you a webdev?

I just want to copy the objects state (variables) and not re-run everything