/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: gg.jpg (1280x720, 92K)

Other urls found in this thread:

lists.gnu.org/archive/html/emacs-devel/2010-04/msg00612.html
youtube.com/watch?v=J6OmF4wL3b4
archive.is/mnbNo
www-db.deis.unibo.it/courses/TBD/Lezioni/07 - n-D Indices.pdf
regex101.com/
programiz.com/python-programming/methods/list/copy
twitter.com/SFWRedditVideos

Lisp is the most powerful programming language.

fpwp

Should I just master COBOL, get a comfy stable job at the bank and not give any fucks for the rest of my life?

Why data structures got to be so damn hard

Season 2 never

Seems reasonable until you actually see it firsthand.

How are you defining powerful here? And which Lisp are you referring to?

Guys i need help. How do you stop procrastinating and actually commit to a project? i find it very hard to keep working on my current main project. It interests me, but it's so gigantic it often ends up boring me within 30 minutes of starting my work

>The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages.

I'm not even sure what Lisp he's talking about there. Emacs Lisp? Common Lisp? The notion of Lisp as a single language bugs me.

idiot

IIRC Stallman finds Common Lisp ugly.

So in my game you have various technologies, in this case 'faster mining'
but in order to research it player needs a certain level of building
faster mining has a WoodMine level 4 requirement therefore I wanted a hashmap with it along with int 4.

What I then wanted is to pass actual player buildings and contrast it against that hashmap or something with requirements so i would look something like this

if(playerBuilding == requirementBuilding)
get the value(4) of requirement building(WoodMine)

It can be done with separate two arrays, don't know if I should even bother with all this...

But he likes Emacs Lisp? Yikes.

Relax, take a nice long walk or something. Get away from the code for a bit.

how does this keep getting replies

Source: lists.gnu.org/archive/html/emacs-devel/2010-04/msg00612.html

Work on a bunch of different projects at the same time, so that when you get bored with one you jump to another one

I don't blame him. It is ugly. It's pretty fucking hard for Lisp to not look ugly. If it wasn't so invested in variadic functions (+, map, progn, etc.) it could be expressed in a much more ML-like syntax that still yields an AST amenable to templating.

youtube.com/watch?v=J6OmF4wL3b4

Why do people have such a hard time writing javascript tutorials and books without shoving in their favorite frameworks and and npm libraries starting from page 1?

It's almost like vanilla javascript is privileged knowledge like graphics programming, nobody fully understands it and it shows, the people who DO understand it don't write books.

Attached: AAAAAAAAAAAAAAAAAAAAA.png (338x656, 394K)

I've been working for a year as a React/Spring software engineer. I don't want to do checkboxes and REST endpoints all my life. Is security (malware analysis in particular) a good bet? Should I learn pentesting and stuff or can I skip that altogether?

Attached: goodparts1.jpg (550x270, 40K)

Yet it can't make a text editor archive.is/mnbNo

Is it possible to print out STL container contents in gdb?

If you think frameworks and npm suck, you should see plain javascript.

Lisp abuses cons cells.

Malware research is pretty interesting, albeit I think a lot of it is graduate level+ research. Not sure how lucrative it is but it's got a great set of challenges with it (making a federated testing environment, reversing, working out attack vectors). If you're just looking at security in general networks is the way to go since that's the largest attack vector out there.

>Assuming you can do linked lists
What are you tripping up on? BST?

I'm just struggling to find the correct data structure for my purposes. What I'd really like is something like a set but with fast indexing by two distinct means.

What is your purpose?

good old r-tree?

one map can be ID -> item.
one map can be key A -> ID.
one map can be key B -> ID.
wrap all 3 maps inside a set-like facade.

do you mean you want a compound key?
[k1 k2]

I have a set of sets of ranges of integers. None of the ranges overlap. i.e. {{(0-10), (5-15)}} and {{(0-10)}, {(5-15)}} are illegal. I want to efficiently find the range which an integer belongs to and I want to efficiently remove a set of ranges.

Just use a list and binary search/insertion.

What's the largest number set? 8 or 4 byte max?

devops is a fucking joke.

Could you use an interval tree of interval trees?

By "none of the ranges overlap" you mean that none of the ranges from the entire set of sets overlap, or none of the ranges inside a single set?

Can someone please explain what DevOps actually is? Every definition I've found boils down to "buzzword buzzword integrate often build often buzzword".
What is the catch? Is it unironically a massive set of buzzwords to sell common sense to retards?

>"buzzword buzzword integrate often build often buzzword"
That's exactly what it is!

