/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

asm.io
mikeos.sourceforge.net/
tannerhelland.com/4660/dithering-eleven-algorithms-source-code/
gist.github.com/LandonPowell/aeacf1f02b49fdb96ba2f7607d5baf27
onlineconversion.com/roman_numerals_advanced.htm
benchmarksgame.alioth.debian.org/u64q/python.html
callbackhell.com/
myredditvideos.com/
twitter.com/AnonBabble

hello where do i learn assembly?

Hey /dpt/ what are your three programming virtues?

What do you have expertise in?

What are you doing right now with your knowledge?

Stallman or Linus?

asm.io
4sMpR060xf.onion

I was looking at this earlier. It's pretty sweet. The games that come with it are even fun.
mikeos.sourceforge.net/

>want to make a fps
>can't model for shit

Really holds me back because i never want to make something that looks like a piece of shit

Trying to think of a way to match colors from a big palette (i.e 24 bit) to their closest color in a smaller palette (i.e 16 colors.) Here's one idea I have:

-have the reduced palette be represented as an array
-have there be a separate array of floating point numbers with as many elements as the palette areay
-for each pixel in the bitmap:
-for each color in the palette array:
-divide the actual pixel color by the current color in the palette array
-if >1, divide 1 by it, so each value is

fizzgen.py
#!/usr/bin/env python2
from __future__ import print_function
import sys
from itertools import compress

