/dpt/

/dpt/ - Daily Programming Thread

old thread:


What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/FXLx0Y32
pastebin.com/4i1LkvCt
benchmarksgame.alioth.debian.org/u64q/compare.php?lang=java&lang2=gpp
youtube.com/watch?v=PkoY1zRgQik
twitter.com/SFWRedditGifs

Trying to figure out something useful to do.

Hey isn't that Dan "Get in the Van" Schneider?

>306 posts
This is an illegitimate spam thread.

shit op
shit thread
before bump limit
sage

Why do some of you idiots dislike do-whiles? Say you have an initial value of a variable set to 0. The user is told to input a value between two numbers that are variable controlled. If zero is within those two numbers the user will never get the chance to enter his value.

Haskell or Rust? Which is the future?

>inb4 some language that doesn't have a decent concurrency model is suggested

I don't know of there being a general dislike of do-while as a construct.

What are some good resources for learning java?
Going to college next year and I wanna be ahead of the curve

Look in the last thread, bunch of people saying not to use them and that they've never seen the need for them.

How is python with pypy-stm not an option?

Other thread got deleted.

I started writing an imageboard software in C and I quickly realized I have no idea what I'm doing.

I have the database schema finished, but I just realized I have to implement a way to tokenize URLs like Sup Forumsthread/56055170 and turn them into something the CGI program can understand.

Jesus, can mods at least delete the OP pic?

MODS delete the OP pic it's a fucking pedo pic.

so, no one knows how to average two integers in Go?
top kek /dpt/, buncha useless fags ITT

How's pic related?

Can't you just use the 56055170 as the pk for the thread table? And have some logic in your application that creates a new thread in the table if one with that id doesn't exist?

Good. Other thread was shit.

It's just dan the hymen divider schneider, chill.

i used to jerk off so much to the grills on that show

Nice thread faggot

is that book some sort of pedo code?