Attached: index.jpg (248x203, 7K)

developers who can vms, pfsense, docker, jenkins and centreon

based and redbilled

4 byte.

none of the ranges from any of the sets overlap.

Make sure that developers don't shoot themselves in the foot when making changes to code and deployment. From what I've seen they automate a lot of testing and deployment to make sure nothing breaks (which things always do). It's sad because all of that can be done iteratively with simple bash scripts, but they feel the need to use all these FOTM frameworks that just break everything quicker.

Have you found a solution yet?

>find an integer in a set of ranges
>none of the ranges from any of the sets overlap
Create a sorted binary tree using your ranges. When you want to find out which range an integer is in, traverse the tree from the root and find the least common ancestor.
The node which has the boundary of each range in common is the node you want to trim.

This is my current idea.
I use a standard binary tree. Whenever I insert to the tree, I keep a pointer to the node in a list corresponding to which of the subsets the range belongs to. When I want to delete one of the subsets I just iterate over that list and delete all those nodes from the tree.
I'm just not sure if I can do better.

That's for a O(log n) solution anyway. Indexes on n-dimensions don't exist in O(1), that I know of.
All contemporary solutions are some variant of a tree.
www-db.deis.unibo.it/courses/TBD/Lezioni/07 - n-D Indices.pdf

Of course you may be able to exploit a property of your domain to use something other than a tree if the domain allows it, but it requires you to be more familiar with the domain, which we are not.

Your idea is not much different from the standard functional programming implementation of immutable lists.