bmap = lambda n: reversed(map(lambda x: int(x), bin(n)[2::]))
bindex = lambda n: map(lambda x: ord(x) - 47, compress('0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghujklmno', bmap(n)))
findex = lambda l: [l[v - 1] for v in [i for n in xrange(2**(len(l)-1)+1, 2**(len(l)), 2) for i in bindex(n)]]
pnot = lambda n: '(1-i**{}%{})'.format(n-1, n)
listpnot = lambda n: [pnot(pr(i)) for i in range(1, n-1)]
combos = lambda n, v: ['*'.join(list(compress(listpnot(n), bmap(i)))[-2:]) for i in range(1,2**(n-2)) if sum(bmap(i)) == v]
all = lambda n: [j for i in range(2,n) for j in combos(n, i)]
pr = lambda n: [
3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
293, 307, 311, 313][n]
a = lambda f: lambda n: 0 if n < 1 else f(f)(n//2) + 1 - n % 2
a = a(a)
addit = lambda n, k:len(bin(2**n - 1 + 2**(n-1) - k)) - 1 - a(2**n - 1 + 2**(n-1) - k)
diffs = lambda n: [] if n < 2 else [addit(n-1, i) for i in range(2**(n-2)-1,-1,-1)]
start = lambda n: '[' + ' + '.join(['i*i%3']+[pnot(pr(i))+'*{}'.format(sum(diffs(i+1))) for i in range(1, len(n)-1)] + all(len(n)))+':]'
end = lambda n: '[:' + ' + '.join(['(1-i*i%3)']+[pnot(pr(i)) for i in range(1, len(n))]) + ']'
if __name__ == '__main__':
if len(sys.argv)< 3:
print ("usage: python2 {} N [r0 r1 r2...] \nwhere rZ is a word to replace in fizz buzz manner up to the number N".format(sys.argv[0]))
exit(1)
p = sys.argv[1]
flist = sys.argv[2:]
str = "for i in range(1, {}): print ''.join({}{}{}) or i".format(int(p)+1, findex(flist), start(flist), end(flist))
print (str)

try running fizzgen.py 100 fizz buzz

Then try running python

Just ran in to a theoretical problem. Even though I'm using the OCaml compiler's back end, for certain reasons I'm not able to have types' runtime representations match up (on the bright side, this does make linking to C slightly easier). For example, my list type is not the same as the OCaml list type, so you can't link to a normal OCaml library. There's a few solutions I've come up with, but they all seem very messy. I might still stick with converting core types (i.e. lists and options) to the OCaml representation, but more than likely I'm gonna have to write some boilerplate to convert the values in a lot of different places just to use the normal standard library.
Should I just start from scratch and offer 0 compatibility with the OCaml ecosystem or is it better to use a hacky solution to make the two sort of compatible?

...

It's so ugly it's beautiful I think.

What does this do?

It writes a generic fizz buzz one liner for N primes

baby proof assistant for propositional linear logic

If you absolutely need image clarity, your downsampling is fine. But seriously, dithering is better in almost every single application for a slight loss in image sharpness, you get much much better color quality.

tannerhelland.com/4660/dithering-eleven-algorithms-source-code/

Start with a simple ass prototype. Boxes shooting boxes.

Also get AAA quality games out of your head. You'll never get to make the next CoD, BF, Bioshock, Halo etc. Unless you get part of an actual AAA team.

/dpt/ I'm going to fucking kill a man

I just wanna fucking know if there's over 5 tracks left in my cunting playlist and I get

[script]
Vinter in Hollywood - You Can Play (2009 Tryvann Live Mix)
grep: Vinter: No such file or directory
grep: in: No such file or directory
grep: Hollywood: No such file or directory
grep: You: No such file or directory
grep: Can: No such file or directory
grep: Play: No such file or directory
grep: (2009: No such file or directory
grep: Tryvann: No such file or directory
grep: Live: No such file or directory
grep: Mix): No such file or directory
grep: ": No such file or directory
0
lmao

[/script]

from

[script]
#!/bin/bash

current_track="$( mpc | head -1 )"
echo $current_track
count="$( mpc playlist | grep -A10 \" $current_track \" | wc -l | tr -d '\n' )"
echo $count

if [ "$count" -gt 5 ]
then
echo "kek"
else
echo "lmao"
fi

[/script]

>script

oh fuck me I'm retarded

It appears in my anger, I killed the chances of getting my question answered

#!/bin/bash

current_track="$( mpc | head -1 )"
echo $current_track
count="$( mpc playlist | grep -A10 \" $current_track \" | wc -l | tr -d '\n' )"
echo $count

if [ "$count" -gt 5 ]
then
echo "kek"
else
echo "lmao"
fi

is something really baby-proof if babies just consciously choose not to use it?

>is it baby proof if it protects from babies
yes

so i guess a hot stove top is baby-proof after the first time a baby touches it, eh? just a joke anyway, the idea being that a logical person would be largely unaffected by such a tool, whereas an illogical person (the ideal target for such a tool) just wouldn't use it

YOU HAVE 5 SECONDS /dpt/ BEFORE I WALK DOWN THE STREET AND STAB THE FIRST PERSON I SEE JESUS FUCK WHY ISN'T MY CUNTING CODE WORKING?

WHY IS BASH SPLITTING IT THE FUCK UP?

SHIT MAKES LESS THAN NO SENSE

>bash
You get what you deserve

Can anyone recommend any ASM tutorials, specifically for NASM?

I fucking hate it so much but I hate that I don't know it

Practice, iterate, get better over time.

Realize you'll need to constrain and engineer your projects unless you're working with other people. Unfortunate, but it's true.

Don't escape those quotation marks in grep.
It's causing bash to hand the arguments in like
grep -A10 "\"Vinter" "in" "Hollywood" "...\""
It should be
count=$( mpc playlist | grep -A10 "$current_track" | wc -l | tr -d '\n' )

Today I am learning to one page app.

If there was someway to verify that you posted that I would drop I phat sum in your paypal

Thanks babe

Stop programming. This simply isn't the field for you.

>Hardcoded list of primes
>Entirely unreadable golphfaggotry
>Abuse of anonymous functions
>Uses exit instead of an else

gist.github.com/LandonPowell/aeacf1f02b49fdb96ba2f7607d5baf27

from sys import argv

def testPrime(num):
for x in range(2, num):
if num % x == 0: return False
return True

def generatePrimes(words):
i = 2
x = []
while len(x) < len(words):
i += 1
if testPrime(i): x += [(words[len(x)], i)]
return x

if __name__ == "__main__":
if len(argv) < 3:
print "FizzGen requires at least 2 arguments. An int, and some strings."
rangeLimit = 100
primes = [("Fizz", 3), ("Buzz", 5), ("Bar", 7)]
else:
rangeLimit = int(argv[1]) + 1
primes = generatePrimes(argv[2:])

for number in range(1, rangeLimit):
print ''.join([
string
for string, prime in primes
if number % prime == 0 ]) or number

>def testPrime(num):
> for x in range(2, num):
> if num % x == 0: return False
> return True
Jesus Christ, how inefficient.
It also return true for 1, 0 and all negative numbers.

I hope you are using reflex and reflex-dom with GHCJS

Sure am not. What are they?

>[("Fizz", 3), ("Buzz", 5), ("Bar", 7)]
>what are dictionaries

>confusing an abstract data structure with its implementation

It's a shitty implementation, that's what I'm saying.

There are three elements you faggot, a binary tree would be even slower if it were stored contiguously

If the list of pairs were stored contiguously, that is

>Writes something in the slowest language imaginable
>Claims to care about performance

>it'll return true for 1 or 0 and all negative numbers
Apparently you can't into Python. No number under 3 will ever be fed to the function.

That's the most readable version of the code, and I don't micro optimize if it harms readability.

Go ahead and replace it with a dictionary and see what happens.
>iterating over a dictionary
>being this programming illiterate

If you use .iteritems() on a dictionary, it reverses all of it's elements and you can't use [::-1] to turn it back the right way. The order counts in this scenario, so I'm using a list.

He didn't write it. I did. He's just not entirely retarded.
>durr change this thing
>There is no advantage to changing that thing and in fact it's harmful.
>DURR IF YOU CARED ABOUT ADVANTAGES WHY DIDNT U USE A DIFFERENT LANGUAGE HUH????
Python isn't the slowest language imaginable. Go read some benchmarks.

>>writes something in the slowest language imaginable
>you should make it slower

>needing to iterate at all
>getting keys and values mixed up

>micro optimize
You can reduce the number of comparisons massively with even the most trivial optimisations.
Stop using that stupid buzzword.
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
for (int i = 3; i < ceil(sqrt(n)); i += 2)
if (n % i == 0)
return false;
return true;

I'm saying that anybody who even slightly cares about performance wouldn't be using the meme snake at all.

>i < ceil(sqrt(n))
Whoops, I mean

>hair splitting about performance in a fucking fizzbuzz in le meme snek
>muh micro optimizations

>Go read some benchmarks
Reading the benchmarks of some library that is implemented in C is not a Python benchmark.

Keys and values don't get mixed up. I don't know what you're on about.

Go run the code with your changes and repost it when you're done. I'll wait.

>Needing to iterate at all.
It's a FizzBuzz. If you can show me a way that doesn't involve some iteration or abstraction of iteration, I'll be impressed, but it'll still be useless and I'll still iterate because it's more readable.

>That first conditional
No need for it, since the function never receives less than a three.
>That second conditional
Top fucking kek. Are you literally retarded?
There will never be a time in which my function will evaluate that to True. Ever. Even if you just change it to 'return False', it becomes a useless conditional for one very specific prime number which gets evaluated my way anyways.

The for loop is useful, but it's an optimization that harms readability, and I don't give that much of a shit about performance on a shitpost when it harms the readability of my shitpost.

>implying I'm hair splitting about performance
You sure you meant to reply to me?

I don't use Python, I'm not him, I was simply attacking this dictionary nonsense

Stupid question:

How do you use jQuery to change an inputted number using a JS function and output it in the same box that it was inputted?

Kind of like this converter: onlineconversion.com/roman_numerals_advanced.htm

I know how to set everything up, the converter function too, except how to apply it so it outputs the value in the same space.

>Hey guys, I'm going to compare interpreted languages to compiled languages and pretend like I'm cool on the internet.
You're making a fool of yourself. Don't call Python the slowest language and then forget to include every interpreted language in your list of languages that aren't Python.

benchmarksgame.alioth.debian.org/u64q/python.html

>>it'll return true for 1 or 0 and all negative numbers
>Apparently you can't into Python. No number under 3 will ever be fed to the function.
>That's the most readable version of the code, and I don't micro optimize if it harms readability.

. . . . . . . . . . . . . . .
. . . . . . S . λ . . . . . .
. S . L . . T Y P I N G . . .
. U . L . . A . ω . . . . . .
. L . A . . T . . . . . . . .
. U . R E F I N E M E N T . .
. C . O . . C . . . . . Y . .
. L . F . . . . . . . . P I .
. A . . . P . . . . . . E . .
. C O N T R U C T I O N S . .
. . F . . O . . H . . . . S .
. . . . . D E P E N D A N T .
. Y F I N U . . O . . D . R .
. . . . . C . . R . . T T O H
. . . . . . . . Y . . . . N .
. . . . . . . . . . T D A G .
. . . . . . . . . . . . . . .

>No need for it, since the function never receives less than a three.
I was presenting the totally correct solution. It's a function which has utility in other programs.
>The for loop is useful, but it's an optimization that harms readability
How the fuck is a nested function call hurting readability?
Also, this optimisation literally removes over half of the comparisons required. Even if it actually had an effect on readability, it would certainly be worth it.
You clearly have fucked up priorities.

Making a next generation UI, figuring out how to build a client-side microservice architecture, and generally working towards bringing about the singularity.

All in a day's work when I actually get shit done instead of dick around and make mad money playing markets.

building reports. boring.
$(document).ready(function(){
$.ajax({
method: "GET",
url: "yeahnah.com/pkg_nope.p_hell_naw",
dataType: "xml",
success: function(data) {
var lastRegion = "0";
var lastTown = "nowhere";
var lastLocation = "0";
var lastLot = "0";
$( data ).find( "ROW" ).each( function(){
var thisRow = "";
var thisRegion = $( this ).find( "REGION" ).text();

I mean iterating over the dictionary, that is. What I'm saying is that you should map primes to their corresponding words, not the words to the primes.

Python is an order of magnitude slower than Java in practically all of those benchmarks.
In the ones where it is actually somewhat close, it uses a library that was implemented in C.

sloppy programmers make sloppy code
callbackhell.com/

>computation manipulation
>extension via lambdas
>pyramid of doom
You do know what the solution to this is, right?

>How the fuck is a nested function call hurting readability?
It's not just about the nested function call, but the harder to understand logic behind it. Now someone has to think about how your calls are feeding into one another instead of just thinking "Oh, it checks all the numbers."
It also fucks up the ink-to-information ratio, but a Sup Forums fag who's hobbies are sperging about optimization in Python shitposts on the internet probably wouldn't have heard of that.

>It would be worth it
Yes, I'll totally make my shitpost harder to understand and more verbose so that it'll run slightly faster.

Why would I map primes to their words instead of words to their primes? That seems entirely arbitrary. It also seems tangential and I think that has nothing to do with what you meant, you just realized you were retarded and wanted to shift focus.

I was giving you the benchmarks for a few Python programs, not telling you to compare it to Java. It seemed you were having trouble finding decent benchmarks.
You seem to not understand that Python is literally implemented entirely in C. A part of Python implemented in C is still a part of Python.

It seems arbitrary to you because you don't know the difference between keys and values.

>You seem to not understand that Python is literally implemented entirely in C. A part of Python implemented in C is still a part of Python.
>confusing a programming language with its implementation

>sloppy code

>Now someone has to think about how your calls are feeding into one another instead of just thinking "Oh, it checks all the numbers."
Oh no! Somebody actually has to think a little bit when trying to understand my program?
I do believe that program structure and clarity is important, but that doesn't mean that you have to cater to literal retards. I expect someone to be able to think about the sqrt(n) case and why that was chosen as the maximum pretty quickly.

Just read the link and be quiet

>Because you don't know the difference between keys and values.
The key is used to refer to a value. In my code, I never actually refer to one using the other, so there isn't actually a key or a value. I just iterate through the tuples and assign them to two atoms.

However, what makes the prime number more valid of a key than the string?

Why don't you just modify the code and show us?

nice comments

how can you suck 2 dicks and still type?
How?

My most elegant and solid code was done in batch. Not sure how to feel about that.

I can write some very efficient and readily extensible in C++, but I never feel good about it. If even a single decision causes a higher probability (or necessity) of a cache miss, or a superfluous check, or an unnecessary branch, I trace the entire chain back to the beginning and feel like it's garbage, despite knowing why I chose to bias things the way I did, and not being able to get rid of them or find a better way. I begin to feel like everything I built will just further accumulate inefficiency as a result of this core, intrinsic, unideal nature of what I've created.

It's a Dirac-esque "if it's ugly it must be wrong" attitude. I don't even know. I do know the way the main program is managing its list of files is terrible though.

the article doesn't even mention the one solution we all know and love

Modularity, intuitiveness, and openness; javascript and cryptoeconomics mainly; working on the parts necessary for spawning a superintelligence of global proportions; Linus, for not being a massive faglord.
If you're going for anything beyond original Doom level graphics, you're doing it wrong as a solo noob.
least common denominator is your lord and savior, this is a one-liner, stop overthinking it
ES6 quasiquotes are your friend
trololo
fuck jquery
document.getElementById(${id}).value is what you want to both get and set.
Use either a keypress event listener or a button to know when to do shit.

Yes it does

...

Embrace your sins, try javascript

>A part of Python implemented in C is still a part of Python
Irrelevant. The python implementation doesn't equate to the language.
If you allow FFI calls to be counted as part of the language's speed, then the whole idea of benchmarking programming languages goes out the window, as practically every language can call C functions.

Why do so many people hate jQuery? I'm too much of a beginner to understand if it's dumb.

Scroll to the bottom and read about promises

>implying I did
I literally said "Python is implemented entirely in C", not that "Python is a C program".
So it looks like you're the one confusing a language with it's implementation.

>someone has to actually think a little bit when trying to understand my program
If your program's goal is to be readable, such as a shitpost on Sup Forums, then that's an issue. What about this aren't you getting?

>but that doesn't mean that you have to cater to literal retards
It's a Sup Forums shitpost, you moron. That's exactly what it means. It's just that I have to decide between catering the majority of retards or if I cater to you, one very specific and very autistic retard.

You're looking up a word based on the prime it corresponds to, not the prime based on its word. I don't care enough to go through the code and fix it, but if I did, what I would do is print the word corresponding to the prime p at every pth iteration of the loop.

>The python implementation doesn't equate to the language.
When comparing language speeds, the implementation is the only element of it that is measurable. I never said they were the same thing. You're tech illiterate and need to consider a different field of study.

>You're looking up a word based on the prime it corresponds to
No, I'm not.

That function, FYI, calls a pl/sql proc that pulls data, then pushes the cursor to another proc that builds the xml.
It takes time.
It can't build a god-damned thing until post.
You can eat shit.

Frameworks in general are cancer
They have their place as a means of creating informed standards across a medium-large team that accommodates inexperienced developers by laying out clear expectations.
If you program for any reason other than taking home a paycheck from a large business not centered on tech, then don't touch the things.

Stop projecting your own incompetence onto everybody else.
Just because you can't solve trivial logic problems, it doesn't mean that other people cant'.

>when you're not sure if it's folder.zip/* or folder.zip/folder/*
>when you guess correctly

That's a very specific kind of monad, but these are general problems solved by monads

string
for string, prime in primes
if number % prime == 0
>not looking up string based on primes

>When comparing language speeds, the implementation is the only element of it that is measurable. I never said they were the same thing. You're tech illiterate and need to consider a different field of study.
The benchmark contains FFI calls, you fucking idiot. Do you even know what the fuck that is?

Ad hom is only fun when you include an argument with it.
I'm not going to obfuscate my code to please you. Deal with it.

>implying this guy would ever be able to anything complex

The answer is always extract to a subdirectory.

Good, you finally took the time to actually read the code.
I'm still not going to iterate over keys and refer to them every time I want the string instead of just iterating over the tuples. No reason to.

No reason to iterate, that is :^)

Shitpost face indicates sarcasm.

Oh, okay.

I'm using FCC to learn and they make us use jQuery quite a bit. It seems quicker than vanilla JS and easy to use for my beginner level.

Oh look, the autist is trying to pick up on emotional connotations!

It doesn't, really. I use it to indicate I'm correct, making no attempt to not be obnoxious, don't expect the other person has the capacity for a meaningful response, etc.

More or less it's shitposting in a way that also signals that who you're talking to is shitposting whether they intend to or not.
:^)
:^)
:^)
:^)
;^)

>Frameworks in general are cancer

Frameworks promote consistency and standards.
You in general are cancer.

>says something he actually means
>says it with sarcasm boi face
Do you know how sarcasm works?

>It doesn't, really.
It does, really. You're wrong and made no argument.