Tool to quickly send pictures to different directories
(don't want my /h/ mixed with my /s/)

# part one


# Ubuntu 16.04: `sudo apt-get install libtcltk-ruby`
require 'tk'
# themes and new-style widgets
require 'tkextlib/tile'
# support for civilized and common image formats (.jpg, .png, etc)
# Ubuntu 16.04: `sudo apt-get install libtk-img`
require 'tkextlib/tkimg'

class HotkeysWindow
attr_accessor :hotkeys

def initialize parent
@parent = parent

path_entries = []

@hotkey_window = TkToplevel.new @parent.root_win
10.times.each do |index|
Tk::Tile::Label.new(@hotkey_window) { text "When I press #{index.to_s} move the image to:" }.grid( :row => index, :column => 0, :sticky => 'w' )
path_entry = Tk::Tile::Entry.new(@hotkey_window).grid( :row => index, :column => 1, :sticky => 'w' )
path_entries.push path_entry
Tk::Tile::Button.new(@hotkey_window) {
text 'Set path'
command(proc{
path_entry.value = Tk::chooseDirectory
})
}.grid( :row => index, :column => 2, :sticky => 'w' )
end

# defining these here so we can access instance vars in such a way that they survive being passed through several blocks to the button commands
onok = proc {
@parent.set_hotkeys(path_entries.map { |e| e.value if e.value and e.value != '' })
@hotkey_window.destroy
}
oncancel = proc {
@hotkey_window.destroy
}
Tk::Tile::Button.new(@hotkey_window) { text 'Ok'; command onok }.grid( :row => 11, :column => 0 )
Tk::Tile::Button.new(@hotkey_window) { text 'Cancel'; command oncancel }.grid( :row => 11, :column => 1 )
end
end

# part two


class ImageSorter
attr_accessor :root_win, :hotkeys

def initialize
@hotkeys = {}
@image_list = []
@current_img_index = 0

build_gui
end

def build_gui
@root_win = TkRoot.new { title 'Image Sorter' }

menubar = TkMenu.new @root
mfile = TkMenu.new menubar
mfile.add :command, :label => 'Set Hotkeys', :command => proc{ show_hotkeys_window }, :accelerator => 'ctrl + h'
mfile.add :command, :label => 'Open Directory', :command => proc{ open_dir }, :accelerator => 'ctrl + o'
mfile.add :command, :label => 'Quit', :command => proc{ exit }, :accelerator => 'ctrl + q'
menubar.add :cascade, :menu => mfile, :label => 'File'
@root_win['menu'] = menubar

@image_display = Tk::Tile::Label.new(@root_win).pack( :side => 'top', :fill => 'both', :expand => 'yes' )

@root_win.bind 'Control-h', proc{ show_hotkeys_window }
@root_win.bind 'Control-o', proc{ open_dir }
@root_win.bind 'Control-q', proc{ exit }

@root_win.bind 'Left', proc{ on_prev }
@root_win.bind 'Right', proc{ on_next }
@root_win.bind 'Key', proc{ |k| on_hotkey k }, "%A"

return @root_win
end

def open_dir
@top_level_dir = Tk::chooseDirectory
return unless Dir.exists? @top_level_dir
#puts "open '#{@top_level_dir}'"
@image_list = find_all_images @top_level_dir
@image_list.sort!
@current_img_index = 0

set_image @image_list[@current_img_index]
end

def show_hotkeys_window
hkw = HotkeysWindow.new self
end

def set_hotkeys keys
#keys.each do |k, hk|
# puts "set hotkey #{hk} (48 + #{hk.key} = #{hk.ascii_key}) => #{hk.path}"
#end
@hotkeys = keys
end

# part three

def on_prev
@current_img_index = @current_img_index - 1
@current_img_index = @image_list.length - 1 if @current_img_index < 0
set_image @image_list[@current_img_index]
end

def on_next
@current_img_index = @current_img_index + 1
@current_img_index = 0 if @current_img_index > @image_list.length - 1
set_image @image_list[@current_img_index]
end

def on_hotkey k
path = @hotkeys[k.to_i]
unless path.nil? or path == ''
puts "move #{@image_list[@current_img_index]} => #{path}"

end
end

# return an array of all image paths under path (recursive)
def find_all_images path
# looks in path and also in sub-dirs of path
return Dir[
"#{path}/**/*.jpg",
"#{path}/**/*.png",
"#{path}/**/*.gif"
]
end

# part four

# show the image at path if it exists
def set_image path
if !path.nil? and File.exists? path
#puts "Go to '#{path}'"
tmp = TkPhotoImage.new( :file => path )
img = TkPhotoImage.new()

# we must manually figure out how much to subsample it to make it fit
# because Tk sucks at handling images so we can't just say "shrink or zoom to fit"
image_ratio = tmp.width.to_f / tmp.height.to_f
window_ratio = @root_win.winfo_width.to_f / @root_win.winfo_height.to_f

if window_ratio > image_ratio
fit_res = [(tmp.width.to_f * @root_win.winfo_height.to_f / tmp.height.to_f).to_i, @root_win.winfo_height]
else
fit_res = [@root_win.winfo_width, (tmp.height.to_f * @root_win.winfo_width.to_f / tmp.width.to_f).to_i]
end

subsample = [(tmp.width.to_f / fit_res[0].to_f).ceil, (tmp.height.to_f / fit_res[1].to_f).ceil]
subsample[0] = (subsample[0] > 0) ? subsample[0] : 1
subsample[1] = (subsample[1] > 0) ? subsample[1] : 1

#puts "#{image_ratio}, #{window_ratio} -> #{fit_res}, #{subsample} ; #{tmp.width}, #{tmp.height} ; #{@root_win.winfo_width}, #{@root_win.winfo_height}"

img.copy( tmp, :subsample => subsample )
tmp = nil
@image_display['image'] = img

@root_win['title'] = path
else
raise "Image path not found: '#{path}' (has the image been moved or deleted?)"
end
end
end


if __FILE__ == $0
i = ImageSorter.new

Tk.mainloop
end


The only think left is to actually move the file when the hotkey is pressed.

Oregon Trail pajeet from the last thread reporting in. (though the quoted post isn't me) Wouldn't a do-while loop be more efficient then reassigning the variable through every iteration of a loop?

For example wouldn't
var something;
for (i = 0; i < 100; i++) {
do {
input(something);
} while (something != somethingElse);
}

be more efficient than
for (i = 0; i < 100; i++) {
var something;
while (something != somethingElse) {
input(something);
}
}

Basic rougelike style game in C++. Not doing random generation yet, map data is read from a file.

ffs why didn't you just pastebin it?

do while and while in this situation should generate the same code. It's a matter of preference.

i put all the comments and OP posts in the same table when i realized the thread and comment tables were almost identical.
each row has a field for is_parent and parent_id if it's not a OP post.

Made something similar to sort my porn a few months ago.

Takes two config files, one with a list of source dirs, and one with a list of dest dirs (each with a shorthand name).

Then it just displays each pic in the source dir and you click one of the buttons created to send it where it belongs.

Kinda surprised something so simple didn't exist, or if it did, I couldn't find it.

reddit wants developers to unionize

Isn't that communism?

Surely you want a seperate table for ops though? Think about something like the catalog, would be easier just to "SELECT * FROM Threads" vs "SELECT * FROM Posts WHERE op_post"

Pretty neat.

pastebin.com/FXLx0Y32

int initialPurchase (int a[]){
char *items[]={"oxen","ammunition","clothing","food","misc. supplies"};
int money, min[]={200,0,0,0,0}, max[] = {300,700,700,700,700};
do{
money = 700;
for(int i = 0;i

Is there a real performance difference?
I have no problems doing something like
SELECT * FROM posts WHERE is_parent = 1;
To generate a thread page, i just grab all the posts that match that parent_id and display them in ascending post number order.

yes. grab a gun and kill random people before the commie developers take over

Surely any query with a WHERE in it will be less performant than one without? Even the best database will perform worse when you ask it to filter rows in any way. In your case you would want to create an index for is_parent in the posts table to make that selection as efficient as possible, but the db will still have to add to the index on each INSERT.

Not that any of this matters at your scale, but if you are thinking about efficiency there you go. Note that I'm not an amazing db person, so the above could be wrong.

Is that Dan "hymen divider" Schneider

His name is Dan "Large Hymen Collider" Schneider fyi.

so not rust then? plain old threads isn't a decent concurrency model

I heard rust had green threads but thanks to their runtime autism (muh C replacement) they scrapped it

What languages do you guys know?

Who is this guy, again?

Spanish, english, and C#. Damn, my C and sepples are super rusty.

Dan "Hold Her Tighter She's A Fighter" Schneider
Dan "The Big Dick At Nick" Schneider
Dan "If You Want A Role Give Up That Hole" Schneider

Cool what kind of things have you made with C?

Unions aren't communism until they're not optional.

Recursive fizzbuzz.

This is the best dpt so far

C, C++ (a bit), Matlab/Octave, LabVIEW and Lua

Dan "bend her over and fill her end" Schneider

C/C++, C#, Python, Ruby, Javascript, Unrealscript, PHP, and a smattering of Lua, Rust, D, and Haskell.

What's the point of languages that aren't C++, D or Haskell?

Java is the best language, it works on any platform and is just as fast as c++.

Now the better question is, what's the point of languages that aren't Assembly?

java, c/c++, c#, javascript, ruby, and barely some python

>Java is the best language, it works on any platform and is just as fast as c++.

Java's portability is greatly overstated. Generally it's implemented in C/C++ and then bootstrapped. It literally runs on as many platforms as C/C++.

if i allocate o(n^2) space at the beginning of my algorithm but free it at the end does my algorithm technically use o(1) space

...
no

>just as fast as c++
Wow. Spotted the first-year pajeet retard.

What a pajeet, don't you know that in some cases Java is actually faster than C++? Try writing a huge for loop in each language and compare the times, Java will be faster because of the JIT.

Idiot.

i dont get how someone can just start programming something. I don't see how it can be used to make shit. Someone blue pill me on this

2D platformer with SDL2
hobby interpreted language
space gravity simulator
conway's game of life
nintextdogs


need new idea pls

That's not how JIT works.

The problem is that you need an idea and a plan on how to complete that idea. i.e. you don't go from "i want to make app that find women" to programming immediately; you have to think about how it will work and how you will implement it
I usually write a short write-up for my reasoning and doodle some design graphs before getting started

Communism is always optional; being stateless, it is not implemented, but spread.
The most horrible form of subjugation comes from within ourselves, the only way to be free is to surrender ourselves to the absolute, to be connatured into eternity.

That's not at all true to the original game. I wanted to make the user experience identical. Not saying your code is bad (it's certainly better than mine) but it's just not what I was going for.

Here's Pajeet remakes The Oregon Trail part deux: Electric PooALoo
pastebin.com/4i1LkvCt

>it is not implemented, but spread.

top fucking laughing, mate. If that's true, then what do you need the revolution for?

anyone here knows some good text-to-speech engines?

ms sam

Unions are not communism or socialism. But strictly speaking, they run contrary to the ideals of a free and open market, and often make the workplace worse for all parties.

We don't need unions. We just need to stop this push towards making everyone a Computer Science major. Convince people either that it is too hard, that it is boring, or that the job market is flooded. There is a grain of truth to all of these, depending on who you are talking to.

If communism is stateless, logic follows that revolution occurs to get rid of the state altogether. Of course, what follows will always be the creation of a state, because the majority of the population wants a state to exist. So what you get is a government that tries to "enforce" communism. What follows is numerous human rights violations in the name of a shitty ideology that doesn't even work on paper.

>top fucking laughing, mate. If that's true, then what do you need the revolution for?
the retarded anarcho-capitalist strikes again with his incredibly twisted (if not simply stupid) logic

Newfag here. I barely know Java and have been using Eclipse. I want to learn C++ so I can make some applications in linux. Is installing the eclipse-cpp package a good ide for C++ development? Or are there other IDE's in linux that you guys use?

I just installed geany because I got tired of using different one-lang IDEs for every lang I wanted to learn, but I haven't really used it yet so I can't recommend it really

Use Vi.

I currently use Geany for XML, javascript, json, etc. I was wanting a more noob friendly IDE that automatically imports missing packages and stuff, like Eclipse does with Java.

>using ides that encourage bad programming habits

If Java is beating your C or C++ then you're butt-fuck shitting-in-the-streets retarded.

benchmarksgame.alioth.debian.org/u64q/compare.php?lang=java&lang2=gpp

Pajeets BTFO with facts.

those don't allow free commercial use :(

Is it possible to use a css val(--whatever) in conjunction with a css transition?
I'm using a polymer iron-icon and trying to use transitions to have it expand from 0px to 32px. But whether I apply the --iron-icon-width:0px using setProperty or by applying a class, it doesn't seem to be rerendering the icon, even though if I poll the value using getPropertyValue, it has been updated correctly.

commonly known as Dan "Hold Her Tighter, She's a Fighter" Schneider

We don't need the revolution, nobody does, revolution is and always has been a tragedy, it is the gold of fools who do not understand what they are overthrowing.
And yet now we celebrate it, can you believe it?
We overthrow the very precepts of western thought and yet we still call ourselves western people.
Now we have only a view through the looking glass; nobody is acquainted with people like Aquinas or Aristotle except superficially, they see it all as if the strife of the last ~2000 years amounts to a mere behavioral quirk of historical peoples that no longer concerns us.

>more like Saaaanjaaaay

Oh look it's another idiot who thinks Java is inherently inferior to c++.

Fyi it's a tie.

Now compare memory usage

nice bait desu

Ram is cheap :')

>this much bait

>hurr durr these graphs with no source and no source code prove me right!!!

youtube.com/watch?v=PkoY1zRgQik

Can Sup Forums use even a single one of these languages?

Here are real comparisons and Java is about 2 times as slow.

benchmarksgame.alioth.debian.org/u64q/compare.php?lang=java&lang2=gpp

Considering all benefits Java brings, though, I'd pick it over C++ any time of day.

Perl, Js, C++, Assembly (isn't a language).

The list's shit.

>Haskell
>difficult

>in some cases Java is faster
By some cases, I mean cases where the JIT can cause Java to actually perform much faster than equivalent C++.

Example:
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++) {
// Some insignificant constant time operations here. Don't ever do a benchmark like this with standard output though, you will end up speed limited by the terminal.
}
}

Java's hot spot JIT will cause this to perform much better than equivalent C++ code.

Sounds like legitimate idiots. The alternative to a do while loop is to have at least some part of the code duplicated before the do while loop and write the condition with one complete iteration in mind.

Do while loops are certainly a good language construct to have if it also has while loops.

Rust just gained a great Future's library. If it gets generators / yield, it'll have an incredibly solid async + concurrency story, better than any other language suitable for a C++ replacement.

Trying to make my own finite element modeller to enable me to do 2D plate analysis without paying out the ass for software.

I've never programmed before

Top. Fucking. Kek.

Yes I'm serious. I always do hard things to force myself to learn.

Well here you're comparing an uninitialized value. Its not equivalent code.

Just started learning Python on Codeacademy.
I'm pretty dumb and english isn't my first language, but I'm stuck here, what am I doing wrongK?

>benchmark with standard output
Why would anyone do that ever? Collate your profiling information. Its not hard.

Jesus...nvm I just noticed the ":" was missing.