Only, you do not need to keep a list of pointers. (it's unnecessary; just traverse the tree)

So my data structure looks something like this
struct node
{
int range_start;
int range_end;
int subset_id; // which subset this node belongs to
struct node *left;
struct node *right;
// whatever other info I need to autobalance
};
And when I want to delete all the elements belonging to a particular subset, I just traverse the whole tree and delete all the nodes with a given subset_id?

Anyone here knows regular expressions?
Why does this 0*1(0(0|1)|1)* accepts 10? If it sees a zero doesn't it have to get either another 0 or 1 because of (0|1)?

Well, here's the way I see it, you want an efficient implementation to search for integers, but you also want to constrain them to some ranges, and you also want to delete an entire range as fast as you can.

So the data structure probably looks more like this:
struct range {
int range_start;
int range_end;
struct node *left; //any nodes with range_end less than my range_start
struct node *right; //any nodes with range_start greater than my range_end
hashtable numbers; // all my numbers
}

The hashtable numbers is probably a fixed-length hashtable that can retrieve values in O(1) (for a total O(log n) search)
When you delete a node, you automatically delete the whole subset in O(1), but since you need to search for the node to delete (and rebalance the tree) a delete becomes O(log n)

convert two 4 byte vals into 8 byte with a bst. for example
5-10 would be
00000000 00000000 00000000 00001010 00000000 00000000 00000000 0000101

and just check your value with an int cast. Have the root be the medium of the ranges. the root and larger ranges have the max in the lower 4 bytes. The smaller ranges will have the min in the lower 4 bytes.

>and you also want to delete an entire range as fast as you can.
No, that's not what I want. I don't want to delete a single range, I want to delete a set of ranges. Also these ranges do not apparently have anything in common (e.g. being relatively adjacent) so I can't guarantee they'll be direct parents or children within the binary tree structure.
I will know which of the sets the range will belong to at insertion time.

So I think something like this is appropriate.

struct node
{
int range_start;
int range_end;

struct node **batch_deletion_prev;
struct node *batch_deletion_next;

struct node **parent;
struct node *left;
struct node *right;
int balance_factor;
}

struct tree
{
struct node *root;
struct node *batch_deletion_sets[NUM_SETS];
}
Apart from the tree structure, every node also belongs to one linked list, for the set it's a part of. When I insert something I add it to the front of one of these linked lists at the same time as I add it to the tree structure, and when I delete a whole set I just walk the linked list and delete everything I encounter.

It really depends on what industry you're deving in. Dev is the dev and Ops is the ops and DevOps are people who help get Ops requirements to Dev.

No software exists in a vacuum. Except maybe video games but not really because there are still players and servers. Software is integrating real world things with real-world clients. For example I'm in a medium-sized fintech company doing all sorts of trading-based integration with robotrading systems for different brokers and a lot of the work is figuring out exactly what the workflow for those trades is going to look like for each specific broker, how to handle fail cases/reject requests with them, etc. Our company is hiring DevOps to take a lot of that information-gathering and communication out of the Dev's hands so that we can focus on software.

What's the difference between an devops/ops and a project lead?

* means 0 or more
It's not matching the whole 10, it's matching 1. Because it starts with 0 or more '0', then matches 1, then matches 0 or more '00', '01', or '1'

Also regex101.com/ is very helpful. It explains matches and lets you hover over your script to see what's going on.

A project lead is defining the projects you're working on. DevOps don't define the requirements, they just help fulfill and explain some of the less-coding related aspects of the project. If you think of it as a building, the Project Lead is doing the architecture and blueprints, the Devs are building the building and the DevOps are talking with suppliers to get the resources, talking with city hall to get the permits, etc.

Please do not use an anime image next time -- thank you.

it has always been an anime image

I see.
How important is it that you delete the set of ranges as fast as you can; i.e. do you actually have an asymptotic number of ranges, and your current implementation does not meet performance requirements on batch delete?

If so, you may consider a lazy deletion approach.
Essentially, when you call batch_delete(int subset_id), you do not *actually* delete a set with a subset_id.
You merely mark the subset_id with a gravestone flag.
Then, when you perform any other operation, you can actually delete a node you traverse whose subset_id has been gravemarked.
You can also have a garbage collection pass which will delete all of the gravemarked subset_ids at once.

This is called amortization; you pay the cost of a slightly heavier insert, retrieval etc. in order to have a cheaper batch delete.

>Monads are like a dildo factory

Yeah, I think that could work. I'm not so memory constrained that I need to reclaim those ranges as soon as I'm done with them, and removing two or three pointers will go a long way to keeping all my data safely contained in a single cache line.

... go on.

Deciding against Janus+Cassandra for my tag recommender. I want to make something lightweight so I can use it for a game idea I have. Still working through how to recommend stuff using a graph.

Planning and learning stage of making stuff with ncurses
on that note, how long for me to be somewhat proficient with ncurses? Not really started because I've been busy so I've not really got an idea in my head

Attached: 1477359080890.png (1920x1080, 984K)

It's pretty easy to pick up. Just remember that terminals are slow as fuck so only redraw what you need to instead of the entire window. Otherwise you get nauseous flickering.

Good shout, thanks friend.
Not really sure why I hadn't delved into it sooner other than being lazy

ncurses isn't anything crazy, if you're familiar with raster graphics at all you can just pick it up and go.

The first project I did in ncurses is conway's game of life, would recommend it if you don't have any ideas.

Why the fuck is list2 being modified?

list1 = [[1,2,3], [4,5,6]]
list2 = [['a','b','c'], ['d','e','f']]

print(list2)

list1 = list(list2)
list1[1].append('e')

print(list2)


C:\Users\Sosimo>py test.py
[['a', 'b', 'c'], ['d', 'e', 'f']]
[['a', 'b', 'c'], ['d', 'e', 'f', 'e']]

C:\Users\Sosimo>

you're storing the reference to list2 in list1, not a copy.

The list() function isn't copying the list, what it's doing is more like casting into a list, but since it's already a list, it's doing nothing (I'm not 100% on the mechanics of Python's list function and how it works with Itterable, sets, and collections, but clearly list(list2) isn't doing what you expect).

What you want is list1 = list2.copy()

Doesn't list(old_list) copy? I've tried old_list.copy() too and I get the same result.

That doesn't work either.

list1 = [[1,2,3], [4,5,6]]
list2 = [['a','b','c'], ['d','e','f']]

print(list2)

list1 = list2.copy()
list1[1].append('e')

print(list2)


C:\Users\Sosimo>py test.py
[['a', 'b', 'c'], ['d', 'e', 'f']]
[['a', 'b', 'c'], ['d', 'e', 'f', 'e']]

C:\Users\Sosimo>

>I've tried old_list.copy() too and I get the same result.
I'm pretty sure you did something that time wrong, then. old_list.copy() will create a deep copy.
programiz.com/python-programming/methods/list/copy
# mixed list
list = ['cat', 0, 6.7]

# copying a list
new_list = list.copy()

# Adding element to the new list
new_list.append('dog')

# Printing new and old list
print('Old List: ', list)
print('New List: ', new_list)

try deepcopy

Everything except ints are assigned by reference
Yes, but it's a shallow copy. It makes a new list containing the same 2 old lists in list2.

this
list(list2) is a cast or no-op.
list(Sequence) is supposed to be used to generate a list from a generator expression.

Say I want to build a thingy in C++ which makes a lot of sense to be composed of several binaries (they do unrelated things, basically several independent stages of processing data where you will usually want to run them independently because they'll be cached to a central store and you'll just rerun the stage you need). But some of the interface will be the same, so most of the option and configuration parsing and handling code could actually be shared between the two.

Now say also I have never made anything of this size and complexity in C++ and never encountered this kind of problem before. How would this be done to avoid code duplication?

Oh, derp, I didn't even look at your code very closely, my bad.

Yeah, see, what you're doing is creating a deep copy of a reference to a list. If you changed list1[1] then list2[1] wouldn't change, but you're adding entries to the list stored in list1[1]. Which is the same list that list2[1] is copying.

In other words "deep copies" aren't n-deep, they are only 1-deep. You would need to do
list1[1] = list2[1].copy to have them reference separate lists.

>in C++
C++ isn't relevant here.
You want to make a core shared library that all of them are dependent on which implements the shared code.
If possible you should implement your parsing and handlers as higher order functions, so that when you bring them into your actual components, the only thing you need to do is specialize the functions for your use case.

python confirmed for worst language

that is literally the definition of shallow copy, and help(list) uses the term "shallow" for the .copy() method

or just
from copy import deepcopy

Keep the configuration code in a separate library and include it in both binaries. The configuration management library could be compiled into every binary if it's small enough, or be compiled into a separate object and linked to the two user application (.dlls in Windows and .so in Unix).

Yes, literally everyone eventually gets bitten by this. Then you have to explain reference semantics to an absolute beginner. Honestly it would almost be better if they were using C++ which is much more upfront and explicit about reference semantics.

This question alone gets asked on /dpt/ at least once a week.

import copy

list1 = [[1,2,3], [4,5,6]]
list2 = [['a','b','c'], ['d','e','f']]

print(list2)

list1 = copy.copy(list1)
#list1 = list2.copy()
list1[1].append('e')

print(list2)
print(list1)


C:\Users\Sosimo>py test.py
[['a', 'b', 'c'], ['d', 'e', 'f']]
[['a', 'b', 'c'], ['d', 'e', 'f']]
[[1, 2, 3], [4, 5, 6, 'e']]


A pajeet in a youtube video told me to just use the copy module and it worked.

Not sure if there's a better thread for this but I started working at a company where they're pretty open for people moving into a development role if they can show they're competent. They've got a lot of various projects running with various languages (Python, Java, C++, C#) and a friend suggested I start with Java since it'll be easier to move into other languages through Java rather than vise versa. I'm planning on spending pretty much every bit of free time I have learning and I'm looking for general advice and tips that people wish they had when they started.

A few people have told me it's more than possible to get to a "competent" level in 4-6 months but I'm thinking a year is probably much more realistic.

That sounds about right. I don't think size will be much of an issue so I'll probably go the first route for end-user simplicity. Since like I said I never used C++ for anything complex, how would that work in general terms? Do I just have my .cxx files that have the functions for doing the configuration handling etc. get included by the compilation commands for both binaries, or is there a better practice for doing this sort of thing?

>list1 = copy.copy(list1)
>#list1 = list2.copy()
>list1[1].append('e')
???

sorry, I'm high
import copy

list1 = [[1,2,3], [4,5,6]]
list2 = [['a','b','c'], ['d','e','f']]

print(list2)

list1 = copy.deepcopy(list2)
#list1 = list2.copy()
list1[1].append('e')

print(list2)
print(list1)


C:\Users\Sosimo>py test.py
[['a', 'b', 'c'], ['d', 'e', 'f']]
[['a', 'b', 'c'], ['d', 'e', 'f']]
[['a', 'b', 'c'], ['d', 'e', 'f', 'e']]

Usually you have separate implementation and interface files (.cpp, .cxx, etc. and a .h, .hpp, etc.) The interface file declares your classes, functions, etc. and the source file contains the actual class and function implmementations. Just like you're probably familiar with. When you compile your applications you just add the source files to the g++ (or clang, whatever) argument list and everything should be kosher. Later, if you want to make it a shared library all you really need to do if change the way you compile it, the file structure will stay the same.

Whoops

Yes, longer is more realistic. It truly doesn't matter what language you start with. If you are interested and intelligent you'll pick it up pretty quick. Just don't get discouraged when you eventually encounter all the stupid bullshit everyone goes through

>Just don't get discouraged when you eventually encounter all the stupid bullshit everyone goes through
That part doesn't worry me at all, it's just finding a starting point currently. There's a lot to take in.

Write a lot of programs, that's pretty much it. You only get good with a language, and programming in general, when you make mistakes that need to be resolved that make you ask the right questions.