old thread: What are you working on, Sup Forums?
/dpt/ - Daily Programming Thread
Other urls found in this thread:
github.com
fabiensanglard.net
roxlu.com
jinx-lang.org
jinx-lang.org
defit.org
rms.sexy
en.wikipedia.org
twitter.com
>javascript
>C++
>java
>python
>ruby
Languages that have no right to exist, and should be destroyed
Reposting from previous thread
so according to sys.getsizeof(), an int is 28 bytes. You're creating 999999999 of them.
You need therefore 999999999*28 bytes of memory, which is ~26 GB, hence the OOM error.
Reposted from last:
I need to copy a large amount of files into their own directories. The issue I am having is keeping them in order when I copy them with GNU parallel. For example, output_file_1 gets placed in output_directory_19.
Here is what I have so far that is working, besides the order of files.
ls *.output > copy.list
parallel "mkdir cele_{}" ::: {1..10000}
parallel -k --link "cp {} cele_{}" :::: copy.list ::: {1..10000}
Is there a way to do this without sacrificing parallel?
How possible would it be to create a program that searches google for news related to some key words and save the links of said articles
i think google used to have a feature where they'd email you or add to an RSS feed whenever a specific keyword appeared in search results but that's probably a paid feature now, knowing them
Any general project ideas that I could actually put on my resume for an entry level Dev position?
just know someone inside the company to put in a good word for you
OK but I'm already doing this, just looking for something I am working on that is a little impressive/just something to talk about in an interview.
Take an idea that you wish existed and then make it happen.
The only way to impress people in this day and age is to make your application a web app, so get started.
Thanks
How can I make this work with other return types, not just void? no bully please
#include
#include
#include
#include
#include
#include
#include
template
const T& max(const T& a, const T& b)
{
return (b > a) ? b : a;
}
class ThreadPool;
class ThreadPool {
public:
int MaxNumThreads;
std::queue tasks;
std::mutex tasksMutex;
std::vector threads;
std::atomic destroy;
static void threadLoop(ThreadPool* tp) {
while (1) {
if (tp->destroy) return;
if (!tp->tasks.size()) std::this_thread::yield();
tp->tasksMutex.lock();
if (!tp->tasks.size()) {
tp->tasksMutex.unlock();
continue;
}
std::packaged_task task = std::move(tp->tasks.front());
tp->tasks.pop();
tp->tasksMutex.unlock();
task();
}
}
ThreadPool() : destroy(false) {
MaxNumThreads = max(std::thread::hardware_concurrency() - 1, (unsigned int)1);
for (unsigned int i = 0; i < MaxNumThreads; i++) {
threads.push_back(std::thread(ThreadPool::threadLoop, this));
}
}
~ThreadPool() {
destroy = true;
for (auto& t : threads) {
t.join();
}
}
template
std::future addTask(_Fn&& func, _Args&&... args) {
tasksMutex.lock();
tasks.push(std::packaged_task(std::bind(func, args...)));
auto future = tasks.back().get_future();
tasksMutex.unlock();
return future;
}
};
void toDo(int* work) {
*work += 10;
}
int main() {
ThreadPool tPool;
int x = 0;
auto f1 = tPool.addTask(toDo, &x);
auto f2 = tPool.addTask(toDo, &x);
auto f3 = tPool.addTask(toDo, &x);
f1.wait();
f2.wait();
f3.wait();
std::cout
Rewrite it in C then ask your question again.
template it first?
Impossibly, C isn't turing complete
>template it
what did he mean by this?
How does a game like Quake 2 draw in software mode?
Does it set the pixels in an array and then that array goes to the window?
I hate to sound like a dick, but that doesn't mean anything if it's not pointed out and explained. If I know where to look, I can probably see how the pixels are set then.
nevermind, figured it out
thanks for nothing
.isBrainlet ? kys() : kys()
if(op.isAFaggot()) op.willKillHimself();
>so according to sys.getsizeof(), an int is 28 bytes.
The absolute fucking state of soy boy PLs...
Doing com scripting in python
why is windows so shit
What programming languages are more extensible than C++ while also being comparable in performance?
>someone saved my meme
You could read the source code, or one of the many reviews of the source code
if (age < 18) return;
wooooow look at you using big boy conditionals
map(lambda anus:anus.head,[])
>more extensible than C++ while also being comparable in performance
Nim. In any case, you're setting an arbitrary goalpost. C++ "extensibility" is babby-tier no matter how much you screech about muh performance.
I made a function that takes my soul as an argument. It is a void :(
Doesn't Nim use a GC?
>C++ "extensibility" is babby-tier no matter how much you screech about muh performance.
I agree, I'm not exactly setting a high bar here.
This absolutely.
It's really something only someone who hasn't really reached outside C++ could say.
You're looking for this.
fabiensanglard.net
i think it's doing the rendering in the vga buffer.
for (int i=0;i
Thanks
Is it possible to recreate this software renderer in SDL2?
Why do you code, if you will always be an unhappy person?
i think the best with today hardware would be to allocate a pixel buffer with opengl or vulkan, doing rendering in that buffer, then uploading the buffer to the gpu.
roxlu.com
with an apu (gpu and cpu on the same chip), you could use a shared memory buffer which is the same as the old hardware.
are you on linux?
Yes.
You'd just have to reproduce the renderer and then pass your graphics api the offscreen buffer mentioned on that page.
windows 8.1 with codeblocks
I'm trying to get myself into the functional mindset, and obviously part of this means programming a few toy programs. I'm doing a markov chain. Now, in an imperative language i'd iterate through the seed text in pairs, storing in some sort of dict/hashmap each word and a list of the words that have came after it.
Functionally, everything is immutable, so doing a similar approach would mean creating a new copy each time. Is this inefficent/the incorrect way to do it "functionally"? I can't think of a different approach.
c++ fag here
I need a scripting language but I want to be as hipster as possible, Python is too mainstream for meself. What do. D? Some Lisp?
perl is nice if you are coming from a C or Java background
How do I pass the same viewstate between modules in asp.net?
ocaml, (ats, haskell if you can script them?), even php would be pretty hipster but people hate it out of trend so you wouldn't get any hipster value out of it.
lua and scheme are mainstream scripting languages
right! thanks, forgot about it. it's marvelous
ok, gonna learn me some perl wizardy
a man can unsarcastically script in ocaml?
first you can have immutable data structures
for instance, consider a linked list - in order to add something to the front, you don't have to edit the old list
second, in this case it's pretty fair to do mutation
Linux newfag here.
Ive got a program that i'm supposed to install on a redhat linux machine. I downloaded the file as an exe.gz file.
Gunzip says the file is the wrong format to unzip. But im pretty sure that you cannot run exe files on linux anyway?
Am I just doing it wrong?
it can compile to native binaries and I think you can embed the vm in your program so you could run the bytecode, I assume the vm can also interpret script but I might be wrong.
e.g.
x
1 -> 2 -> 3
prepend 4
y .. x
4 -> 1 -> 2 -> 3
as far as x is concerned, the list is unchanged
Chaiscript
Very hipster.
Made by a frequent Cppcon speaker.
Implemented in idiomatic C++.
Made for C++ embedding.
Permissive license (BSD)
Perhaps you didn't care for embedding. But trust me you will.
polymorphism nigga
i'd poly your morphisms desu
jinx-lang.org
how procedure are defined is interesting.
see the fizzbuzz example jinx-lang.org
Emulating Smalltalk's Cascades in Python:
class Cascade:
... def __init__(self,arg):
... self.arg = arg
... def end(self):
... return self.arg
... def __getattr__(self,attr):
... def _forwarded(*args,**kwargs):
... method = getattr(self.arg,attr)
... method(*args,**kwargs)
... return self
... return _forwarded
Which lets me do something like Cascade(foo).bar(x,y).baz(z,w).end().returningmessage(a,b,c)
...which makes Python strictly more expressive than Smalltalk for sending messages to objects.
>exe.gz
Please, user.
not op but interested in how you would make a functional markov chain.
from my understanding you need a dictionary because you need to look up the probabilities for generating word sequences, and with a linked list the look up is O(n) which would make generating awful especially considering the language he's feeding in, theres probably going to be atleast a few thousand unique words which is exponentially more pairings.
python has no concept of messaging.
ignoring finger trees for a second as i said he could literally just mutate it
these people meming about no mutation in FP are talking about pure FP
>wearing my thigh highs under my pants at uni
>getting those sneaky programming gains
>professor notices how clean and my code is
>wiggles ears
(((snek gainz)))
It's still better at sending messages between than smalltalk.
what is message passing in the context of programming languages?
So gcc could detect UB while compiling for example -faggressive-loop-optimizations.
Does that means gcc will simulate the code during optimization process?
How smart is gcc actually??
Smarter than you
gcc gains an IQ point whenever you compile with it
Here's the first hit in Google.
defit.org
It's not smart, it's just good at recognizing common patterns which were hand-coded manually.
I've gotten those aggressive loop optimizations one too many times and sometimes I think it's a bug because there's absolutely nothing wrong with misusing for loops in order to jump around an array dynamically using the return value of memmem and pointer offset arithmetic
how do I post my code for it to look like this
i never really looked into fp and have no idea what finger trees are. so this might sound like a dumb thing to say, but what are the advantages of fp over imperative when you allow mutations?
It's falling behind with regards to other compilers (even msvc, in terms of error checking at least).
>is it doing simulations
No its doing analysis. I'm not sure what your actual case is but consider if you built a graph of your program and tag where you strike UB. You then see if there's a valid path to that part of the program.
That's one way to do it. I'm not that familiar with GCC. Code is a mess.
Yeah this is often done to help remidy the failings of a compiler. I hope GCC isn't primarily this. I doubt it is but I couldn't tell you.
Depends. "real" messages would be actor model stuff and only really exist in Erlang and similar languages. However, smalltalk uses the message terminology for ordinary method calls, where the distinction just means that method calls are objects that you can take apart and modify before passing them on to other objects.
...mycode
I was trying to figure out how you draw circles.
Turns out my method isn't something unique but I was wondering if there is one that doesn't leave these gaps and could be faster at the same time.
>
I know we have a few lisp wizards here. This might seem like a stupid question but I'm hoping for serious answers. I'd especially love a link to relevant material.
Is there any reason why an implementation of Scheme could not, or should not, use postfix/reverse polish notation instead of prefix/polish notation? Apart from the obvious fact that it would not technically be a "Scheme" if it differed from the specification in such a major way.
Could anyone imagine a scenario where reversed operator/operand ordering would cause a problem?
well in this case you've got a really simple use of mutations that's perfectly safe
finger trees are an efficient immutable data structure for stuff like sets
does it work?
>Maybe
[*code]
Code here
[*/code]
Remove *.
Others are being asses. But we all prefer if you format posts correctly.
>doesn't leave these gaps
Use pythagoras to find the distance between each pixel to the center point.
If (distance
>Others are being asses
Did you read the last sentence of the sticky as mentioned by ??
RMS
rms.sexy
Any ideas for how I could make this queue implementation in haskell a bit nicer? I'm just learning -- pretty much works by flipping enqueue/dequeue when the dequeue is empty, or return Nothing if enqueue & dequeue is empty
data Queue a =
Queue { enqueue :: [a]
, dequeue :: [a]
} deriving (Eq, Show)
push :: a -> Queue a -> Queue a
push a = (\(Queue e d) -> Queue (a : e) d)
pop :: Queue a -> Maybe (a, Queue a)
pop (Queue enq deq) =
let qLen = length deq
in case qLen of
0 ->
if length enq == 0
then Nothing
else (pop $ Queue [] enq)
_ ->
let (hd:rst) = deq
in Just (hd, Queue enq rst)
int c = 0;
while(c==0)
{
c++;
c--;
}
[code/]
not like that user
>code works all of a sudden
wtf i love multithreading magic now
What are some characteristics you'd look for in a monitor for coding?
Searching online, everyone seems to care about gaming and that's not very important to me.
what are you listening to when you are programming?
awk or csh
>What are some characteristics you'd look for in a monitor for coding?
Cheap as fuck. You don't need a gaming/designer screen for coding.
german tech house really does it for me
it's rhythmic and has few lyrics, gets me in the groove
>misusing for loops in order to jump around an array dynamically using the return value of memmem and pointer offset arithmetic
What do you mean with this?
Why is it"misusing"
you're gonna see this for every PC peripheral category, because it's completely driven by gamer manchildren and crypto spergs 100%.
just buy a cheap laptop with a ULV cpu and a LOONG 12 hour battery life and install linux
these last two days it's been avicii or a osrs twitch streamer named b0aty
You shouldn't use length to match empty nonempty queue. Just match the head of the queue.
Short answer: en.wikipedia.org
Longer answer: Try to find Jim Blinn's article "How Many Ways Can You Draw a Circle?" on a pretty interesting survey of different ways to draw a circle. It's in his book "A Trip Down the Graphics Pipeline" which is available on Library Genesis.
Just make sure the monitor you pick show text clearly, and have a good contrast for easier reading.
imagine something like for (; *ptr; i++)
where the i doesn't actually have any say in stopping the for loop
basically I use it instead of a do { while loop because it looks cleaner
I calculate it along 1 axis and can easily fill the gaps for any difference bigger than 1 along other axis reflecting it 3 times at the same time.
I thought it maybe wasn't too efficient.